From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-12-27 07:38:33
On Sunday 26 December 2004 16:35, Dirk Gregorius wrote:
> I have a text file which defines several properties. For example:
> // Properties.txt
> "Position" "1.0 2.0 3.0"
> "Color" "1.0 0.0 0.0"
> "Intensity" "500"
> properties.push_back( Property( key, value ) );
> Vector3 position = any_cast<Vector3>( pos->Value );
> 1. Is it possible to use boost::any in this way? If yes - where and how
> do I have to implement the conversions?
To the best of my knowledge -- no. boost::any does not support lexical casting
of content that you seem to want. You can use
or something like that.
> 2. If this is not possible could I use boost::programm_options instead
> for the value type? How and where do I have to implement the conversion
You'd overload the 'validate' function for your Vector3, I think. The idea is
that you'll have to specify the types of all properties when declaring the
> 3. Would you suggest to define a simple Value class like this when I can
> not use any boost classes:
> class Value
> Value( const std::string& )
> template<typename T>
> T As(void ) const;
> std::string m_Value;
Seems like lexical_cast does what you want.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk