|
Boost Users : |
Subject: Re: [Boost-users] [boost-users][Variant] Sequence instantiation
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-08-27 23:13:36
> Ah, for something like that I personally would use Variant to hold it
> all, Spirit2.1 (with stringtable > continued parsing trick, Spirit2.1
> is in the boost trunk but it works on older boosts' too) to parse it,
> would give the best speed and is easily extensible in the future while
> being completely typesafe.
>
I'm assuming the Spirit 2.1 is just for parsing the xml file. I still
need to have a switch statement to determine what type I'm suppose to be
storing. Lets suppose for a moment that I've determined the type to be
stored (whether Spirit 2.1, tinyXML or some other parser). I've tried
making the Destination class a template based on type (see code at
bottom of email). Then I created a variant of all the Destination class
with the types I wanted. A map was used with a key for the parameter
name and the value was a vector of the variants. Matching the parameter
name is simple in the get function. I've had trouble comparing the type
and then returning just a vector of that type and not a vector of the
variant. It seams that since the caller knows what type they want that
I shouldn't have to return a variant.
This approach seem to be complicating the return value. The only reason
to to make Destination a template was to keep track of the type. Is
there a way to keep track of the type in the key or something? That way
the Destination class can be simple and keep the return simple. The
caller knows what type they want and if it isn't there the return vector
will be empty. Can you provide some code on what you might suggest?
Ryan
Code:
typedef boost::mpl::vector< Destination<long>, Destination<short>,
Destination<std::string> > supported_types;
typedef
boost::variant::make_variant_over<supported_types>::type
supported_variant;
std::map< std::string, std::vector<supported_variant>
> supported_list;
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