RDKit: RDKit::Dict Class Reference

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | List of all members
RDKit::Dict Class Reference

The `Dict` class can be used to store objects of arbitrary type keyed by `strings`. More...

`#include <Dict.h>`

## Public Types
typedef std::map< std::string, boost::any > | DataType

## Public Member Functions
| Dict ()
| Dict (const Dict &other)
Dict & | operator= (const Dict &other)
bool | hasVal (const char *what) const
| Returns whether or not the dictionary contains a particular key. More...
bool | hasVal (const std::string &what) const
STR_VECT | keys () const
| Returns the set of keys in the dictionary. More...
template<typename T >
void | getVal (const std::string &what, T &res) const
| Gets the value associated with a particular key. More...
template<typename T >
T | getVal (const std::string &what) const
template<typename T >
T | getVal (const char *what, T &res) const
template<typename T >
T | getVal (const char *what) const
void | getVal (const std::string &what, std::string &res) const
void | getVal (const char *what, std::string &res) const
template<typename T >
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. More...
template<typename T >
bool | getValIfPresent (const char *what, T &res) const
bool | getValIfPresent (const std::string &what, std::string &res) const
bool | getValIfPresent (const char *what, std::string &res) const
template<typename T >
void | setVal (const std::string &what, T &val)
| Sets the value associated with a key. More...
template<typename T >
void | setVal (const char *what, T &val)
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. More...
void | clearVal (const char *what)
void | reset ()
| Clears all keys (and values) from the dictionary. More...
template<typename T >
T | fromany (const boost::any &arg) const
| Converts a `boost::any` to type `T`. More...
template<typename T >
boost::any | toany (T arg) const
| Converts an instance of type `T` to `boost::any`. More...

## Detailed Description

The `Dict` class can be used to store objects of arbitrary type keyed by `strings`.

The actual storage is done using `boost::any` objects.

Definition at line 33 of file Dict.h.

## Member Typedef Documentation

typedef std::map<std::string, boost::any> RDKit::Dict::DataType

Definition at line 35 of file Dict.h.

## Constructor & Destructor Documentation

RDKit::Dict::Dict | ( |  | ) |
| inline

Definition at line 36 of file Dict.h.

RDKit::Dict::Dict | ( | const Dict & | other | ) |
| inline

Definition at line 38 of file Dict.h.

## Member Function Documentation

void RDKit::Dict::clearVal | ( | const std::string & | what | ) |
| inline

Clears the value associated with a particular key, removing the key from the dictionary.

Parameters

  what | the key to clear

Notes:

- If the dictionary does not contain the key `what`, a KeyErrorException will be thrown.

Definition at line 195 of file Dict.h.

References hasVal().

Referenced by RDKit::Bond::clearComputedProps(), RDKit::Atom::clearComputedProps(), RDKit::MolCatalogEntry::clearProp(), RDKit::FragCatalogEntry::clearProp(), RDKit::FilterCatalogEntry::clearProp(), RDKit::Bond::clearProp(), RDKit::Atom::clearProp(), RDKit::ROMol::clearProp(), and clearVal().

void RDKit::Dict::clearVal | ( | const char * | what | ) |
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 201 of file Dict.h.

References clearVal().

template<typename T >

T RDKit::Dict::fromany | ( | const boost::any & | arg | ) | const

Converts a `boost::any` to type `T`.

Parameters

  arg | a `boost::any` reference

Returns
  the converted object of type `T`

template<typename T >

void RDKit::Dict::getVal | ( | const std::string & | what,
|  | T & | res
| ) |  | const
| inline

Gets the value associated with a particular key.

Parameters

  what | the key to lookup
  res | a reference used to return the result

Notes:

- If `res` is a `std::string`, every effort will be made to convert the specified element to a string using the `boost::lexical_cast` machinery.
- If the dictionary does not contain the key `what`, a KeyErrorException will be thrown.

Definition at line 84 of file Dict.h.

Referenced by RDKit::MolCatalogEntry::getProp(), RDKit::FragCatalogEntry::getProp(), RDKit::FilterCatalogEntry::getProp(), RDKit::Bond::getProp(), RDKit::Atom::getProp(), RDKit::ROMol::getProp(), getVal(), and RDKit::ROMol::setProp().

template<typename T >

T RDKit::Dict::getVal | ( | const std::string & | what | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 89 of file Dict.h.

template<typename T >

T RDKit::Dict::getVal | ( | const char * | what,
|  | T & | res
| ) |  | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 98 of file Dict.h.

template<typename T >

T RDKit::Dict::getVal | ( | const char * | what | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 106 of file Dict.h.

void RDKit::Dict::getVal | ( | const std::string & | what,
|  | std::string & | res
| ) |  | const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void RDKit::Dict::getVal | ( | const char * | what,
|  | std::string & | res
| ) |  | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 114 of file Dict.h.

References getVal().

template<typename T >

bool RDKit::Dict::getValIfPresent | ( | const std::string & | what,
|  | T & | res
| ) |  | const
| inline

Potentially gets the value associated with a particular key returns true on success/false on failure.

Parameters

  what | the key to lookup
  res | a reference used to return the result

Notes:

- If `res` is a `std::string`, every effort will be made to convert the specified element to a string using the `boost::lexical_cast` machinery.
- If the dictionary does not contain the key `what`, a KeyErrorException will be thrown.

Definition at line 134 of file Dict.h.

Referenced by RDKit::FilterCatalogEntry::getPropIfPresent(), RDKit::Bond::getPropIfPresent(), RDKit::Atom::getPropIfPresent(), RDKit::ROMol::getPropIfPresent(), and getValIfPresent().

template<typename T >

bool RDKit::Dict::getValIfPresent | ( | const char * | what,
|  | T & | res
| ) |  | const
| inline

Definition at line 143 of file Dict.h.

bool RDKit::Dict::getValIfPresent | ( | const std::string & | what,
|  | std::string & | res
| ) |  | const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool RDKit::Dict::getValIfPresent | ( | const char * | what,
|  | std::string & | res
| ) |  | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 151 of file Dict.h.

References getValIfPresent().

bool RDKit::Dict::hasVal | ( | const char * | what | ) | const
| inline

Returns whether or not the dictionary contains a particular key.

Definition at line 48 of file Dict.h.

Referenced by clearVal(), RDKit::MolCatalogEntry::hasProp(), RDKit::FragCatalogEntry::hasProp(), RDKit::FilterCatalogEntry::hasProp(), RDKit::Bond::hasProp(), RDKit::Atom::hasProp(), and RDKit::ROMol::hasProp().

bool RDKit::Dict::hasVal | ( | const std::string & | what | ) | const
| inline

Definition at line 52 of file Dict.h.

STR_VECT RDKit::Dict::keys | ( |  | ) | const
| inline

Returns the set of keys in the dictionary.

Returns
  a `STR_VECT`

Definition at line 61 of file Dict.h.

Referenced by RDKit::FilterCatalogEntry::getPropList(), RDKit::Bond::getPropList(), RDKit::Atom::getPropList(), and RDKit::ROMol::getPropList().

Dict& RDKit::Dict::operator= | ( | const Dict & | other | ) |
| inline

Definition at line 40 of file Dict.h.

void RDKit::Dict::reset | ( |  | ) |
| inline

Clears all keys (and values) from the dictionary.

Definition at line 209 of file Dict.h.

template<typename T >

void RDKit::Dict::setVal | ( | const std::string & | what,
|  | T & | val
| ) |  |
| inline

Sets the value associated with a key.

Parameters

  what | the key to set
  val | the value to store

Notes:

- If `val` is a `const char *`, it will be converted to a `std::string` for storage.
- If the dictionary already contains the key `what`, the value will be replaced.

Definition at line 169 of file Dict.h.

References toany().

Referenced by RDKit::Bond::clearComputedProps(), RDKit::Atom::clearComputedProps(), RDKit::Bond::clearProp(), RDKit::Atom::clearProp(), RDKit::ROMol::clearProp(), RDKit::MolCatalogEntry::setProp(), RDKit::FragCatalogEntry::setProp(), RDKit::FilterCatalogEntry::setProp(), RDKit::Bond::setProp(), RDKit::Atom::setProp(), RDKit::ROMol::setProp(), and setVal().

template<typename T >

void RDKit::Dict::setVal | ( | const char * | what,
|  | T & | val
| ) |  |
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 174 of file Dict.h.

References setVal().

void RDKit::Dict::setVal | ( | const std::string & | what,
|  | const char * | val
| ) |  |
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 179 of file Dict.h.

References setVal().

template<typename T >

boost::any RDKit::Dict::toany | ( | T | arg | ) | const

Converts an instance of type `T` to `boost::any`.

Parameters

  arg | the object to be converted

Returns
  a `boost::any` instance

Referenced by setVal().

The documentation for this class was generated from the following file:

- Dict.h