21 #include <boost/any.hpp> 23 #include <boost/lexical_cast.hpp> 35 typedef std::map<std::string, boost::any>
DataType;
40 Dict(
const Dict &other) : _data(other._data) {};
51 std::string key(what);
54 bool hasVal(
const std::string &what)
const {
55 return _data.find(what)!=_data.end();
65 DataType::const_iterator item;
66 for (item = _data.begin(); item != _data.end(); item++) {
67 res.push_back(item->first);
86 void getVal(
const std::string &what,T &res)
const {
87 res = getVal<T>(what);
91 T
getVal(
const std::string &what)
const {
92 DataType::const_iterator pos=_data.find(what);
95 const boost::any &val = pos->second;
96 return fromany<T>(val);
100 template <
typename T>
101 T
getVal(
const char *what,T &res)
const {
102 std::string key(what);
103 res = getVal<T>(key);
107 template <
typename T>
109 std::string key(what);
110 return getVal<T>(key);
114 void getVal(
const std::string &what, std::string &res)
const;
116 void getVal(
const char *what, std::string &res)
const {
getVal(std::string(what),res); };
133 template <
typename T>
135 DataType::const_iterator pos=_data.find(what);
138 const boost::any &val = pos->second;
139 res = fromany<T>(val);
143 template <
typename T>
145 std::string key(what);
146 return getValIfPresent<T>(key, res);
169 template <
typename T>
170 void setVal(
const std::string &what, T &val){
171 _data[what] =
toany(val);
174 template <
typename T>
176 std::string key = what;
180 void setVal(
const std::string &what,
const char *val){
205 std::string key=what;
223 template <
typename T>
224 T
fromany(
const boost::any &arg)
const;
234 template <
typename T>
235 boost::any
toany(T arg)
const;
bool hasVal(const std::string &what) const
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
T getVal(const std::string &what) const
bool getValIfPresent(const char *what, std::string &res) const
STR_VECT keys() const
Returns the set of keys in the dictionary.
bool getValIfPresent(const std::string &what, T &res) const
Potentially gets the value associated with a particular key returns true on success/false on failure...
void setVal(const char *what, T &val)
bool getValIfPresent(const char *what, T &res) const
std::map< std::string, boost::any > DataType
void setVal(const std::string &what, const char *val)
void clearVal(const std::string &what)
Clears the value associated with a particular key, removing the key from the dictionary.
void getVal(const std::string &what, T &res) const
Gets the value associated with a particular key.
T fromany(const boost::any &arg) const
Converts a boost::any to type T.
void getVal(const char *what, std::string &res) const
void clearVal(const char *what)
Includes a bunch of functionality for handling Atom and Bond queries.
boost::any toany(T arg) const
Converts an instance of type T to boost::any.
bool hasVal(const char *what) const
Returns whether or not the dictionary contains a particular key.
T getVal(const char *what) const
Dict & operator=(const Dict &other)
T getVal(const char *what, T &res) const
void reset()
Clears all keys (and values) from the dictionary.
The Dict class can be used to store objects of arbitrary type keyed by strings.
std::vector< std::string > STR_VECT
Class to allow us to throw a KeyError from C++ and have it make it back to Python.