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 
56  {
57 
59  typedef ComponentCache::SharedObjectPointer ComponentPtr;
60  typedef std::vector<ComponentPtr> ComponentList;
61 
62  public:
66  typedef std::shared_ptr<BasicReaction> SharedPointer;
67 
71  typedef boost::indirect_iterator<ComponentList::iterator, BasicMolecule> ComponentIterator;
72 
76  typedef boost::indirect_iterator<ComponentList::const_iterator, const BasicMolecule> ConstComponentIterator;
77 
82 
88 
93  BasicReaction(const Reaction& rxn);
94 
101 
102  unsigned int getComponentRole(const Molecule& mol) const;
103 
104  std::size_t getComponentIndex(const Molecule& mol) const;
105 
106  bool containsComponent(const Molecule& mol) const;
107 
108  void clear();
109 
110  std::size_t getNumComponents() const;
111 
112  std::size_t getNumComponents(unsigned int role) const;
113 
119 
125 
131 
137 
147  ConstComponentIterator getComponentsBegin(unsigned int role) const;
148 
159 
169  ConstComponentIterator getComponentsEnd(unsigned int role) const;
170 
181 
182  const BasicMolecule& getComponent(std::size_t idx) const;
183 
184  BasicMolecule& getComponent(std::size_t idx);
185 
186  const BasicMolecule& getComponent(std::size_t idx, unsigned int role) const;
187 
188  BasicMolecule& getComponent(std::size_t idx, unsigned int role);
189 
190  BasicMolecule& addComponent(unsigned int role);
191 
201  BasicMolecule& addComponent(unsigned int role, const Molecule& mol);
202 
203  void swapComponentRoles(unsigned int role1, unsigned int role2);
204 
205  void removeComponent(std::size_t idx);
206 
207  void removeComponent(std::size_t idx, unsigned int role);
208 
215 
216  void removeComponents(unsigned int role);
217 
219 
230 
231  using Reaction::operator=;
232 
238  void copy(const BasicReaction& rxn);
239 
240  void copy(const Reaction& rxn);
241 
242  private:
243  ConstComponentIterator getReactantsBegin() const;
244  ComponentIterator getReactantsBegin();
245 
246  ConstComponentIterator getReactantsEnd() const;
247  ComponentIterator getReactantsEnd();
248 
249  ConstComponentIterator getAgentsBegin() const;
250  ComponentIterator getAgentsBegin();
251 
252  ConstComponentIterator getAgentsEnd() const;
253  ComponentIterator getAgentsEnd();
254 
255  ConstComponentIterator getProductsBegin() const;
256  ComponentIterator getProductsBegin();
257 
258  ConstComponentIterator getProductsEnd() const;
259  ComponentIterator getProductsEnd();
260 
267  const BasicMolecule& getReactant(std::size_t idx) const;
268 
275  BasicMolecule& getReactant(std::size_t idx);
276 
283  const BasicMolecule& getAgent(std::size_t idx) const;
284 
291  BasicMolecule& getAgent(std::size_t idx);
292 
299  const BasicMolecule& getProduct(std::size_t idx) const;
300 
307  BasicMolecule& getProduct(std::size_t idx);
308 
314  void removeReactant(std::size_t idx);
315 
321  void removeAgent(std::size_t idx);
322 
328  void removeProduct(std::size_t idx);
329 
333  void removeReactants();
334 
338  void removeAgents();
339 
343  void removeProducts();
344 
351  BasicMolecule& addComponent(unsigned int role, const Molecule* mol);
352 
358  BasicMolecule& addReactant(const Molecule* mol);
359 
365  BasicMolecule& addAgent(const Molecule* mol);
366 
372  BasicMolecule& addProduct(const Molecule* mol);
373 
377  void clearComponents();
378 
383  void copyComponents(const BasicReaction& rxn);
384 
389  void copyComponents(const Reaction& rxn);
390 
391  ComponentPtr allocComponent(const Molecule* mol);
392 
393  ComponentCache compCache;
394  ComponentList components;
395  std::size_t agentsStartIdx;
396  std::size_t productsStartIdx;
397  };
398  } // namespace Chem
399 } // namespace CDPL
400 
401 #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.
Default implementation of the Chem::Molecule interface.
Definition: BasicMolecule.hpp:58
Default implementation of the Chem::Reaction interface.
Definition: BasicReaction.hpp:56
BasicReaction(const BasicReaction &rxn)
Constructs a BasicReaction instance that is a copy of the reaction 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:76
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:71
ConstComponentIterator getComponentsEnd(unsigned int role) const
Returns a constant iterator pointing to the end of the reaction components with the specified role.
ComponentIterator getComponentsEnd(unsigned int role)
Returns a mutable iterator pointing to the end of the reaction components with the specified role.
ComponentIterator getComponentsEnd()
Returns a mutable iterator pointing to the end of the reaction components.
std::size_t getNumComponents() const
Returns the total number of reaction components.
void removeComponents(unsigned int role)
Removes all components with the specified 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 beginning of the reaction components with the specified r...
BasicReaction()
Constructs an empty BasicReaction instance.
std::size_t getNumComponents(unsigned int role) const
Returns the number of reaction components with the specified role.
ComponentIterator getComponentsBegin(unsigned int role)
Returns a mutable iterator pointing to the beginning of the reaction components with the specified ro...
bool containsComponent(const Molecule &mol) const
Tells whether the specified molecule is a component of this reaction.
std::shared_ptr< BasicReaction > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated BasicReaction instances.
Definition: BasicReaction.hpp:66
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 reaction component at index idx in the list of components with the specified role.
unsigned int getComponentRole(const Molecule &mol) const
Returns the reaction role of the specified component.
void swapComponentRoles(unsigned int role1, unsigned int role2)
Swaps the reaction roles of the component sets specified by role1 and role2.
void clear()
Removes all components and clears all properties of the reaction.
BasicReaction(const Reaction &rxn)
Constructs a BasicReaction instance that is a copy of the reaction rxn.
Reaction::SharedPointer clone() const
Creates a deep copy of the current reaction state.
ConstComponentIterator getComponentsBegin() const
Returns a constant iterator pointing to the beginning of the reaction components.
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 reaction component at the specified index.
ConstComponentIterator getComponentsEnd() const
Returns a constant iterator pointing to the end of the reaction components.
BasicMolecule & getComponent(std::size_t idx)
Returns a non-const reference to the reaction component at index idx.
const BasicMolecule & getComponent(std::size_t idx) const
Returns a const reference to the reaction component at index idx.
BasicMolecule & addComponent(unsigned int role)
Creates a new reaction component with the specified role.
ComponentIterator getComponentsBegin()
Returns a mutable iterator pointing to the beginning of the reaction components.
BasicMolecule & getComponent(std::size_t idx, unsigned int role)
Returns a non-const reference to the reaction component at index idx in the list of components with t...
const BasicMolecule & getComponent(std::size_t idx, unsigned int role) const
Returns a const reference to the reaction component at index idx in the list of components with the s...
std::size_t getComponentIndex(const Molecule &mol) const
Returns the index of the specified reaction component.
Abstract base class representing a mutable molecular graph that owns and manages its atoms and bonds.
Definition: Molecule.hpp:53
Abstract base class for chemical reactions composed of role-tagged reaction components of type Chem::...
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)
Clears the value of the Chem::MolecularGraphProperty::COMPONENTS property of the molecular graph molg...
The namespace of the Chemical Data Processing Library.