RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
RDKit::Dict Class Reference

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

#include <Dict.h>

Classes

struct  Pair
 

Public Types

typedef std::vector< PairDataType
 

Public Member Functions

 Dict ()
 
 Dict (const Dict &other)
 
 Dict (Dict &&other) noexcept=default
 
 ~Dict ()
 
void update (const Dict &other, bool preserveExisting=false)
 
Dictoperator= (const Dict &other)
 
Dictoperator= (Dict &&other) noexcept
 
boolgetNonPODStatus ()
 Access to the underlying non-POD containment flag This is meant to be used only in bulk updates of _data.
 
const DataTypegetData () const
 Access to the underlying data.
 
DataTypegetData ()
 
bool hasVal (const std::string &what) const
 Returns whether or not the dictionary contains a particular key.
 
STR_VECT keys () const
 Returns the set of keys in the dictionary.
 
template<typename T >
void getVal (const std::string &what, T &res) const
 Gets the value associated with a particular key.
 
template<typename T >
getVal (const std::string &what) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void 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.
 
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.
 
bool 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.
 
template<typename T >
void setVal (const std::string &what, T &val)
 Sets the value associated with a key.
 
template<typename T >
void setPODVal (const std::string &what, T val)
 
void setVal (const std::string &what, bool val)
 
void setVal (const std::string &what, double val)
 
void setVal (const std::string &what, float val)
 
void setVal (const std::string &what, int val)
 
void setVal (const std::string &what, unsigned int val)
 
void setVal (const std::string &what, const char *val)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void clearVal (const std::string &what)
 Clears the value associated with a particular key, removing the key from the dictionary.
 
void reset ()
 Clears all keys (and values) from the dictionary.
 

Detailed Description

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

The actual storage is done using RDValue objects.

Definition at line 36 of file Dict.h.

Member Typedef Documentation

◆ DataType

Definition at line 47 of file Dict.h.

Constructor & Destructor Documentation

◆ Dict() [1/3]

RDKit::Dict::Dict ( )
inline

Definition at line 49 of file Dict.h.

◆ Dict() [2/3]

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

Definition at line 51 of file Dict.h.

References RDKit::copy_rdvalue().

◆ Dict() [3/3]

RDKit::Dict::Dict ( Dict &&  other)
defaultnoexcept

◆ ~Dict()

RDKit::Dict::~Dict ( )
inline

Definition at line 65 of file Dict.h.

Member Function Documentation

◆ clearVal()

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

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

Parameters
whatthe key to clear

Definition at line 314 of file Dict.h.

Referenced by RDKit::RDProps::clearComputedProps(), RDKit::FilterCatalogEntry::clearProp(), and RDKit::RDProps::clearProp().

◆ getData() [1/2]

DataType & RDKit::Dict::getData ( )
inline

Definition at line 140 of file Dict.h.

◆ getData() [2/2]

const DataType & RDKit::Dict::getData ( ) const
inline

Access to the underlying data.

Definition at line 139 of file Dict.h.

◆ getNonPODStatus()

bool & RDKit::Dict::getNonPODStatus ( )
inline

Access to the underlying non-POD containment flag This is meant to be used only in bulk updates of _data.

Definition at line 135 of file Dict.h.

◆ getVal() [1/3]

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 189 of file Dict.h.

◆ getVal() [2/3]

void RDKit::Dict::getVal ( const std::string &  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 199 of file Dict.h.

References RDKit::rdvalue_tostring().

◆ getVal() [3/3]

template<typename T >
void RDKit::Dict::getVal ( const std::string &  what,
T &  res 
) const
inline

Gets the value associated with a particular key.

Parameters
whatthe key to lookup
resa 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 183 of file Dict.h.

Referenced by RDKit::FilterCatalogEntry::getProp(), RDKit::FilterCatalogEntry::getProp(), RDKit::FilterCatalogEntry::getProp(), RDKit::RDProps::getProp(), RDKit::FilterCatalogEntry::getProp(), and RDKit::RDProps::getProp().

◆ getValIfPresent() [1/2]

bool RDKit::Dict::getValIfPresent ( const std::string &  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 235 of file Dict.h.

References RDKit::rdvalue_tostring().

◆ getValIfPresent() [2/2]

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
whatthe key to lookup
resa 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 224 of file Dict.h.

Referenced by RDKit::FilterCatalogEntry::getPropIfPresent(), RDKit::FilterCatalogEntry::getPropIfPresent(), and RDKit::RDProps::getPropIfPresent().

◆ hasVal()

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

Returns whether or not the dictionary contains a particular key.

Definition at line 146 of file Dict.h.

Referenced by RDKit::FilterCatalogEntry::hasProp(), RDKit::FilterCatalogEntry::hasProp(), and RDKit::RDProps::hasProp().

◆ keys()

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

Returns the set of keys in the dictionary.

Returns
a STR_VECT

Definition at line 160 of file Dict.h.

Referenced by RDKit::FilterCatalogEntry::getPropList(), and RDKit::RDProps::getPropList().

◆ operator=() [1/2]

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

Definition at line 97 of file Dict.h.

References RDKit::copy_rdvalue().

◆ operator=() [2/2]

Dict & RDKit::Dict::operator= ( Dict &&  other)
inlinenoexcept

Definition at line 119 of file Dict.h.

◆ reset()

void RDKit::Dict::reset ( )
inline

Clears all keys (and values) from the dictionary.

Definition at line 329 of file Dict.h.

Referenced by RDKit::RDProps::clear().

◆ setPODVal()

template<typename T >
void RDKit::Dict::setPODVal ( const std::string &  what,
val 
)
inline

Definition at line 274 of file Dict.h.

◆ setVal() [1/7]

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

Definition at line 288 of file Dict.h.

◆ setVal() [2/7]

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 301 of file Dict.h.

◆ setVal() [3/7]

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

Definition at line 290 of file Dict.h.

◆ setVal() [4/7]

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

Definition at line 292 of file Dict.h.

◆ setVal() [5/7]

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

Definition at line 294 of file Dict.h.

◆ setVal() [6/7]

template<typename T >
void RDKit::Dict::setVal ( const std::string &  what,
T &  val 
)
inline

Sets the value associated with a key.

Parameters
whatthe key to set
valthe 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 259 of file Dict.h.

Referenced by RDKit::RDProps::clearComputedProps(), RDKit::RDProps::clearProp(), RDKit::FilterCatalogEntry::setProp(), and RDKit::RDProps::setProp().

◆ setVal() [7/7]

void RDKit::Dict::setVal ( const std::string &  what,
unsigned int  val 
)
inline

Definition at line 296 of file Dict.h.

◆ update()

void RDKit::Dict::update ( const Dict other,
bool  preserveExisting = false 
)
inline

Definition at line 69 of file Dict.h.

References RDKit::copy_rdvalue(), and RDKit::Dict::Pair::val.

Referenced by RDKit::RDProps::updateProps().


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