Chemical Data Processing Library C++ API - Version 1.2.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 
191 
192  private:
193  class CDPL_CHEM_API ConstBondAccessor
194  {
195 
196  public:
197  ConstBondAccessor(const BondAccessor& accessor):
198  container(accessor.container) {}
199 
200  ConstBondAccessor(const BondContainer* cntnr):
201  container(cntnr) {}
202 
203  const Bond& operator()(std::size_t idx) const
204  {
205  return container->getBond(idx);
206  }
207 
208  bool operator==(const ConstBondAccessor& accessor) const
209  {
210  return (container == accessor.container);
211  }
212 
213  ConstBondAccessor& operator=(const BondAccessor& accessor)
214  {
215  container = accessor.container;
216  return *this;
217  }
218 
219  private:
220  const BondContainer* container;
221  };
222 
223  class CDPL_CHEM_API BondAccessor
224  {
225 
226  friend class ConstBondAccessor;
227 
228  public:
229  BondAccessor(BondContainer* cntnr):
230  container(cntnr) {}
231 
232  Bond& operator()(std::size_t idx) const
233  {
234  return container->getBond(idx);
235  }
236 
237  bool operator==(const BondAccessor& accessor) const
238  {
239  return (container == accessor.container);
240  }
241 
242  private:
243  BondContainer* container;
244  };
245  };
246  } // namespace Chem
247 } // namespace CDPL
248 
249 #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 the class CDPL::Util::IndexedElementIterator.
A 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 stored Chem::Bond objects.
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 Chem::Bond instance is stored in this container.
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)
Assignment operator.
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 Chem::Bond instance at index idx.
virtual void orderBonds(const BondCompareFunction &func)=0
Orders the stored 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 Chem::Bond instance in this container.
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.
Bond.
Definition: Bond.hpp:50
A 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
A 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)
Definition: GridExpression.hpp:339
The namespace of the Chemical Data Processing Library.