Merge branch 'master' of git@git.tuebingen.mpg.de:libdai
authorJoris Mooij <jorism@osun.tuebingen.mpg.de>
Wed, 24 Sep 2008 12:54:22 +0000 (14:54 +0200)
committerJoris Mooij <jorism@osun.tuebingen.mpg.de>
Wed, 24 Sep 2008 12:54:22 +0000 (14:54 +0200)
1  2 
include/dai/properties.h

@@@ -101,12 -100,22 +101,24 @@@ class PropertySet : public std::map<Pro
                  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); }