|
Boost Users : |
From: Andrew Agno (andrewagno_at_[hidden])
Date: 2008-04-23 12:06:43
On Wed, Apr 23, 2008 at 05:06:58AM +0000, Ryan Gallagher wrote:
> Jeffery Cavallaro <jcavalla <at> google.com> writes:
> [...]
> > For example, if I wanted to a program to spit out all of its options
> > to standard out, there doesn't seem to be any hooks to extract an Any
> > value in a generic way (e.g., as a string).
>
> Okay, this isn't exactly generic and only addresses this specific case
> for the issue that you brought up, but for program_options where you
> normally just have a limited number of types I've used:
I've done something similar as well. If you have a lot of types, and
you want support for vectors of those types, you may want to look at the
boost preprocessor macro library:
...
#define TYPE_LIST ( unsigned char, ( unsigned short, ( unsigned int, ( unsigned long, ( signed char, ( signed short, ( signed int, ( signed long, ( bool, ( char, ( std::string, BOOST_PP_NIL)))))))))))
#define MAKE_VECTOR_LIST( d, data, elem ) std::vector<elem>
#define VECTOR_LIST BOOST_PP_LIST_TRANSFORM( MAKE_VECTOR_LIST, _, TYPE_LIST )
#define CAST_SIMPLE( r, data, elem ) if ( ti == typeid( elem ) ) { elem e = anyValue->as<elem>(); return boost::lexical_cast<string>( e ); }
#define CAST_VECTOR( r, data, elem ) if ( ti == typeid( elem ) ) { /* iterate through the vector... */ }
BOOST_PP_LIST_FOR_EACH(CAST_SIMPLE, _, TYPE_LIST);
BOOST_PP_LIST_FOR_EACH(CAST_VECTOR, _, VECTOR_LIST);
...
Andrew.
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