Chemical Data Processing Library C++ API - Version 1.4.0
BasicReaction.hpp
Go to the documentation of this file.
1 /*
2  * BasicReaction.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_CHEM_BASICREACTION_HPP
30 #define CDPL_CHEM_BASICREACTION_HPP
31 
32 #include <vector>
33 #include <memory>
34 
35 #include <boost/iterator/indirect_iterator.hpp>
36 
37 #include "CDPL/Chem/APIPrefix.hpp"
38 #include "CDPL/Chem/Reaction.hpp"
40 #include "CDPL/Util/ObjectPool.hpp"
41 
42 
43 namespace CDPL
44 {
45 
46  namespace Chem
47  {
48 
57  {
58 
60  typedef ComponentCache::SharedObjectPointer ComponentPtr;
61  typedef std::vector<ComponentPtr> ComponentList;
62 
63  public:
67  typedef std::shared_ptr<BasicReaction> SharedPointer;
68 
69 
73  typedef boost::indirect_iterator<ComponentList::iterator, BasicMolecule> ComponentIterator;
74 
78  typedef boost::indirect_iterator<ComponentList::const_iterator, const BasicMolecule> ConstComponentIterator;
79 
84 
90 
95  BasicReaction(const Reaction& rxn);
96 
103 
109  unsigned int getComponentRole(const Molecule& mol) const;
110 
116  std::size_t getComponentIndex(const Molecule& mol) const;
117 
123  bool containsComponent(const Molecule& mol) const;
124 
128  void clear();
129 
134  std::size_t getNumComponents() const;
135 
141  std::size_t getNumComponents(unsigned int role) const;
142 
148 
154 
160 
166 
172  ConstComponentIterator getComponentsBegin(unsigned int role) const;
173 
180 
186  ConstComponentIterator getComponentsEnd(unsigned int role) const;
187 
194 
200  const BasicMolecule& getComponent(std::size_t idx) const;
201 
207  BasicMolecule& getComponent(std::size_t idx);
208 
215  const BasicMolecule& getComponent(std::size_t idx, unsigned int role) const;
216 
223  BasicMolecule& getComponent(std::size_t idx, unsigned int role);
224 
230  BasicMolecule& addComponent(unsigned int role);
231 
241  BasicMolecule& addComponent(unsigned int role, const Molecule& mol);
242 
248  void swapComponentRoles(unsigned int role1, unsigned int role2);
249 
254  void removeComponent(std::size_t idx);
255 
261  void removeComponent(std::size_t idx, unsigned int role);
262 
269 
274  void removeComponents(unsigned int role);
275 
281 
292 
293  using Reaction::operator=;
294 
300  void copy(const BasicReaction& rxn);
301 
307  void copy(const Reaction& rxn);
308 
309  private:
310  ConstComponentIterator getReactantsBegin() const;
311  ComponentIterator getReactantsBegin();
312 
313  ConstComponentIterator getReactantsEnd() const;
314  ComponentIterator getReactantsEnd();
315 
316  ConstComponentIterator getAgentsBegin() const;
317  ComponentIterator getAgentsBegin();
318 
319  ConstComponentIterator getAgentsEnd() const;
320  ComponentIterator getAgentsEnd();
321 
322  ConstComponentIterator getProductsBegin() const;
323  ComponentIterator getProductsBegin();
324 
325  ConstComponentIterator getProductsEnd() const;
326  ComponentIterator getProductsEnd();
327 
334  const BasicMolecule& getReactant(std::size_t idx) const;
335 
342  BasicMolecule& getReactant(std::size_t idx);
343 
350  const BasicMolecule& getAgent(std::size_t idx) const;
351 
358  BasicMolecule& getAgent(std::size_t idx);
359 
366  const BasicMolecule& getProduct(std::size_t idx) const;
367 
374  BasicMolecule& getProduct(std::size_t idx);
375 
381  void removeReactant(std::size_t idx);
382 
388  void removeAgent(std::size_t idx);
389 
395  void removeProduct(std::size_t idx);
396 
400  void removeReactants();
401 
405  void removeAgents();
406 
410  void removeProducts();
411 
418  BasicMolecule& addComponent(unsigned int role, const Molecule* mol);
419 
425  BasicMolecule& addReactant(const Molecule* mol);
426 
432  BasicMolecule& addAgent(const Molecule* mol);
433 
439  BasicMolecule& addProduct(const Molecule* mol);
440 
444  void clearComponents();
445 
450  void copyComponents(const BasicReaction& rxn);
451 
456  void copyComponents(const Reaction& rxn);
457 
458  ComponentPtr allocComponent(const Molecule* mol);
459 
460  ComponentCache compCache;
461  ComponentList components;
462  std::size_t agentsStartIdx;
463  std::size_t productsStartIdx;
464  };
465  } // namespace Chem
466 } // namespace CDPL
467 
468 #endif // CDPL_CHEM_BASICREACTION_HPP
Definition of class CDPL::Chem::BasicMolecule.
Definition of the preprocessor macro CDPL_CHEM_API.
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of class CDPL::Util::ObjectPool.
Definition of class CDPL::Chem::Reaction.
Concrete Chem::Molecule implementation that owns Chem::BasicAtom and Chem::BasicBond instances.
Definition: BasicMolecule.hpp:60
Default concrete implementation of the Chem::Reaction abstract interface.
Definition: BasicReaction.hpp:57
BasicReaction(const BasicReaction &rxn)
Constructs a copy of the BasicReaction instance rxn.
boost::indirect_iterator< ComponentList::const_iterator, const BasicMolecule > ConstComponentIterator
A constant random access iterator used to iterate over the stored const Chem::BasicMolecule reaction ...
Definition: BasicReaction.hpp:78
ComponentIterator removeComponent(const ComponentIterator &it)
Removes the component referenced by the given iterator.
void copy(const BasicReaction &rxn)
Replaces the current set of reaction components and properties by a copy of the components and proper...
boost::indirect_iterator< ComponentList::iterator, BasicMolecule > ComponentIterator
A mutable random access iterator used to iterate over the stored Chem::BasicMolecule reaction compone...
Definition: BasicReaction.hpp:73
ConstComponentIterator getComponentsEnd(unsigned int role) const
Returns a constant iterator pointing one past the last component with the given reaction role.
ComponentIterator getComponentsEnd(unsigned int role)
Returns a mutable iterator pointing one past the last component with the given reaction role.
ComponentIterator getComponentsEnd()
Returns a mutable iterator pointing one past the last component of the reaction.
std::size_t getNumComponents() const
Returns the total number of components in the reaction.
void removeComponents(unsigned int role)
Removes all components with the specified reaction role.
BasicReaction & operator=(const BasicReaction &rxn)
Replaces the current set of reaction components and properties by a copy of the components and proper...
ConstComponentIterator getComponentsBegin(unsigned int role) const
Returns a constant iterator pointing to the first component with the given reaction role.
BasicReaction()
Constructs an empty BasicReaction instance.
std::size_t getNumComponents(unsigned int role) const
Returns the number of components with the given reaction role.
ComponentIterator getComponentsBegin(unsigned int role)
Returns a mutable iterator pointing to the first component with the given reaction role.
bool containsComponent(const Molecule &mol) const
Tells whether mol is a component of the reaction.
std::shared_ptr< BasicReaction > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated BasicReaction instances.
Definition: BasicReaction.hpp:67
BasicMolecule & addComponent(unsigned int role, const Molecule &mol)
Creates a new reaction component with the specified role that is a copy of the molecule mol.
void removeComponent(std::size_t idx, unsigned int role)
Removes the component at the given index within its reaction role.
unsigned int getComponentRole(const Molecule &mol) const
Returns the reaction role of the component mol (see namespace Chem::ReactionRole).
void swapComponentRoles(unsigned int role1, unsigned int role2)
Swaps the reaction roles of two component groups.
void clear()
Removes all components and clears all properties of the reaction.
BasicReaction(const Reaction &rxn)
Constructs a copy of the Chem::Reaction instance rxn.
Reaction::SharedPointer clone() const
Creates a deep copy of the reaction.
ConstComponentIterator getComponentsBegin() const
Returns a constant iterator pointing to the first component of the reaction.
void copy(const Reaction &rxn)
Replaces the current set of reaction components and properties by a copy of the components and proper...
void removeComponent(std::size_t idx)
Removes the component at the specified index.
ConstComponentIterator getComponentsEnd() const
Returns a constant iterator pointing one past the last component of the reaction.
BasicMolecule & getComponent(std::size_t idx)
Returns a reference to the component at the specified index.
const BasicMolecule & getComponent(std::size_t idx) const
Returns a const reference to the component at the specified index.
BasicMolecule & addComponent(unsigned int role)
Adds a new empty component with the specified reaction role.
ComponentIterator getComponentsBegin()
Returns a mutable iterator pointing to the first component of the reaction.
BasicMolecule & getComponent(std::size_t idx, unsigned int role)
Returns a reference to the component at the given index within its reaction role.
const BasicMolecule & getComponent(std::size_t idx, unsigned int role) const
Returns a const reference to the component at the given index within its reaction role.
std::size_t getComponentIndex(const Molecule &mol) const
Returns the index of the component mol in the reaction.
Abstract base class representing a mutable molecular graph that owns its atoms and bonds.
Definition: Molecule.hpp:53
Abstract base class for chemical reactions composed of role-tagged Chem::Molecule components.
Definition: Reaction.hpp:59
std::shared_ptr< Reaction > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Reaction instances.
Definition: Reaction.hpp:62
std::shared_ptr< ObjectType > SharedObjectPointer
A smart pointer to a borrowed object that returns the object to the pool on destruction.
Definition: ObjectPool.hpp:71
CDPL_CHEM_API void clearComponents(MolecularGraph &molgraph)
Removes the Chem::MolecularGraphProperty::COMPONENTS property from molgraph.
The namespace of the Chemical Data Processing Library.