Chemical Data Processing Library C++ API - Version 1.4.0
Public Types | Public Member Functions | List of all members
CDPL::Chem::BasicReaction Class Reference

Default concrete implementation of the Chem::Reaction abstract interface. More...

#include <BasicReaction.hpp>

+ Inheritance diagram for CDPL::Chem::BasicReaction:

Public Types

typedef std::shared_ptr< BasicReactionSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated BasicReaction instances. More...
 
typedef boost::indirect_iterator< ComponentList::iterator, BasicMoleculeComponentIterator
 A mutable random access iterator used to iterate over the stored Chem::BasicMolecule reaction components. More...
 
typedef boost::indirect_iterator< ComponentList::const_iterator, const BasicMoleculeConstComponentIterator
 A constant random access iterator used to iterate over the stored const Chem::BasicMolecule reaction components. More...
 
- Public Types inherited from CDPL::Chem::Reaction
typedef std::shared_ptr< ReactionSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated Reaction instances. More...
 
typedef Util::IndexedElementIterator< const Molecule, ConstComponentAccessor > ConstComponentIterator
 A constant random access iterator used to iterate over the components of the reaction. More...
 
typedef Util::IndexedElementIterator< Molecule, ComponentAccessor > ComponentIterator
 A mutable random access iterator used to iterate over the components of the reaction. More...
 
typedef std::function< void(Reaction &, const Reaction &)> CopyPostprocessingFunction
 Type of a functor invoked after a reaction copy operation to post-process the target reaction (first argument) using information from the source reaction (second argument). More...
 
- Public Types inherited from CDPL::Base::PropertyContainer
typedef PropertyMap::value_type PropertyEntry
 A Base::LookupKey / Base::Any pair that stores the property value for a given property key. More...
 
typedef PropertyMap::const_iterator ConstPropertyIterator
 A constant iterator used to iterate over the property entries. More...
 

Public Member Functions

 BasicReaction ()
 Constructs an empty BasicReaction instance. More...
 
 BasicReaction (const BasicReaction &rxn)
 Constructs a copy of the BasicReaction instance rxn. More...
 
 BasicReaction (const Reaction &rxn)
 Constructs a copy of the Chem::Reaction instance rxn. More...
 
 ~BasicReaction ()
 Destructor. More...
 
unsigned int getComponentRole (const Molecule &mol) const
 Returns the reaction role of the component mol (see namespace Chem::ReactionRole). More...
 
std::size_t getComponentIndex (const Molecule &mol) const
 Returns the index of the component mol in the reaction. More...
 
bool containsComponent (const Molecule &mol) const
 Tells whether mol is a component of the reaction. More...
 
void clear ()
 Removes all components and clears all properties of the reaction. More...
 
std::size_t getNumComponents () const
 Returns the total number of components in the reaction. More...
 
std::size_t getNumComponents (unsigned int role) const
 Returns the number of components with the given reaction role. More...
 
ConstComponentIterator getComponentsBegin () const
 Returns a constant iterator pointing to the first component of the reaction. More...
 
ComponentIterator getComponentsBegin ()
 Returns a mutable iterator pointing to the first component of the reaction. More...
 
ConstComponentIterator getComponentsEnd () const
 Returns a constant iterator pointing one past the last component of the reaction. More...
 
ComponentIterator getComponentsEnd ()
 Returns a mutable iterator pointing one past the last component of the reaction. More...
 
ConstComponentIterator getComponentsBegin (unsigned int role) const
 Returns a constant iterator pointing to the first component with the given reaction role. More...
 
ComponentIterator getComponentsBegin (unsigned int role)
 Returns a mutable iterator pointing to the first component with the given reaction role. More...
 
ConstComponentIterator getComponentsEnd (unsigned int role) const
 Returns a constant iterator pointing one past the last component with the given reaction role. More...
 
ComponentIterator getComponentsEnd (unsigned int role)
 Returns a mutable iterator pointing one past the last component with the given reaction role. More...
 
const BasicMoleculegetComponent (std::size_t idx) const
 Returns a const reference to the component at the specified index. More...
 
BasicMoleculegetComponent (std::size_t idx)
 Returns a reference to the component at the specified index. More...
 
const BasicMoleculegetComponent (std::size_t idx, unsigned int role) const
 Returns a const reference to the component at the given index within its reaction role. More...
 
BasicMoleculegetComponent (std::size_t idx, unsigned int role)
 Returns a reference to the component at the given index within its reaction role. More...
 
BasicMoleculeaddComponent (unsigned int role)
 Adds a new empty component with the specified reaction role. More...
 
BasicMoleculeaddComponent (unsigned int role, const Molecule &mol)
 Creates a new reaction component with the specified role that is a copy of the molecule mol. More...
 
void swapComponentRoles (unsigned int role1, unsigned int role2)
 Swaps the reaction roles of two component groups. More...
 
void removeComponent (std::size_t idx)
 Removes the component at the specified index. More...
 
void removeComponent (std::size_t idx, unsigned int role)
 Removes the component at the given index within its reaction role. More...
 
ComponentIterator removeComponent (const ComponentIterator &it)
 Removes the component referenced by the given iterator. More...
 
void removeComponents (unsigned int role)
 Removes all components with the specified reaction role. More...
 
Reaction::SharedPointer clone () const
 Creates a deep copy of the reaction. More...
 
BasicReactionoperator= (const BasicReaction &rxn)
 Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn. More...
 
void copy (const BasicReaction &rxn)
 Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn. More...
 
void copy (const Reaction &rxn)
 Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn. More...
 
Reactionoperator= (const Reaction &rxn)
 Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn. More...
 
- Public Member Functions inherited from CDPL::Chem::Reaction
virtual ~Reaction ()
 Virtual destructor. More...
 
ConstComponentIterator getComponentsBegin () const
 Returns a constant iterator pointing to the beginning of the reaction components. More...
 
ComponentIterator getComponentsBegin ()
 Returns a mutable iterator pointing to the beginning of the reaction components. More...
 
ConstComponentIterator getComponentsEnd () const
 Returns a constant iterator pointing to the end of the reaction components. More...
 
ComponentIterator getComponentsEnd ()
 Returns a mutable iterator pointing to the end of the reaction components. More...
 
ConstComponentIterator begin () const
 Returns a constant iterator pointing to the beginning of the reaction components. More...
 
ComponentIterator begin ()
 Returns a mutable iterator pointing to the beginning of the reaction components. More...
 
ConstComponentIterator end () const
 Returns a constant iterator pointing to the end of the reaction components. More...
 
ComponentIterator end ()
 Returns a mutable iterator pointing to the end of the reaction components. More...
 
ConstComponentIterator getComponentsBegin (unsigned int role) const
 Returns a constant iterator pointing to the beginning of the reaction components with the specified role. More...
 
ComponentIterator getComponentsBegin (unsigned int role)
 Returns a mutable iterator pointing to the beginning of the reaction components with the specified role. More...
 
ConstComponentIterator getComponentsEnd (unsigned int role) const
 Returns a constant iterator pointing to the end of the reaction components with the specified role. More...
 
ComponentIterator getComponentsEnd (unsigned int role)
 Returns a mutable iterator pointing to the end of the reaction components with the specified role. More...
 
ComponentIterator removeComponent (const ComponentIterator &it)
 Removes the reaction component specified by the iterator it. More...
 
Reactionoperator= (const Reaction &rxn)
 Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn. More...
 
- Public Member Functions inherited from CDPL::Base::PropertyContainer
std::size_t getNumProperties () const
 Returns the number of property entries. More...
 
template<typename T >
void setProperty (const LookupKey &key, T &&val)
 Sets the value of the property specified by key to val. More...
 
template<typename T >
const T & getProperty (const LookupKey &key) const
 Returns the value of the property specified by key as a const reference to an object of type T. More...
 
template<typename T >
const T & getPropertyOrDefault (const LookupKey &key, const T &def_val) const
 Returns the value of the property specified by key as a const reference to an object of type T, or the default value def_val if a stored value does not exist. More...
 
const AnygetProperty (const LookupKey &key, bool throw_=false) const
 Returns the value of the property specified by key. More...
 
bool isPropertySet (const LookupKey &key) const
 Tells whether or not a value has been assigned to the property specified by key. More...
 
ConstPropertyIterator getPropertiesBegin () const
 Returns a constant iterator pointing to the beginning of the property entries. More...
 
ConstPropertyIterator getPropertiesEnd () const
 Returns a constant iterator pointing to the end of the property entries. More...
 
ConstPropertyIterator begin () const
 Returns a constant iterator pointing to the beginning of the property entries. More...
 
ConstPropertyIterator end () const
 Returns a constant iterator pointing to the end of the property entries. More...
 
bool removeProperty (const LookupKey &key)
 Clears the value of the property specified by key. More...
 
void clearProperties ()
 Clears all property values. More...
 
void addProperties (const PropertyContainer &cntnr)
 Adds the property value entries in the PropertyContainer instance cntnr. More...
 
void copyProperties (const PropertyContainer &cntnr)
 Replaces the current set of properties by a copy of the entries in cntnr. More...
 
void swap (PropertyContainer &cntnr)
 Exchanges the properties of this container with the properties of the container cntnr. More...
 
const PropertyContainergetProperties () const
 Returns a const reference to itself. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CDPL::Chem::Reaction
static void registerCopyPostprocessingFunction (const CopyPostprocessingFunction &func)
 Registers a global post-processing function invoked after every reaction copy operation. More...
 
- Protected Member Functions inherited from CDPL::Chem::Reaction
void invokeCopyPostprocessingFunctions (const Reaction &src_rxn)
 Invokes all registered copy post-processing functions with *this as the target reaction and src_rxn as the source. More...
 
- Protected Member Functions inherited from CDPL::Base::PropertyContainer
 PropertyContainer ()
 Constructs an empty PropertyContainer instance. More...
 
 PropertyContainer (const PropertyContainer &cntnr)
 Constructs a copy of the PropertyContainer instance cntnr. More...
 
virtual ~PropertyContainer ()
 Virtual destructor. More...
 
PropertyContaineroperator= (const PropertyContainer &cntnr)
 Assignment operator. More...
 

Detailed Description

Default concrete implementation of the Chem::Reaction abstract interface.

BasicReaction stores reaction components as Chem::BasicMolecule instances grouped by reaction role (reactant, agent, product). Components are pooled via a Util::ObjectPool to minimize allocation overhead in batch processing scenarios.

Member Typedef Documentation

◆ SharedPointer

A reference-counted smart pointer [SHPTR] for dynamically allocated BasicReaction instances.

◆ ComponentIterator

typedef boost::indirect_iterator<ComponentList::iterator, BasicMolecule> CDPL::Chem::BasicReaction::ComponentIterator

A mutable random access iterator used to iterate over the stored Chem::BasicMolecule reaction components.

◆ ConstComponentIterator

typedef boost::indirect_iterator<ComponentList::const_iterator, const BasicMolecule> CDPL::Chem::BasicReaction::ConstComponentIterator

A constant random access iterator used to iterate over the stored const Chem::BasicMolecule reaction components.

Constructor & Destructor Documentation

◆ BasicReaction() [1/3]

CDPL::Chem::BasicReaction::BasicReaction ( )

Constructs an empty BasicReaction instance.

◆ BasicReaction() [2/3]

CDPL::Chem::BasicReaction::BasicReaction ( const BasicReaction rxn)

Constructs a copy of the BasicReaction instance rxn.

Parameters
rxnThe other Reaction instance to copy.

◆ BasicReaction() [3/3]

CDPL::Chem::BasicReaction::BasicReaction ( const Reaction rxn)

Constructs a copy of the Chem::Reaction instance rxn.

Parameters
rxnThe other Chem::Reaction instance to copy.

◆ ~BasicReaction()

CDPL::Chem::BasicReaction::~BasicReaction ( )

Destructor.

Destroys the BasicReaction instance and frees all allocated resources.

Member Function Documentation

◆ getComponentRole()

unsigned int CDPL::Chem::BasicReaction::getComponentRole ( const Molecule mol) const
virtual

Returns the reaction role of the component mol (see namespace Chem::ReactionRole).

Parameters
molThe molecule whose role is requested.
Returns
The reaction role of the component.

Implements CDPL::Chem::Reaction.

◆ getComponentIndex()

std::size_t CDPL::Chem::BasicReaction::getComponentIndex ( const Molecule mol) const
virtual

Returns the index of the component mol in the reaction.

Parameters
molThe molecule whose index is requested.
Returns
The zero-based index of the component.

Implements CDPL::Chem::Reaction.

◆ containsComponent()

bool CDPL::Chem::BasicReaction::containsComponent ( const Molecule mol) const
virtual

Tells whether mol is a component of the reaction.

Parameters
molThe molecule to look up.
Returns
true if mol is a component of the reaction, and false otherwise.

Implements CDPL::Chem::Reaction.

◆ clear()

void CDPL::Chem::BasicReaction::clear ( )
virtual

Removes all components and clears all properties of the reaction.

Implements CDPL::Chem::Reaction.

◆ getNumComponents() [1/2]

std::size_t CDPL::Chem::BasicReaction::getNumComponents ( ) const
virtual

Returns the total number of components in the reaction.

Returns
The total number of components.

Implements CDPL::Chem::Reaction.

◆ getNumComponents() [2/2]

std::size_t CDPL::Chem::BasicReaction::getNumComponents ( unsigned int  role) const
virtual

Returns the number of components with the given reaction role.

Parameters
roleThe reaction role (see namespace Chem::ReactionRole).
Returns
The number of components with the specified role.

Implements CDPL::Chem::Reaction.

◆ getComponentsBegin() [1/4]

ConstComponentIterator CDPL::Chem::BasicReaction::getComponentsBegin ( ) const

Returns a constant iterator pointing to the first component of the reaction.

Returns
A constant iterator pointing to the first component.

◆ getComponentsBegin() [2/4]

ComponentIterator CDPL::Chem::BasicReaction::getComponentsBegin ( )

Returns a mutable iterator pointing to the first component of the reaction.

Returns
A mutable iterator pointing to the first component.

◆ getComponentsEnd() [1/4]

ConstComponentIterator CDPL::Chem::BasicReaction::getComponentsEnd ( ) const

Returns a constant iterator pointing one past the last component of the reaction.

Returns
A constant iterator pointing one past the last component.

◆ getComponentsEnd() [2/4]

ComponentIterator CDPL::Chem::BasicReaction::getComponentsEnd ( )

Returns a mutable iterator pointing one past the last component of the reaction.

Returns
A mutable iterator pointing one past the last component.

◆ getComponentsBegin() [3/4]

ConstComponentIterator CDPL::Chem::BasicReaction::getComponentsBegin ( unsigned int  role) const

Returns a constant iterator pointing to the first component with the given reaction role.

Parameters
roleThe reaction role (see namespace Chem::ReactionRole).
Returns
A constant iterator pointing to the first component with the specified role.

◆ getComponentsBegin() [4/4]

ComponentIterator CDPL::Chem::BasicReaction::getComponentsBegin ( unsigned int  role)

Returns a mutable iterator pointing to the first component with the given reaction role.

Parameters
roleThe reaction role (see namespace Chem::ReactionRole).
Returns
A mutable iterator pointing to the first component with the specified role.

◆ getComponentsEnd() [3/4]

ConstComponentIterator CDPL::Chem::BasicReaction::getComponentsEnd ( unsigned int  role) const

Returns a constant iterator pointing one past the last component with the given reaction role.

Parameters
roleThe reaction role (see namespace Chem::ReactionRole).
Returns
A constant iterator pointing one past the last component with the specified role.

◆ getComponentsEnd() [4/4]

ComponentIterator CDPL::Chem::BasicReaction::getComponentsEnd ( unsigned int  role)

Returns a mutable iterator pointing one past the last component with the given reaction role.

Parameters
roleThe reaction role (see namespace Chem::ReactionRole).
Returns
A mutable iterator pointing one past the last component with the specified role.

◆ getComponent() [1/4]

const BasicMolecule& CDPL::Chem::BasicReaction::getComponent ( std::size_t  idx) const
virtual

Returns a const reference to the component at the specified index.

Parameters
idxThe zero-based component index.
Returns
A const reference to the component.

Implements CDPL::Chem::Reaction.

◆ getComponent() [2/4]

BasicMolecule& CDPL::Chem::BasicReaction::getComponent ( std::size_t  idx)
virtual

Returns a reference to the component at the specified index.

Parameters
idxThe zero-based component index.
Returns
A reference to the component.

Implements CDPL::Chem::Reaction.

◆ getComponent() [3/4]

const BasicMolecule& CDPL::Chem::BasicReaction::getComponent ( std::size_t  idx,
unsigned int  role 
) const
virtual

Returns a const reference to the component at the given index within its reaction role.

Parameters
idxThe zero-based component index within the role.
roleThe reaction role (see namespace Chem::ReactionRole).
Returns
A const reference to the component.

Implements CDPL::Chem::Reaction.

◆ getComponent() [4/4]

BasicMolecule& CDPL::Chem::BasicReaction::getComponent ( std::size_t  idx,
unsigned int  role 
)
virtual

Returns a reference to the component at the given index within its reaction role.

Parameters
idxThe zero-based component index within the role.
roleThe reaction role (see namespace Chem::ReactionRole).
Returns
A reference to the component.

Implements CDPL::Chem::Reaction.

◆ addComponent() [1/2]

BasicMolecule& CDPL::Chem::BasicReaction::addComponent ( unsigned int  role)
virtual

Adds a new empty component with the specified reaction role.

Parameters
roleThe reaction role of the new component (see namespace Chem::ReactionRole).
Returns
A reference to the newly created component molecule.

Implements CDPL::Chem::Reaction.

◆ addComponent() [2/2]

BasicMolecule& CDPL::Chem::BasicReaction::addComponent ( unsigned int  role,
const Molecule mol 
)

Creates a new reaction component with the specified role that is a copy of the molecule mol.

Parameters
roleA flag specifying the reaction role of the new component (see namespace Chem::ReactionRole).
molSpecifies a molecule that provides the data for the new reaction component (note that only explicitly assigned molecule, atom and bond properties will be copied).
Returns
A reference to the newly created component molecule.
Exceptions
Base::ValueErrorif the value of role is not Chem::ReactionRole::REACTANT, Chem::ReactionRole::AGENT or Chem::ReactionRole::PRODUCT.

◆ swapComponentRoles()

void CDPL::Chem::BasicReaction::swapComponentRoles ( unsigned int  role1,
unsigned int  role2 
)
virtual

Swaps the reaction roles of two component groups.

Parameters
role1The first reaction role.
role2The second reaction role.

Implements CDPL::Chem::Reaction.

◆ removeComponent() [1/3]

void CDPL::Chem::BasicReaction::removeComponent ( std::size_t  idx)
virtual

Removes the component at the specified index.

Parameters
idxThe zero-based component index.

Implements CDPL::Chem::Reaction.

◆ removeComponent() [2/3]

void CDPL::Chem::BasicReaction::removeComponent ( std::size_t  idx,
unsigned int  role 
)
virtual

Removes the component at the given index within its reaction role.

Parameters
idxThe zero-based component index within the role.
roleThe reaction role (see namespace Chem::ReactionRole).

Implements CDPL::Chem::Reaction.

◆ removeComponent() [3/3]

ComponentIterator CDPL::Chem::BasicReaction::removeComponent ( const ComponentIterator it)

Removes the component referenced by the given iterator.

Parameters
itIterator referencing the component to remove.
Returns
A mutable iterator pointing to the component following the removed one.

◆ removeComponents()

void CDPL::Chem::BasicReaction::removeComponents ( unsigned int  role)
virtual

Removes all components with the specified reaction role.

Parameters
roleThe reaction role of the components to remove (see namespace Chem::ReactionRole).

Implements CDPL::Chem::Reaction.

◆ clone()

Reaction::SharedPointer CDPL::Chem::BasicReaction::clone ( ) const
virtual

Creates a deep copy of the reaction.

Returns
A smart pointer to the cloned reaction.

Implements CDPL::Chem::Reaction.

◆ operator=() [1/2]

BasicReaction& CDPL::Chem::BasicReaction::operator= ( const BasicReaction rxn)

Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn.

Internally calls copy() to perform the actual work.

Parameters
rxnThe reaction to copy.
Returns
A reference to itself.

◆ copy() [1/2]

void CDPL::Chem::BasicReaction::copy ( const BasicReaction rxn)

Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn.

Parameters
rxnThe reaction to copy.

◆ copy() [2/2]

void CDPL::Chem::BasicReaction::copy ( const Reaction rxn)
virtual

Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn.

Parameters
rxnThe reaction to copy.

Implements CDPL::Chem::Reaction.

◆ operator=() [2/2]

Reaction& CDPL::Chem::Reaction::operator=

Replaces the current set of reaction components and properties by a copy of the components and properties of the reaction rxn.

Internally calls copy() to perform the actual work.

Parameters
rxnThe reaction to copy.
Returns
A reference to itself.

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