Chemical Data Processing Library C++ API - Version 1.4.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 #include <functional>
34 
35 #include "CDPL/Chem/APIPrefix.hpp"
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Chem
44  {
45 
46  class Molecule;
47 
59  {
60 
61  class ConstComponentAccessor;
62  class ComponentAccessor;
63 
64  public:
68  typedef std::shared_ptr<Reaction> SharedPointer;
69 
74 
79 
88  typedef std::function<void(Reaction&, const Reaction&)> CopyPostprocessingFunction;
89 
93  virtual ~Reaction() {}
94 
98  virtual void clear() = 0;
99 
104  virtual std::size_t getNumComponents() const = 0;
105 
113  virtual std::size_t getNumComponents(unsigned int role) const = 0;
114 
123  virtual unsigned int getComponentRole(const Molecule& mol) const = 0;
124 
131  virtual std::size_t getComponentIndex(const Molecule& mol) const = 0;
132 
138  virtual bool containsComponent(const Molecule& mol) const = 0;
139 
145 
151 
157 
163 
169 
175 
181 
187 
197  ConstComponentIterator getComponentsBegin(unsigned int role) const;
198 
209 
219  ConstComponentIterator getComponentsEnd(unsigned int role) const;
220 
231 
238  virtual const Molecule& getComponent(std::size_t idx) const = 0;
239 
246  virtual Molecule& getComponent(std::size_t idx) = 0;
247 
259  virtual const Molecule& getComponent(std::size_t idx, unsigned int role) const = 0;
260 
272  virtual Molecule& getComponent(std::size_t idx, unsigned int role) = 0;
273 
281  virtual Molecule& addComponent(unsigned int role) = 0;
282 
293  virtual void swapComponentRoles(unsigned int role1, unsigned int role2) = 0;
294 
300  virtual void removeComponent(std::size_t idx) = 0;
301 
311  virtual void removeComponent(std::size_t idx, unsigned int role) = 0;
312 
321 
328  virtual void removeComponents(unsigned int role) = 0;
329 
334  virtual SharedPointer clone() const = 0;
335 
341  virtual void copy(const Reaction& rxn) = 0;
342 
353 
359 
360  protected:
367 
368  private:
369  class CDPL_CHEM_API ConstComponentAccessor
370  {
371 
372  friend class Reaction;
373 
374  public:
375  ConstComponentAccessor(const ComponentAccessor& accessor):
376  reaction(accessor.reaction), compRole(accessor.compRole) {}
377  ConstComponentAccessor(const Reaction* rxn, unsigned int role):
378  reaction(rxn), compRole(role) {}
379 
380  const Molecule& operator()(std::size_t idx) const;
381 
382  bool operator==(const ConstComponentAccessor& accessor) const;
383 
384  private:
385  const Reaction* reaction;
386  unsigned int compRole;
387  };
388 
389  class CDPL_CHEM_API ComponentAccessor
390  {
391 
392  friend class Reaction;
393  friend class ConstComponentAccessor;
394 
395  public:
396  ComponentAccessor(Reaction* rxn, unsigned int role):
397  reaction(rxn), compRole(role) {}
398 
399  Molecule& operator()(std::size_t idx) const;
400 
401  bool operator==(const ComponentAccessor& accessor) const;
402 
403  private:
404  Reaction* reaction;
405  unsigned int compRole;
406  };
407  };
408  } // namespace Chem
409 } // namespace CDPL
410 
411 #endif // CDPL_CHEM_REACTION_HPP
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::IndexedElementIterator.
Definition of class CDPL::Base::PropertyContainer.
Base class providing methods for the storage and lookup of object properties.
Definition: PropertyContainer.hpp:75
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::function< void(Reaction &, const Reaction &)> CopyPostprocessingFunction
Type of a functor invoked after a reaction copy operation to post-process the target reaction (first ...
Definition: Reaction.hpp:88
Util::IndexedElementIterator< Molecule, ComponentAccessor > ComponentIterator
A mutable random access iterator used to iterate over the components of the reaction.
Definition: Reaction.hpp:78
ConstComponentIterator getComponentsEnd() const
Returns a constant iterator pointing to the end of the reaction components.
static void registerCopyPostprocessingFunction(const CopyPostprocessingFunction &func)
Registers a global post-processing function invoked after every reaction copy operation.
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...
virtual std::size_t getNumComponents() const =0
Returns the number of reaction components.
virtual void removeComponent(std::size_t idx)=0
Removes the reaction component at the specified index.
ComponentIterator end()
Returns a mutable iterator pointing to the end of the reaction components.
virtual void clear()=0
Removes all components and clears all properties of the reaction.
ConstComponentIterator getComponentsBegin(unsigned int role) const
Returns a constant iterator pointing to the beginning of the reaction components with the specified r...
ComponentIterator getComponentsBegin(unsigned int role)
Returns a mutable iterator pointing to the beginning of the reaction components with the specified ro...
void invokeCopyPostprocessingFunctions(const Reaction &src_rxn)
Invokes all registered copy post-processing functions with *this as the target reaction and src_rxn a...
std::shared_ptr< Reaction > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Reaction instances.
Definition: Reaction.hpp:62
virtual void swapComponentRoles(unsigned int role1, unsigned int role2)=0
Swaps the reaction roles of the component sets specified by role1 and role2.
ComponentIterator getComponentsEnd(unsigned int role)
Returns a mutable iterator pointing to the end of the reaction components with the specified role.
ConstComponentIterator getComponentsEnd(unsigned int role) const
Returns a constant iterator pointing to the end of the reaction components with the specified role.
virtual const Molecule & getComponent(std::size_t idx) const =0
Returns a const reference to the reaction component at index idx.
ComponentIterator getComponentsBegin()
Returns a mutable iterator pointing to the beginning of the reaction components.
Util::IndexedElementIterator< const Molecule, ConstComponentAccessor > ConstComponentIterator
A constant random access iterator used to iterate over the components of the reaction.
Definition: Reaction.hpp:73
virtual std::size_t getComponentIndex(const Molecule &mol) const =0
Returns the index of the specified reaction component.
virtual bool containsComponent(const Molecule &mol) const =0
Tells whether the specified molecule is a component of this reaction.
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...
ConstComponentIterator getComponentsBegin() const
Returns a constant iterator pointing to the beginning of the reaction components.
virtual std::size_t getNumComponents(unsigned int role) const =0
Returns the number of reaction components with the specified role.
virtual void removeComponents(unsigned int role)=0
Removes all components with the specified role.
virtual Molecule & getComponent(std::size_t idx)=0
Returns a non-const reference to the reaction component at index idx.
ConstComponentIterator end() const
Returns a constant iterator pointing to the end of the reaction components.
ComponentIterator getComponentsEnd()
Returns a mutable iterator pointing to the end of the reaction components.
virtual SharedPointer clone() const =0
Creates a copy of the current reaction state.
ConstComponentIterator begin() const
Returns a constant iterator pointing to the beginning of the reaction components.
virtual ~Reaction()
Virtual destructor.
Definition: Reaction.hpp:93
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.
ComponentIterator begin()
Returns a mutable iterator pointing to the beginning of the reaction components.
virtual Molecule & addComponent(unsigned int role)=0
Creates a new reaction component with the specified role.
Reaction & operator=(const Reaction &rxn)
Replaces the current set of reaction components and properties by a copy of the components and proper...
virtual void copy(const Reaction &rxn)=0
Replaces the current set of reaction components and properties by a copy of the components and proper...
virtual unsigned int getComponentRole(const Molecule &mol) const =0
Returns the reaction role of the specified component.
ComponentIterator removeComponent(const ComponentIterator &it)
Removes the reaction component specified by the iterator it.
STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
GridEquality< E1, E2 >::ResultType operator==(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Tells whether the grid expressions e1 and e2 are element-wise equal.
Definition: GridExpression.hpp:579
The namespace of the Chemical Data Processing Library.