Chemical Data Processing Library C++ API - Version 1.0.0
Reaction.hpp
Go to the documentation of this file.
1 /*
2  * Reaction.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_REACTION_HPP
30 #define CDPL_CHEM_REACTION_HPP
31 
32 #include <memory>
33 
34 #include "CDPL/Chem/APIPrefix.hpp"
37 
38 
39 namespace CDPL
40 {
41 
42  namespace Chem
43  {
44 
45  class Molecule;
46 
51  {
52 
53  class ConstComponentAccessor;
54  class ComponentAccessor;
55 
56  public:
60  typedef std::shared_ptr<Reaction> SharedPointer;
61 
66 
71 
75  virtual ~Reaction() {}
76 
80  virtual void clear() = 0;
81 
86  virtual std::size_t getNumComponents() const = 0;
87 
95  virtual std::size_t getNumComponents(unsigned int role) const = 0;
96 
105  virtual unsigned int getComponentRole(const Molecule& mol) const = 0;
106 
113  virtual std::size_t getComponentIndex(const Molecule& mol) const = 0;
114 
120  virtual bool containsComponent(const Molecule& mol) const = 0;
121 
127 
133 
139 
145 
151 
157 
163 
169 
179  ConstComponentIterator getComponentsBegin(unsigned int role) const;
180 
191 
201  ConstComponentIterator getComponentsEnd(unsigned int role) const;
202 
213 
220  virtual const Molecule& getComponent(std::size_t idx) const = 0;
221 
228  virtual Molecule& getComponent(std::size_t idx) = 0;
229 
241  virtual const Molecule& getComponent(std::size_t idx, unsigned int role) const = 0;
242 
254  virtual Molecule& getComponent(std::size_t idx, unsigned int role) = 0;
255 
263  virtual Molecule& addComponent(unsigned int role) = 0;
264 
275  virtual void swapComponentRoles(unsigned int role1, unsigned int role2) = 0;
276 
282  virtual void removeComponent(std::size_t idx) = 0;
283 
293  virtual void removeComponent(std::size_t idx, unsigned int role) = 0;
294 
303 
310  virtual void removeComponents(unsigned int role) = 0;
311 
316  virtual SharedPointer clone() const = 0;
317 
323  virtual void copy(const Reaction& rxn) = 0;
324 
334  Reaction& operator=(const Reaction& rxn);
335 
336  private:
337  class CDPL_CHEM_API ConstComponentAccessor
338  {
339 
340  friend class Reaction;
341 
342  public:
343  ConstComponentAccessor(const ComponentAccessor& accessor):
344  reaction(accessor.reaction), compRole(accessor.compRole) {}
345  ConstComponentAccessor(const Reaction* rxn, unsigned int role):
346  reaction(rxn), compRole(role) {}
347 
348  const Molecule& operator()(std::size_t idx) const;
349 
350  bool operator==(const ConstComponentAccessor& accessor) const;
351 
352  private:
353  const Reaction* reaction;
354  unsigned int compRole;
355  };
356 
357  class CDPL_CHEM_API ComponentAccessor
358  {
359 
360  friend class Reaction;
361  friend class ConstComponentAccessor;
362 
363  public:
364  ComponentAccessor(Reaction* rxn, unsigned int role):
365  reaction(rxn), compRole(role) {}
366 
367  Molecule& operator()(std::size_t idx) const;
368 
369  bool operator==(const ComponentAccessor& accessor) const;
370 
371  private:
372  Reaction* reaction;
373  unsigned int compRole;
374  };
375  };
376  } // namespace Chem
377 } // namespace CDPL
378 
379 #endif // CDPL_CHEM_REACTION_HPP
CDPL::Chem::Reaction::begin
ComponentIterator begin()
Returns a mutable iterator pointing to the beginning of the reaction components.
CDPL::Chem::Reaction::removeComponent
ComponentIterator removeComponent(const ComponentIterator &it)
Removes the reaction component specified by the iterator it.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL::Chem::Reaction::addComponent
virtual Molecule & addComponent(unsigned int role)=0
Creates a new reaction component with the specified role.
IndexedElementIterator.hpp
Definition of the class CDPL::Util::IndexedElementIterator.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Math::operator==
GridEquality< E1, E2 >::ResultType operator==(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Definition: GridExpression.hpp:339
CDPL::Chem::Reaction::containsComponent
virtual bool containsComponent(const Molecule &mol) const =0
Tells whether the specified molecule is a component of this reaction.
CDPL::Util::IndexedElementIterator
A STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
CDPL::Chem::Reaction::getNumComponents
virtual std::size_t getNumComponents() const =0
Returns the number of reaction components.
CDPL::Chem::Reaction::copy
virtual void copy(const Reaction &rxn)=0
Replaces the current set of reaction components and properties by a copy of the components and proper...
CDPL::Chem::Molecule
Molecule.
Definition: Molecule.hpp:48
CDPL::Chem::Reaction::removeComponent
virtual void removeComponent(std::size_t idx)=0
Removes the reaction component at the specified index.
CDPL::Chem::Reaction::getComponent
virtual Molecule & getComponent(std::size_t idx)=0
Returns a non-const reference to the reaction component at index idx.
CDPL::Chem::Reaction::getComponentsEnd
ConstComponentIterator getComponentsEnd(unsigned int role) const
Returns a constant iterator pointing to the end of the reaction components with the specified role.
CDPL::Chem::Reaction::begin
ConstComponentIterator begin() const
Returns a constant iterator pointing to the beginning of the reaction components.
CDPL::Chem::Reaction::getComponent
virtual const Molecule & getComponent(std::size_t idx, unsigned int role) const =0
Returns a const reference to the reaction component at index idx in the list of components with the s...
CDPL::Chem::Reaction::getComponentsBegin
ConstComponentIterator getComponentsBegin() const
Returns a constant iterator pointing to the beginning of the reaction components.
CDPL::Chem::Reaction::SharedPointer
std::shared_ptr< Reaction > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Reaction instances.
Definition: Reaction.hpp:54
CDPL::Chem::Reaction::getComponent
virtual const Molecule & getComponent(std::size_t idx) const =0
Returns a const reference to the reaction component at index idx.
CDPL::Chem::Reaction::getNumComponents
virtual std::size_t getNumComponents(unsigned int role) const =0
Returns the number of reaction components with the specified role.
CDPL::Chem::Reaction::getComponentsEnd
ConstComponentIterator getComponentsEnd() const
Returns a constant iterator pointing to the end of the reaction components.
CDPL::Chem::Reaction::ComponentIterator
Util::IndexedElementIterator< Molecule, ComponentAccessor > ComponentIterator
A mutable random access iterator used to iterate over the components of the reaction.
Definition: Reaction.hpp:70
CDPL::Chem::Reaction::getComponentRole
virtual unsigned int getComponentRole(const Molecule &mol) const =0
Returns the reaction role of the specified component.
CDPL::Base::PropertyContainer
A class providing methods for the storage and lookup of object properties.
Definition: PropertyContainer.hpp:75
CDPL::Chem::Reaction::getComponentsBegin
ComponentIterator getComponentsBegin(unsigned int role)
Returns a mutable iterator pointing to the beginning of the reaction components with the specified ro...
CDPL::Chem::Reaction::clone
virtual SharedPointer clone() const =0
Creates a copy of the current reaction state.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::Reaction::getComponentsBegin
ConstComponentIterator getComponentsBegin(unsigned int role) const
Returns a constant iterator pointing to the beginning of the reaction components with the specified r...
CDPL::Chem::Reaction
Reaction.
Definition: Reaction.hpp:51
CDPL::Chem::Reaction::getComponentsBegin
ComponentIterator getComponentsBegin()
Returns a mutable iterator pointing to the beginning of the reaction components.
CDPL::Chem::Reaction::removeComponent
virtual void removeComponent(std::size_t idx, unsigned int role)=0
Removes the reaction component at index idx in the list of components with the specified role.
CDPL::Chem::Reaction::end
ConstComponentIterator end() const
Returns a constant iterator pointing to the end of the reaction components.
CDPL::Chem::Reaction::~Reaction
virtual ~Reaction()
Virtual destructor.
Definition: Reaction.hpp:75
CDPL::Chem::Reaction::getComponentsEnd
ComponentIterator getComponentsEnd(unsigned int role)
Returns a mutable iterator pointing to the end of the reaction components with the specified role.
CDPL::Chem::Reaction::ConstComponentIterator
Util::IndexedElementIterator< const Molecule, ConstComponentAccessor > ConstComponentIterator
A constant random access iterator used to iterate over the components of the reaction.
Definition: Reaction.hpp:65
CDPL::Chem::Reaction::getComponentIndex
virtual std::size_t getComponentIndex(const Molecule &mol) const =0
Returns the index of the specified reaction component.
CDPL::Chem::Reaction::clear
virtual void clear()=0
Removes all components and clears all properties of the reaction.
PropertyContainer.hpp
Definition of the class CDPL::Base::PropertyContainer.
CDPL::Chem::Reaction::getComponent
virtual Molecule & getComponent(std::size_t idx, unsigned int role)=0
Returns a non-const reference to the reaction component at index idx in the list of components with t...
CDPL::Chem::Reaction::getComponentsEnd
ComponentIterator getComponentsEnd()
Returns a mutable iterator pointing to the end of the reaction components.
CDPL::Chem::Reaction::swapComponentRoles
virtual void swapComponentRoles(unsigned int role1, unsigned int role2)=0
Swaps the reaction roles of the component sets specified by role1 and role2.
CDPL::Chem::Reaction::removeComponents
virtual void removeComponents(unsigned int role)=0
Removes all components with the specified role.
CDPL::Chem::Reaction::end
ComponentIterator end()
Returns a mutable iterator pointing to the end of the reaction components.