-/* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
- Radboud University Nijmegen, The Netherlands
-
+/* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
+ Radboud University Nijmegen, The Netherlands /
+ Max Planck Institute for Biological Cybernetics, Germany
+
This file is part of libDAI.
libDAI is free software; you can redistribute it and/or modify
#include <iostream>
#include <dai/properties.h>
-#include <dai/alldai.h>
+#include <dai/exceptions.h>
namespace dai {
-/// Sends a single Property object to an output stream
std::ostream& operator<< (std::ostream & os, const Property & p) {
os << p.first << "=";
if( p.second.type() == typeid(size_t) )
os << boost::any_cast<bool>(p.second);
else if( p.second.type() == typeid(PropertySet) )
os << boost::any_cast<PropertySet>(p.second);
-#ifdef WITH_BP
- else if( p.second.type() == typeid(BP::Properties::UpdateType) )
- os << boost::any_cast<BP::Properties::UpdateType>(p.second);
-#endif
-#ifdef WITH_HAK
- else if( p.second.type() == typeid(HAK::Properties::ClustersType) )
- os << boost::any_cast<HAK::Properties::ClustersType>(p.second);
-#endif
-#ifdef WITH_JTREE
- else if( p.second.type() == typeid(JTree::Properties::UpdateType) )
- os << boost::any_cast<JTree::Properties::UpdateType>(p.second);
-#endif
-#ifdef WITH_MR
- else if( p.second.type() == typeid(MR::Properties::UpdateType) )
- os << boost::any_cast<MR::Properties::UpdateType>(p.second);
- else if( p.second.type() == typeid(MR::Properties::InitType) )
- os << boost::any_cast<MR::Properties::InitType>(p.second);
-#endif
-#ifdef WITH_TREEEP
- else if( p.second.type() == typeid(TreeEP::Properties::TypeType) )
- os << boost::any_cast<TreeEP::Properties::TypeType>(p.second);
-#endif
-#ifdef WITH_LC
- else if( p.second.type() == typeid(LC::Properties::CavityType) )
- os << boost::any_cast<LC::Properties::CavityType>(p.second);
- else if( p.second.type() == typeid(LC::Properties::UpdateType) )
- os << boost::any_cast<LC::Properties::UpdateType>(p.second);
-#endif
else
- throw "Unknown property type";
+ DAI_THROW(UNKNOWN_PROPERTY_TYPE);
return( os );
}
-/// Sends a PropertySet object to an output stream
+/// Writes a PropertySet object to an output stream
std::ostream& operator<< (std::ostream & os, const PropertySet & ps) {
os << "[";
for( PropertySet::const_iterator p = ps.begin(); p != ps.end(); p++ ) {
// Check whether s is of the form "[.*]"
if( (s.length() < 2) || (s.at(0) != '[') || (s.at(s.length()-1)) != ']' )
- throw "Malformed property";
+ DAI_THROW(MALFORMED_PROPERTY);
size_t N = s.length() - 1;
for( size_t token_start = 1; token_start < N; ) {
if( s[token_end] == '=' )
break;
if( token_end == N )
- throw "Malformed property key";
+ DAI_THROW(MALFORMED_PROPERTY);
// we found a key
std::string key = s.substr(token_start, token_end - token_start);
break;
}
if( !(level == 0) )
- throw "Malformed property value";
+ DAI_THROW(MALFORMED_PROPERTY);
// we found a vlue
std::string value = s.substr(token_start, token_end - token_start);