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 
160  virtual std::size_t getNumEntities() const;
161 
168  virtual const Entity3D& getEntity(std::size_t idx) const;
169 
176  virtual Entity3D& getEntity(std::size_t idx);
177 
182  virtual void orderAtoms(const AtomCompareFunction& func) = 0;
183 
188  const AtomContainer& getAtoms() const
189  {
190  return *this;
191  }
192 
198  {
199  return *this;
200  }
201 
202  protected:
206  virtual ~AtomContainer() {}
207 
214 
215  private:
216  class CDPL_CHEM_API ConstAtomAccessor
217  {
218 
219  public:
220  ConstAtomAccessor(const AtomAccessor& accessor):
221  container(accessor.container) {}
222 
223  ConstAtomAccessor(const AtomContainer* cntnr):
224  container(cntnr) {}
225 
226  const Atom& operator()(std::size_t idx) const
227  {
228  return container->getAtom(idx);
229  }
230 
231  bool operator==(const ConstAtomAccessor& accessor) const
232  {
233  return (container == accessor.container);
234  }
235 
236  ConstAtomAccessor& operator=(const AtomAccessor& accessor)
237  {
238  container = accessor.container;
239  return *this;
240  }
241 
242  private:
243  const AtomContainer* container;
244  };
245 
246  class CDPL_CHEM_API AtomAccessor
247  {
248 
249  friend class ConstAtomAccessor;
250 
251  public:
252  AtomAccessor(AtomContainer* cntnr):
253  container(cntnr) {}
254 
255  Atom& operator()(std::size_t idx) const
256  {
257  return container->getAtom(idx);
258  }
259 
260  bool operator==(const AtomAccessor& accessor) const
261  {
262  return (container == accessor.container);
263  }
264 
265  private:
266  AtomContainer* container;
267  };
268  };
269  } // namespace Chem
270 } // namespace CDPL
271 
272 #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 stored atoms according to criteria implemented by the provided atom comparison function.
virtual std::size_t getNumAtoms() const =0
Returns the number of stored Chem::Atom objects.
const AtomContainer & getAtoms() const
Returns a const reference to itself.
Definition: AtomContainer.hpp:188
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 Chem::Atom instance in this container.
virtual const Entity3D & getEntity(std::size_t idx) const
Returns a const reference to the Chem::Entity3D instance at index idx (equivalent to getAtom(idx)).
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 Chem::Atom instance at index idx.
virtual bool containsAtom(const Atom &atom) const =0
Tells whether the specified Chem::Atom instance is stored in this container.
AtomContainer & getAtoms()
Returns a reference to itself.
Definition: AtomContainer.hpp:197
virtual Entity3D & getEntity(std::size_t idx)
Returns a non-const reference to the Chem::Entity3D instance at index idx (equivalent to getAtom(idx)...
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 ~AtomContainer()
Virtual destructor.
Definition: AtomContainer.hpp:206
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)
Assignment operator.
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 (equivalent to getNumAtoms()).
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:57
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:579
The namespace of the Chemical Data Processing Library.