
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 lexical_cast<Vector3>*any_cast<string>(&pos->Value) 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 here.
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 options.
3. Would you suggest to define a simple Value class like this when I can not use any boost classes:
class Value { public: Value(); Value( const std::string& )
template<typename T> T As(void ) const;
private: std::string m_Value; }
Seems like lexical_cast does what you want. - Volodya