Boost logo

Boost Users :

Subject: Re: [Boost-users] boost fusion and/or boost parameter: open ended question about constructing object from a string
From: e r (erwann.rogard_at_[hidden])
Date: 2008-09-10 17:04:05


David Abrahams wrote:
> on Wed Sep 10 2008, e r <erwann.rogard-AT-gmail.com> wrote:
>
>> hi,
>>
>> here's what i'd like to do
>>
>> A]
>>
>> hpp:
>>
>> struct my{
>> template<typename ArgPack>
>> my(const ArgPack& args):n_(args[tag::n]),k_(args[tag::k]){}
>> }
>>
>>
>> struct argpack{
>> arglist<???> operator()(const string& str){???}
>> }
>>
>> cpp:
>>
>> string str("n=2; k=1");
>>
>> my(argpack(str));
>>
>> In words,I'm looking to construct an ArgPack from a string, what's the
>> appropriate library for this?
>
> Well, unless the types of all your arguments are the same *and* you have
> a limited set of parameter names, all known at compile time,
> Boost.Parameter can not help at all... and even if you meet all those

Thanks.

- Actually, no the arguments are not all the same type.
- A limited set of parameter names: limited as in small or known? Known,
but not necessarily small.

> conditions, using Boost.Parameter would probably be more trouble than it
> is worth. The problem is that Boost.Parameter establishes an
> association between keywords and argument values at compile time, and
> your strings have to be parsed at runtime.

Quite a painful dilemma because I use Boost.Parameter (not unlike many
folks I guess) to pass down arguments into nested objects (whose types
may be parameterized in the host class) and I couldn't deal with
positional arguments.

>
>> Does it seem like I should invest in Boost
>> Spirit?
>
> Almost any of Boost's text processing libraries might be useful to you.
> In your case, it might be easiest to build something on Boost.Regex or
> Boost.XPressive, or even tokenizer, since the job you're doing is so
> simple.
>
>> The above is a simplified version of what i really need, which is,
>> potentially,
>> 1) having to construct a large number of objects (to be pushed at the
>> back of a container)
>> 2) each object taking a large number arguments (not just n and k as above)
>> 3) each object an instance of one of a set of classes
>> (my0,my1,my2,...,myN) each with its specific argument tags (keywords).
>>
>> So I'd like to put all these arguments in a file, each line
>> corresponding to an object, rather than have a messy cpp file.
>
> Well, if you're willing to compile that file as C++, you could go back
> to using Boost.Parameter... ;-)

since the arguments to be passed into object constructors are known at
compile time, i guess i could still do this?

a) have some sort of cpp template i.e. some, not all the code
intentionally left out (say marked by "NA"), to be filled from a text
file, via a text processor b) compile the modified cpp file.

i'm not all that experienced with parsers and such. is this where
Boost.Xpressive etc fit in or should i just go ahead and use perl?

>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net