Re: argument parsing based on a specific syntax template

  • From: "Littlefield, Tyler" <tyler@xxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Thu, 23 Jun 2011 08:30:22 -0600

Hello:
It's something kind of like that. except here's the deal. I need to find a way to get a big command like dig north to 12213 nolink parsed out, and there are multiple variations of that command.
On 6/23/2011 3:25 AM, Nick.Adamson@xxxxxxxxxxxxxxxxxxxxxx wrote:
Hi Ty.

I may not understand quite what your after but default arguments may be
what your after.

Take the function prototype,

Bool CheckDirection( const std::string&  strDirection = "north", int
nAmount = 2, bool bNoLink = false);

This means you can call the function providing as many or as little
arguments as you like as the ones you don't provide get set to there
default values.

As an example you could call:
CheckDirection();

And your default information is north 2 with out link.
Or you could call:
CheckDirection( "east" );
Which will do east 2 false.
And so on.

If this is not really what your after can you explain a little.

Thanks.
Nick.



Nick Adamson
Software Engineer
  General Dynamics United Kingdom Limited
Bryn Brithdir, Oakdale Business Park, Blackwood, South Wales, NP12 4AA
Telephone: +44 (0)1495 23 6467
Email: Nick.Adamson@xxxxxxxxxxxxxxxxxxxxxx
Website: www.generaldynamics.uk.com
To help reduce waste paper, please only print this email if you really
need to.


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Littlefield,
Tyler
Sent: 23 June 2011 06:25
To: programmingblind@xxxxxxxxxxxxx
Subject: argument parsing based on a specific syntax template

Hello all:
I was working on a longish command today for the mud and sort of had
this idea. It's something I started before, but I kind of elaborated on
it.
I was working on a dig command, where there are a few variations of a
dig command:
dig north to 1212
dig north 1212
dig north to 1212 nolink
dig north 1212 nolink
dig north
so, I had an idea, and I am not really sure how hard this would be to
implement. Here's a small sample of what I want though.
{
std::string direction;
VNUM rnum;
BOOL nolink;
if (ParseCommandArguments<std::string, int,
BOOL>(<north,south,east,west,northeast,northwest,southeast,southwest,n,w
,s,e,ne,nw,se,sw>
[to] [rnum](num+) [nolink]", direction, rnum, nolink))
{
//failed!
}
else
{
...we have our data returned
}
...
}

How hard would something like this be to implement? I'm also interested
in exposing some sort of visitor functionality on stl containers where I

can do something like:
struct PlayerListIterator:public Visitor
{
operator ()(Player* p)
{
return p->GetName();
}
};
I'm thinking that providing lists shouldn't be that hard, you could
provide a pointer to the list, and the visitor that would be used to
check. At least I hope those are visitors, anyway.

Either way, thoughts and suggestions would be welcome.



--

Take care,
Ty
my website:
http://tds-solutions.net
my blog:
http://tds-solutions.net/blog
skype: st8amnd127
My programs don't have bugs; they're randomly added features!

__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: