21 #include <boost/any.hpp> 23 #include <boost/lexical_cast.hpp> 35 typedef std::map<std::string, boost::any>
DataType;
38 Dict(
const Dict &other) : _data(other._data){};
48 bool hasVal(
const char *what)
const {
49 std::string key(what);
52 bool hasVal(
const std::string &what)
const {
53 return _data.find(what) != _data.end();
63 DataType::const_iterator item;
64 for (item = _data.begin(); item != _data.end(); item++) {
65 res.push_back(item->first);
84 void getVal(
const std::string &what, T &res)
const {
85 res = getVal<T>(what);
89 T
getVal(
const std::string &what)
const {
90 DataType::const_iterator pos = _data.find(what);
92 const boost::any &val = pos->second;
93 return fromany<T>(val);
100 std::string key(what);
101 res = getVal<T>(key);
105 template <
typename T>
107 std::string key(what);
108 return getVal<T>(key);
112 void getVal(
const std::string &what, std::string &res)
const;
114 void getVal(
const char *what, std::string &res)
const {
115 getVal(std::string(what), res);
133 template <
typename T>
135 DataType::const_iterator pos = _data.find(what);
136 if (pos == _data.end())
return false;
137 const boost::any &val = pos->second;
138 res = fromany<T>(val);
142 template <
typename T>
144 std::string key(what);
145 return getValIfPresent<T>(key, res);
168 template <
typename T>
169 void setVal(
const std::string &what, T &val) {
170 _data[what] =
toany(val);
173 template <
typename T>
175 std::string key = what;
179 void setVal(
const std::string &what,
const char *val) {
202 std::string key = what;
218 template <
typename T>
219 T
fromany(
const boost::any &arg)
const;
228 template <
typename T>
229 boost::any
toany(T arg)
const;
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
void getVal(const char *what, std::string &res) const
bool hasVal(const char *what) const
Returns whether or not the dictionary contains a particular key.
void setVal(const char *what, T &val)
std::map< std::string, boost::any > DataType
void setVal(const std::string &what, const char *val)
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...
bool hasVal(const std::string &what) const
void getVal(const std::string &what, T &res) const
Gets the value associated with a particular key.
void clearVal(const std::string &what)
Clears the value associated with a particular key, removing the key from the dictionary.
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.
STR_VECT keys() const
Returns the set of keys in the dictionary.
T getVal(const char *what) const
T fromany(const boost::any &arg) const
Converts a boost::any to type T.
Dict & operator=(const Dict &other)
T getVal(const std::string &what) const
void reset()
Clears all keys (and values) from the dictionary.
bool getValIfPresent(const char *what, std::string &res) const
T getVal(const char *what, T &res) const
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.
bool getValIfPresent(const char *what, T &res) const