Chemical Data Processing Library C++ API - Version 1.1.1
AtomContainer.hpp
Go to the documentation of this file.
1 /*
2  * AtomContainer.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_ATOMCONTAINER_HPP
30 #define CDPL_CHEM_ATOMCONTAINER_HPP
31 
32 #include <cstddef>
33 
34 #include "CDPL/Chem/APIPrefix.hpp"
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Chem
44  {
45 
46  class Atom;
47 
55  {
56 
57  class ConstAtomAccessor;
58  class AtomAccessor;
59 
60  public:
65 
70 
75  virtual std::size_t getNumAtoms() const = 0;
76 
83  virtual const Atom& getAtom(std::size_t idx) const = 0;
84 
91  virtual Atom& getAtom(std::size_t idx) = 0;
92 
97  ConstAtomIterator getAtomsBegin() const;
98 
103  ConstAtomIterator getAtomsEnd() const;
104 
109  AtomIterator getAtomsBegin();
110 
115  AtomIterator getAtomsEnd();
116 
122 
128 
134 
140 
146  virtual bool containsAtom(const Atom& atom) const = 0;
147 
154  virtual std::size_t getAtomIndex(const Atom& atom) const = 0;
155 
156  virtual std::size_t getNumEntities() const;
157 
158  virtual const Entity3D& getEntity(std::size_t idx) const;
159 
160  virtual Entity3D& getEntity(std::size_t idx);
161 
166  virtual void orderAtoms(const AtomCompareFunction& func) = 0;
167 
172  const AtomContainer& getAtoms() const
173  {
174  return *this;
175  }
176 
182  {
183  return *this;
184  }
185 
186  protected:
190  virtual ~AtomContainer() {}
191 
198 
199  private:
200  class CDPL_CHEM_API ConstAtomAccessor
201  {
202 
203  public:
204  ConstAtomAccessor(const AtomAccessor& accessor):
205  container(accessor.container) {}
206 
207  ConstAtomAccessor(const AtomContainer* cntnr):
208  container(cntnr) {}
209 
210  const Atom& operator()(std::size_t idx) const
211  {
212  return container->getAtom(idx);
213  }
214 
215  bool operator==(const ConstAtomAccessor& accessor) const
216  {
217  return (container == accessor.container);
218  }
219 
220  ConstAtomAccessor& operator=(const AtomAccessor& accessor)
221  {
222  container = accessor.container;
223  return *this;
224  }
225 
226  private:
227  const AtomContainer* container;
228  };
229 
230  class CDPL_CHEM_API AtomAccessor
231  {
232 
233  friend class ConstAtomAccessor;
234 
235  public:
236  AtomAccessor(AtomContainer* cntnr):
237  container(cntnr) {}
238 
239  Atom& operator()(std::size_t idx) const
240  {
241  return container->getAtom(idx);
242  }
243 
244  bool operator==(const AtomAccessor& accessor) const
245  {
246  return (container == accessor.container);
247  }
248 
249  private:
250  AtomContainer* container;
251  };
252  };
253  } // namespace Chem
254 } // namespace CDPL
255 
256 #endif // CDPL_CHEM_ATOMCONTAINER_HPP
CDPL::Chem::AtomCompareFunction
std::function< bool(const Chem::Atom &, const Chem::Atom &)> AtomCompareFunction
A generic wrapper class used to store a user-defined atom compare function.
Definition: AtomCompareFunction.hpp:41
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::Math::operator==
GridEquality< E1, E2 >::ResultType operator==(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Definition: GridExpression.hpp:339
CDPL::Chem::AtomContainer::begin
ConstAtomIterator begin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Atom objects.
CDPL::Chem::AtomContainer::getNumEntities
virtual std::size_t getNumEntities() const
Returns the number of stored Chem::Entity3D objects.
AtomCompareFunction.hpp
Type definition of a generic wrapper class for storing user-defined Chem::Atom compare functions.
CDPL::Chem::AtomContainer::end
AtomIterator end()
Returns a mutable iterator pointing to the end of the stored Chem::Atom objects.
CDPL::Chem::AtomContainer::getAtoms
const AtomContainer & getAtoms() const
Returns a const reference to itself.
Definition: AtomContainer.hpp:172
CDPL::Util::IndexedElementIterator
A STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::AtomContainer::getNumAtoms
virtual std::size_t getNumAtoms() const =0
Returns the number of stored Chem::Atom objects.
CDPL::Chem::AtomContainer::AtomIterator
Util::IndexedElementIterator< Atom, AtomAccessor > AtomIterator
A mutable random access iterator used to iterate over the stored Chem::Atom objects.
Definition: AtomContainer.hpp:69
CDPL::Chem::AtomContainer::getEntity
virtual const Entity3D & getEntity(std::size_t idx) const
Returns a const reference to the Chem::Entity3D instance at index idx.
CDPL::Chem::AtomContainer::getEntity
virtual Entity3D & getEntity(std::size_t idx)
Returns a non-const reference to the entity at index idx.
CDPL::Chem::Entity3DContainer
A common interface for data-structures that support a random access to stored Chem::Entity3D instance...
Definition: Entity3DContainer.hpp:53
CDPL::Chem::AtomContainer::getAtom
virtual Atom & getAtom(std::size_t idx)=0
Returns a non-const reference to the atom at index idx.
CDPL::Chem::AtomContainer::begin
AtomIterator begin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Atom objects.
CDPL::Chem::AtomContainer
A common interface for data-structures that support a random access to stored Chem::Atom instances.
Definition: AtomContainer.hpp:55
CDPL::Chem::AtomContainer::orderAtoms
virtual void orderAtoms(const AtomCompareFunction &func)=0
Orders the stored atoms according to criteria implemented by the provided atom comparison function.
Entity3DContainer.hpp
Definition of the class CDPL::Chem::Entity3DContainer.
CDPL::Chem::AtomContainer::getAtom
virtual const Atom & getAtom(std::size_t idx) const =0
Returns a const reference to the Chem::Atom instance at index idx.
CDPL::Chem::AtomContainer::~AtomContainer
virtual ~AtomContainer()
Virtual destructor.
Definition: AtomContainer.hpp:190
CDPL::Chem::AtomContainer::ConstAtomIterator
Util::IndexedElementIterator< const Atom, ConstAtomAccessor > ConstAtomIterator
A constant random access iterator used to iterate over the stored const Chem::Atom objects.
Definition: AtomContainer.hpp:58
CDPL::Chem::AtomContainer::getAtomIndex
virtual std::size_t getAtomIndex(const Atom &atom) const =0
Returns the index of the specified Chem::Atom instance in this container.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::AtomContainer::containsAtom
virtual bool containsAtom(const Atom &atom) const =0
Tells whether the specified Chem::Atom instance is stored in this container.
CDPL::Chem::AtomContainer::end
ConstAtomIterator end() const
Returns a constant iterator pointing to the end of the stored const Chem::Atom objects.
CDPL::Chem::Entity3D
Entity3D.
Definition: Entity3D.hpp:46
CDPL::Chem::AtomContainer::operator=
AtomContainer & operator=(const AtomContainer &cntnr)
Assignment operator.
CDPL::Chem::AtomContainer::getAtoms
AtomContainer & getAtoms()
Returns a reference to itself.
Definition: AtomContainer.hpp:181