Chemical Data Processing Library C++ API - Version 1.4.0
BondContainer.hpp
Go to the documentation of this file.
1 /*
2  * BondContainer.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_BONDCONTAINER_HPP
30 #define CDPL_CHEM_BONDCONTAINER_HPP
31 
32 #include <cstddef>
33 
34 #include "CDPL/Chem/APIPrefix.hpp"
37 
38 
39 namespace CDPL
40 {
41 
42  namespace Chem
43  {
44 
45  class Bond;
46 
54  {
55 
56  class ConstBondAccessor;
57  class BondAccessor;
58 
59  public:
64 
69 
74  virtual std::size_t getNumBonds() const = 0;
75 
82  virtual const Bond& getBond(std::size_t idx) const = 0;
83 
90  virtual Bond& getBond(std::size_t idx) = 0;
91 
97 
103 
109 
115 
121 
127 
133 
139 
145  virtual bool containsBond(const Bond& bond) const = 0;
146 
153  virtual std::size_t getBondIndex(const Bond& bond) const = 0;
154 
159  virtual void orderBonds(const BondCompareFunction& func) = 0;
160 
165  const BondContainer& getBonds() const
166  {
167  return *this;
168  }
169 
175  {
176  return *this;
177  }
178 
179  protected:
183  virtual ~BondContainer() {}
184 
192 
193  private:
194  class CDPL_CHEM_API ConstBondAccessor
195  {
196 
197  public:
198  ConstBondAccessor(const BondAccessor& accessor):
199  container(accessor.container) {}
200 
201  ConstBondAccessor(const BondContainer* cntnr):
202  container(cntnr) {}
203 
204  const Bond& operator()(std::size_t idx) const
205  {
206  return container->getBond(idx);
207  }
208 
209  bool operator==(const ConstBondAccessor& accessor) const
210  {
211  return (container == accessor.container);
212  }
213 
214  ConstBondAccessor& operator=(const BondAccessor& accessor)
215  {
216  container = accessor.container;
217  return *this;
218  }
219 
220  private:
221  const BondContainer* container;
222  };
223 
224  class CDPL_CHEM_API BondAccessor
225  {
226 
227  friend class ConstBondAccessor;
228 
229  public:
230  BondAccessor(BondContainer* cntnr):
231  container(cntnr) {}
232 
233  Bond& operator()(std::size_t idx) const
234  {
235  return container->getBond(idx);
236  }
237 
238  bool operator==(const BondAccessor& accessor) const
239  {
240  return (container == accessor.container);
241  }
242 
243  private:
244  BondContainer* container;
245  };
246  };
247  } // namespace Chem
248 } // namespace CDPL
249 
250 #endif // CDPL_CHEM_BONDCONTAINER_HPP
Type definition of a generic wrapper class for storing user-defined Chem::Bond compare functions.
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.
Common interface for data structures that support a random access to stored Chem::Bond instances.
Definition: BondContainer.hpp:54
Util::IndexedElementIterator< Bond, BondAccessor > BondIterator
A mutable random access iterator used to iterate over the stored Chem::Bond objects.
Definition: BondContainer.hpp:68
virtual std::size_t getNumBonds() const =0
Returns the number of bonds.
BondIterator begin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Bond objects.
virtual bool containsBond(const Bond &bond) const =0
Tells whether the specified bond is part of the bond sequence.
ConstBondIterator end() const
Returns a constant iterator pointing to the end of the stored const Chem::Bond objects.
BondIterator getBondsEnd()
Returns a mutable iterator pointing to the end of the stored Chem::Bond objects.
const BondContainer & getBonds() const
Returns a const reference to itself.
Definition: BondContainer.hpp:165
virtual Bond & getBond(std::size_t idx)=0
Returns a non-const reference to the bond at index idx.
BondContainer & operator=(const BondContainer &cntnr)
Replaces the current set of properties by a copy of the properties of the container cntnr.
ConstBondIterator getBondsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Bond objects.
BondIterator end()
Returns a mutable iterator pointing to the end of the stored Chem::Bond objects.
ConstBondIterator getBondsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Bond objects.
virtual ~BondContainer()
Virtual destructor.
Definition: BondContainer.hpp:183
virtual const Bond & getBond(std::size_t idx) const =0
Returns a const reference to the bond at index idx.
virtual void orderBonds(const BondCompareFunction &func)=0
Orders the bonds according to criteria implemented by the provided bond comparison function.
ConstBondIterator begin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Bond objects.
virtual std::size_t getBondIndex(const Bond &bond) const =0
Returns the index of the specified bond.
Util::IndexedElementIterator< const Bond, ConstBondAccessor > ConstBondIterator
A constant random access iterator used to iterate over the stored const Chem::Bond objects.
Definition: BondContainer.hpp:57
BondContainer & getBonds()
Returns a reference to itself.
Definition: BondContainer.hpp:174
BondIterator getBondsBegin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Bond objects.
Abstract base class representing a chemical bond between two atoms (represented by Chem::Atom instanc...
Definition: Bond.hpp:54
STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
std::function< bool(const Chem::Bond &, const Chem::Bond &)> BondCompareFunction
Generic wrapper class used to store a user-defined bond compare function.
Definition: BondCompareFunction.hpp:41
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:677
The namespace of the Chemical Data Processing Library.