|
Boost Users : |
Subject: Re: [Boost-users] [boost-users][Variant] Sequence instantiation
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-08-26 22:32:33
> I doubt Boost.Variant is the best choice for this. You say a template
> function to enforce types, I would say Boost.Enable_if combined with
> Boost.Type_traits and Boost.MPL would make it real easy.
>
I'm all for making this easy. So, let me give you some background of
what I'm trying to do. I'm reading an xml file that contains a binary
format description (lets call the class BFD). This will allow me to
specify a customers binary data in such a way as to place the binary
data into an object. Each parameter has a type associated with it.
This can be a int, short, string, long etc. The class reading the xml
file is storing the type information based on the parameter name. Any
class trying to retrieve this binary format description will need to
specify the parameter name and expected type. If the parameter name
exists but the type is incorrect then an empty description is returned.
I need to limit the types that can be requested from the BFD. That's
where the mpl::vector of known types comes into play. The function
returning the binary description information will check (at compile
time) to make sure the type requested is part of the known types. Since
the BFD is comparing types I need to convert the string names of these
types, in the xml file, into real types. This has posed a problem. I
come up with nothing better than a case statement. Once the type is
known I then create a binary format description object (this is a
template structure). The only reason the structure is a template is to
associate a type. This is why I though the boost::variant was
necessary. A variant composed of each of the types in the mpl::vector
was defined as the second parameter of a map with the key as the
parameter name from the xml file. The function returning the binary
description information will check the type of the data stored in the
map and if the types match then return the structure.
So with this information in mind how would you use the boost::enable_if,
boost::type_traits and boost:mpl.
Ryan
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