Chemical Data Processing Library C++ API - Version 1.4.0
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 
98 
104 
110 
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 
163  virtual std::size_t getNumEntities() const;
164 
174  virtual const Chem::Entity3D& getEntity(std::size_t idx) const;
175 
185  virtual Chem::Entity3D& getEntity(std::size_t idx);
186 
191  virtual void orderAtoms(const AtomCompareFunction& func) = 0;
192 
197  const AtomContainer& getAtoms() const
198  {
199  return *this;
200  }
201 
207  {
208  return *this;
209  }
210 
211  protected:
215  virtual ~AtomContainer() {}
216 
224 
225  private:
226  class CDPL_CHEM_API ConstAtomAccessor
227  {
228 
229  public:
230  ConstAtomAccessor(const AtomAccessor& accessor):
231  container(accessor.container) {}
232 
233  ConstAtomAccessor(const AtomContainer* cntnr):
234  container(cntnr) {}
235 
236  const Atom& operator()(std::size_t idx) const
237  {
238  return container->getAtom(idx);
239  }
240 
241  bool operator==(const ConstAtomAccessor& accessor) const
242  {
243  return (container == accessor.container);
244  }
245 
246  ConstAtomAccessor& operator=(const AtomAccessor& accessor)
247  {
248  container = accessor.container;
249  return *this;
250  }
251 
252  private:
253  const AtomContainer* container;
254  };
255 
256  class CDPL_CHEM_API AtomAccessor
257  {
258 
259  friend class ConstAtomAccessor;
260 
261  public:
262  AtomAccessor(AtomContainer* cntnr):
263  container(cntnr) {}
264 
265  Atom& operator()(std::size_t idx) const
266  {
267  return container->getAtom(idx);
268  }
269 
270  bool operator==(const AtomAccessor& accessor) const
271  {
272  return (container == accessor.container);
273  }
274 
275  private:
276  AtomContainer* container;
277  };
278  };
279  } // namespace Chem
280 } // namespace CDPL
281 
282 #endif // CDPL_CHEM_ATOMCONTAINER_HPP
Type declaration of a generic wrapper class for storing user-defined Chem::Atom 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::Chem::Entity3DContainer.
Definition of class CDPL::Util::IndexedElementIterator.
Common interface for data structures that support a random access to stored Chem::Atom instances.
Definition: AtomContainer.hpp:55
virtual void orderAtoms(const AtomCompareFunction &func)=0
Orders the atoms according to criteria implemented by the provided atom comparison function.
virtual std::size_t getNumAtoms() const =0
Returns the number of atoms.
const AtomContainer & getAtoms() const
Returns a const reference to itself.
Definition: AtomContainer.hpp:197
ConstAtomIterator end() const
Returns a constant iterator pointing to the end of the stored const Chem::Atom objects.
virtual Atom & getAtom(std::size_t idx)=0
Returns a non-const reference to the atom at index idx.
virtual std::size_t getAtomIndex(const Atom &atom) const =0
Returns the index of the specified atom.
Util::IndexedElementIterator< Atom, AtomAccessor > AtomIterator
A mutable random access iterator used to iterate over the stored Chem::Atom objects.
Definition: AtomContainer.hpp:69
virtual const Atom & getAtom(std::size_t idx) const =0
Returns a const reference to the atom at index idx.
virtual bool containsAtom(const Atom &atom) const =0
Tells whether the specified atom is part of the atom sequence.
AtomContainer & getAtoms()
Returns a reference to itself.
Definition: AtomContainer.hpp:206
AtomIterator getAtomsEnd()
Returns a mutable iterator pointing to the end of the stored Chem::Atom objects.
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
virtual Chem::Entity3D & getEntity(std::size_t idx)
Returns a non-const reference to the entity at index idx.
virtual const Chem::Entity3D & getEntity(std::size_t idx) const
Returns a const reference to the entity at index idx.
virtual ~AtomContainer()
Virtual destructor.
Definition: AtomContainer.hpp:215
AtomIterator begin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Atom objects.
AtomIterator getAtomsBegin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Atom objects.
AtomContainer & operator=(const AtomContainer &cntnr)
Replaces the current set of properties by a copy of the properties of the container cntnr.
ConstAtomIterator begin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Atom objects.
AtomIterator end()
Returns a mutable iterator pointing to the end of the stored Chem::Atom objects.
virtual std::size_t getNumEntities() const
Returns the number of stored Chem::Entity3D objects.
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Atom objects.
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Atom objects.
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:58
Common interface for data structures that support a random access to stored Chem::Entity3D instances.
Definition: Entity3DContainer.hpp:53
Base class for objects that have a position in 3D space (e.g. Chem::Atom and Chem::Feature).
Definition: Entity3D.hpp:46
STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
std::function< bool(const Atom &, const Atom &)> AtomCompareFunction
Generic wrapper class used to store a user-defined atom compare function.
Definition: AtomCompareFunction.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.