return result;
} else if( val.type() == typeid(ValueType) ) {
return boost::any_cast<ValueType>(val);
- } else
- assert( 0 == 1 );
+ } else {
+ DAI_THROW(IMPOSSIBLE_TYPECAST);
+ return ValueType();
+ }
}
+ /// Converts a property from ValueType to string (if necessary)
+ template<typename ValueType>
+ PropertySet & setAsString(const PropertyKey &key, ValueType &val) {
+ if( val.type() == typeid(std::string) ) {
+ return Set(key, val);
+ } else {
+ std::stringstream ss (std::stringstream::out);
+ ss << val;
+ return Set(key, ss.str());
+ }
+ }
+
/// Shorthand for (temporarily) adding properties, e.g. PropertySet p()("method","BP")("verbose",1)("tol",1e-9)
PropertySet operator()(const PropertyKey &key, const PropertyValue &val) const { PropertySet copy = *this; return copy.Set(key,val); }