Boost logo

Boost :

From: Sven M. Hallberg (pesco_at_[hidden])
Date: 2001-05-11 13:15:50


On Fri, May 11, 2001 at 10:41:01AM -0700, Gary Powell wrote:
> Would it be worth parameterizing on the charType like this?
>
> template<class charType, class charTraits = std::character_traits<charType>
> >
> class basic_option_processor {
> public:
> template<class H>
> reg(H hdlr, basic_string<charType, charTraits> desc ,charType shortFlag,
> basic_string<charType, charTraits> LongName,
> basic_string<charType, charTraits> argName = "");
>
> // etc...
> };
>
> typedef basic_option_procesor<char> option_processor;
> typedef basic_option_procesor<wchar> woption_processor;

Oh you're right. This should definately be done to cleanly support wide
character-based systems.

> > I have to rework the handler objects again, considering using a boost
> > callback type, so I won't go into detail. Right now I have convenience
> > functions for their creation:
> >
> > // creates a no-argument handler
> > handler(void (*func)());
> > template<class F> noarg_handler(F func); // special case for function
> > objects
> > // creates a mandatory-arg handler
> > template<class F> handler(F func);
> > // creates a optional-arg handler supplying a default to its function if
> > // no argument is given.
> > template<class F> handler(F func, F::argument_type def);
> >
> > But I'm suspecting this is a less-than-optimal solution. Especially the
> > special case for non-arg function objects. Ugh.
> >
> > I think the problem that lead me to all this was that I wanted to relieve
> > the
> > programmer from processing a string argument, so I needed a functor that
> > does
> > the conversion from string to the function's argument type. Any
> > suggestions
> > welcome.
> <<
> A question comes to mind and that is how to you control the parsing? As in
> does each handler tell the parser how much of the line it just ate?

Oh, I'm relying on a parser that does the entire job: Process the options
according to fixed rules, i.e. the result is a bunch of data structures like
this:

struct option {
    optflag denom; // how the option was given on the cmdline
    string arg; // argument (if any - "" otherwise)
};

The processor takes all those and passes each on to the corresponding handler
object. The handler object than processes the argument and passes the
resulting value on to its function.

> Also formatting of the help string, do you embed <cr>'s?

Oh, I didn't think about that. I embed '\n'. Wasn't it that \n expands to CRLF
on MS-DOS and friends?

Regards,
Sven

-- 
"Would the All-Seeing Eye please look in my direction?"
 [ KeyID........: 0xC297FEAB ]
 [ Fingerprint..: FEA5 0F93 7320 3F39 66A5  AED3 073F 2D5F C297 FEAB ]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk