Chemical Data Processing Library C++ API - Version 1.1.1
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 
96  ConstBondIterator getBondsBegin() const;
97 
102  ConstBondIterator getBondsEnd() const;
103 
108  BondIterator getBondsBegin();
109 
114  BondIterator getBondsEnd();
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
CDPL::Chem::BondContainer::getBonds
BondContainer & getBonds()
Returns a reference to itself.
Definition: BondContainer.hpp:174
CDPL::Chem::BondContainer::begin
ConstBondIterator begin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Bond objects.
CDPL::Chem::BondContainer::containsBond
virtual bool containsBond(const Bond &bond) const =0
Tells whether the specified Chem::Bond instance is stored in this container.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
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::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::BondContainer::getBonds
const BondContainer & getBonds() const
Returns a const reference to itself.
Definition: BondContainer.hpp:165
CDPL::Math::operator==
GridEquality< E1, E2 >::ResultType operator==(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Definition: GridExpression.hpp:339
CDPL::Chem::BondContainer::getNumBonds
virtual std::size_t getNumBonds() const =0
Returns the number of stored Chem::Bond objects.
CDPL::Chem::BondContainer::~BondContainer
virtual ~BondContainer()
Virtual destructor.
Definition: BondContainer.hpp:183
CDPL::Chem::BondContainer::getBondIndex
virtual std::size_t getBondIndex(const Bond &bond) const =0
Returns the index of the specified Chem::Bond instance in this container.
CDPL::Chem::BondContainer::BondIterator
Util::IndexedElementIterator< Bond, BondAccessor > BondIterator
A mutable random access iterator used to iterate over the stored Chem::Bond objects.
Definition: BondContainer.hpp:68
CDPL::Chem::BondContainer::getBond
virtual Bond & getBond(std::size_t idx)=0
Returns a non-const reference to the bond at index idx.
CDPL::Util::IndexedElementIterator
A STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
BondCompareFunction.hpp
Type definition of a generic wrapper class for storing user-defined Chem::Bond compare functions.
CDPL::Chem::BondContainer::begin
BondIterator begin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Bond objects.
CDPL::Chem::BondContainer::ConstBondIterator
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
CDPL::Chem::BondContainer::getBond
virtual const Bond & getBond(std::size_t idx) const =0
Returns a const reference to the Chem::Bond instance at index idx.
CDPL::Chem::BondContainer::orderBonds
virtual void orderBonds(const BondCompareFunction &func)=0
Orders the stored bonds according to criteria implemented by the provided bond comparison function.
CDPL::Chem::BondCompareFunction
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
CDPL::Chem::BondContainer::operator=
BondContainer & operator=(const BondContainer &cntnr)
Assignment operator.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::BondContainer
A common interface for data-structures that support a random access to stored Chem::Bond instances.
Definition: BondContainer.hpp:54
CDPL::Chem::BondContainer::end
BondIterator end()
Returns a mutable iterator pointing to the end of the stored Chem::Bond objects.
CDPL::Chem::BondContainer::end
ConstBondIterator end() const
Returns a constant iterator pointing to the end of the stored const Chem::Bond objects.