Chemical Data Processing Library C++ API - Version 1.1.1
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 
53  {
54 
56  typedef ComponentCache::SharedObjectPointer ComponentPtr;
57  typedef std::vector<ComponentPtr> ComponentList;
58 
59  public:
63  typedef std::shared_ptr<BasicReaction> SharedPointer;
64 
65 
66  typedef boost::indirect_iterator<ComponentList::iterator, BasicMolecule> ComponentIterator;
67  typedef boost::indirect_iterator<ComponentList::const_iterator, const BasicMolecule> ConstComponentIterator;
68 
73 
79 
84  BasicReaction(const Reaction& rxn);
85 
92 
93  unsigned int getComponentRole(const Molecule& mol) const;
94 
95  std::size_t getComponentIndex(const Molecule& mol) const;
96 
97  bool containsComponent(const Molecule& mol) const;
98 
99  void clear();
100 
101  std::size_t getNumComponents() const;
102 
103  std::size_t getNumComponents(unsigned int role) const;
104 
106 
108 
110 
112 
113  ConstComponentIterator getComponentsBegin(unsigned int role) const;
114 
116 
117  ConstComponentIterator getComponentsEnd(unsigned int role) const;
118 
120 
121  const BasicMolecule& getComponent(std::size_t idx) const;
122 
123  BasicMolecule& getComponent(std::size_t idx);
124 
125  const BasicMolecule& getComponent(std::size_t idx, unsigned int role) const;
126 
127  BasicMolecule& getComponent(std::size_t idx, unsigned int role);
128 
129  BasicMolecule& addComponent(unsigned int role);
130 
140  BasicMolecule& addComponent(unsigned int role, const Molecule& mol);
141 
142  void swapComponentRoles(unsigned int role1, unsigned int role2);
143 
144  void removeComponent(std::size_t idx);
145 
146  void removeComponent(std::size_t idx, unsigned int role);
147 
149 
150  void removeComponents(unsigned int role);
151 
153 
164 
165  using Reaction::operator=;
166 
172  void copy(const BasicReaction& rxn);
173 
174  void copy(const Reaction& rxn);
175 
176  private:
177  ConstComponentIterator getReactantsBegin() const;
178  ComponentIterator getReactantsBegin();
179 
180  ConstComponentIterator getReactantsEnd() const;
181  ComponentIterator getReactantsEnd();
182 
183  ConstComponentIterator getAgentsBegin() const;
184  ComponentIterator getAgentsBegin();
185 
186  ConstComponentIterator getAgentsEnd() const;
187  ComponentIterator getAgentsEnd();
188 
189  ConstComponentIterator getProductsBegin() const;
190  ComponentIterator getProductsBegin();
191 
192  ConstComponentIterator getProductsEnd() const;
193  ComponentIterator getProductsEnd();
194 
195  const BasicMolecule& getReactant(std::size_t idx) const;
196  BasicMolecule& getReactant(std::size_t idx);
197 
198  const BasicMolecule& getAgent(std::size_t idx) const;
199  BasicMolecule& getAgent(std::size_t idx);
200 
201  const BasicMolecule& getProduct(std::size_t idx) const;
202  BasicMolecule& getProduct(std::size_t idx);
203 
204  void removeReactant(std::size_t idx);
205  void removeAgent(std::size_t idx);
206  void removeProduct(std::size_t idx);
207 
208  void removeReactants();
209  void removeAgents();
210  void removeProducts();
211 
212  BasicMolecule& addComponent(unsigned int role, const Molecule* mol);
213 
214  BasicMolecule& addReactant(const Molecule* mol);
215  BasicMolecule& addAgent(const Molecule* mol);
216  BasicMolecule& addProduct(const Molecule* mol);
217 
218  void clearComponents();
219 
220  void copyComponents(const BasicReaction& rxn);
221  void copyComponents(const Reaction& rxn);
222 
223  ComponentPtr allocComponent(const Molecule* mol);
224 
225  ComponentCache compCache;
226  ComponentList components;
227  std::size_t agentsStartIdx;
228  std::size_t productsStartIdx;
229  };
230  } // namespace Chem
231 } // namespace CDPL
232 
233 #endif // CDPL_CHEM_BASICREACTION_HPP
ObjectPool.hpp
Definition of the class CDPL::Util::ObjectPool.
CDPL::Chem::BasicReaction::getComponent
const BasicMolecule & getComponent(std::size_t idx) const
Returns a const reference to the reaction component at index idx.
CDPL::Chem::BasicReaction::clear
void clear()
Removes all components and clears all properties of the reaction.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL::Chem::BasicReaction::removeComponent
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.
CDPL::Chem::BasicReaction::copy
void copy(const BasicReaction &rxn)
Replaces the current set of reaction components and properties by a copy of the components and proper...
CDPL::Chem::BasicReaction::getComponentsEnd
ConstComponentIterator getComponentsEnd() const
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::BasicReaction::copy
void copy(const Reaction &rxn)
Replaces the current set of reaction components and properties by a copy of the components and proper...
CDPL::Chem::BasicMolecule
BasicMolecule.
Definition: BasicMolecule.hpp:54
CDPL::Chem::BasicReaction::removeComponent
void removeComponent(std::size_t idx)
Removes the reaction component at the specified index.
CDPL::Chem::BasicReaction::getNumComponents
std::size_t getNumComponents() const
Returns the number of reaction components.
CDPL::Chem::BasicReaction::BasicReaction
BasicReaction(const BasicReaction &rxn)
Constructs a copy of the BasicReaction instance rxn.
CDPL::Chem::BasicReaction::getComponentsBegin
ConstComponentIterator getComponentsBegin() const
CDPL::Chem::BasicReaction::getNumComponents
std::size_t getNumComponents(unsigned int role) const
Returns the number of reaction components with the specified role.
CDPL::Chem::BasicReaction::containsComponent
bool containsComponent(const Molecule &mol) const
Tells whether the specified molecule is a component of this reaction.
CDPL::Chem::Molecule
Molecule.
Definition: Molecule.hpp:49
CDPL::Chem::BasicReaction::BasicReaction
BasicReaction()
Constructs an empty BasicReaction instance.
CDPL::Chem::BasicReaction::getComponentsBegin
ComponentIterator getComponentsBegin(unsigned int role)
CDPL::Chem::BasicReaction::getComponentsEnd
ComponentIterator getComponentsEnd(unsigned int role)
CDPL::Util::ObjectPool< BasicMolecule >
CDPL::Chem::Reaction::SharedPointer
std::shared_ptr< Reaction > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Reaction instances.
Definition: Reaction.hpp:55
CDPL::Chem::clearComponents
CDPL_CHEM_API void clearComponents(MolecularGraph &molgraph)
CDPL::Chem::BasicReaction::getComponentIndex
std::size_t getComponentIndex(const Molecule &mol) const
Returns the index of the specified reaction component.
Reaction.hpp
Definition of the class CDPL::Chem::Reaction.
CDPL::Chem::BasicReaction::getComponent
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...
CDPL::Chem::BasicReaction::addComponent
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.
CDPL::Chem::BasicReaction::swapComponentRoles
void swapComponentRoles(unsigned int role1, unsigned int role2)
Swaps the reaction roles of the component sets specified by role1 and role2.
CDPL::Chem::BasicReaction::SharedPointer
std::shared_ptr< BasicReaction > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated BasicReaction instances.
Definition: BasicReaction.hpp:63
CDPL::Chem::BasicReaction::clone
Reaction::SharedPointer clone() const
Creates a copy of the current reaction state.
CDPL::Chem::BasicReaction::getComponentsEnd
ComponentIterator getComponentsEnd()
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::Reaction
Reaction.
Definition: Reaction.hpp:52
CDPL::Chem::BasicReaction::addComponent
BasicMolecule & addComponent(unsigned int role)
Creates a new reaction component with the specified role.
CDPL::Chem::BasicReaction::~BasicReaction
~BasicReaction()
Destructor.
CDPL::Chem::BasicReaction::getComponent
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...
CDPL::Chem::BasicReaction::getComponentsEnd
ConstComponentIterator getComponentsEnd(unsigned int role) const
CDPL::Chem::BasicReaction::getComponentRole
unsigned int getComponentRole(const Molecule &mol) const
Returns the reaction role of the specified component.
CDPL::Chem::BasicReaction::removeComponents
void removeComponents(unsigned int role)
Removes all components with the specified role.
CDPL::Chem::BasicReaction::ConstComponentIterator
boost::indirect_iterator< ComponentList::const_iterator, const BasicMolecule > ConstComponentIterator
Definition: BasicReaction.hpp:67
CDPL::Chem::BasicReaction::getComponentsBegin
ConstComponentIterator getComponentsBegin(unsigned int role) const
CDPL::Chem::BasicReaction
BasicReaction.
Definition: BasicReaction.hpp:53
CDPL::Chem::BasicReaction::ComponentIterator
boost::indirect_iterator< ComponentList::iterator, BasicMolecule > ComponentIterator
Definition: BasicReaction.hpp:66
CDPL::Chem::BasicReaction::getComponentsBegin
ComponentIterator getComponentsBegin()
CDPL::Chem::BasicReaction::BasicReaction
BasicReaction(const Reaction &rxn)
Constructs a copy of the Chem::Reaction instance rxn.
CDPL::Chem::BasicReaction::removeComponent
ComponentIterator removeComponent(const ComponentIterator &it)
CDPL::Chem::BasicReaction::operator=
BasicReaction & operator=(const BasicReaction &rxn)
Replaces the current set of reaction components and properties by a copy of the components and proper...
CDPL::Chem::BasicReaction::getComponent
BasicMolecule & getComponent(std::size_t idx)
Returns a non-const reference to the reaction component at index idx.
BasicMolecule.hpp
Definition of the class CDPL::Chem::BasicMolecule.