Chemical Data Processing Library C++ API - Version 1.1.1
Entity3DContainer.hpp
Go to the documentation of this file.
1 /*
2  * Entity3DContainer.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_ENTITYCONTAINER_HPP
30 #define CDPL_CHEM_ENTITYCONTAINER_HPP
31 
32 #include <cstddef>
33 
34 #include "CDPL/Chem/APIPrefix.hpp"
36 
37 
38 namespace CDPL
39 {
40 
41  namespace Chem
42  {
43 
44  class Entity3D;
45 
53  {
54 
55  class ConstEntityAccessor;
56  class EntityAccessor;
57 
58  public:
63 
68 
73  virtual std::size_t getNumEntities() const = 0;
74 
81  virtual const Entity3D& getEntity(std::size_t idx) const = 0;
82 
89  virtual Entity3D& getEntity(std::size_t idx) = 0;
90 
96 
102 
108 
114 
120 
126 
132 
138 
144  {
145  return *this;
146  }
147 
153  {
154  return *this;
155  }
156 
157  protected:
161  virtual ~Entity3DContainer() {}
162 
169 
170  private:
171  class CDPL_CHEM_API ConstEntityAccessor
172  {
173 
174  public:
175  ConstEntityAccessor(const EntityAccessor& accessor):
176  container(accessor.container) {}
177 
178  ConstEntityAccessor(const Entity3DContainer* cntnr):
179  container(cntnr) {}
180 
181  const Entity3D& operator()(std::size_t idx) const
182  {
183  return container->getEntity(idx);
184  }
185 
186  bool operator==(const ConstEntityAccessor& accessor) const
187  {
188  return (container == accessor.container);
189  }
190 
191  ConstEntityAccessor& operator=(const EntityAccessor& accessor)
192  {
193  container = accessor.container;
194  return *this;
195  }
196 
197  private:
198  const Entity3DContainer* container;
199  };
200 
201  class CDPL_CHEM_API EntityAccessor
202  {
203 
204  friend class ConstEntityAccessor;
205 
206  public:
207  EntityAccessor(Entity3DContainer* cntnr):
208  container(cntnr) {}
209 
210  Entity3D& operator()(std::size_t idx) const
211  {
212  return container->getEntity(idx);
213  }
214 
215  bool operator==(const EntityAccessor& accessor) const
216  {
217  return (container == accessor.container);
218  }
219 
220  private:
221  Entity3DContainer* container;
222  };
223  };
224  } // namespace Chem
225 } // namespace CDPL
226 
227 #endif // CDPL_CHEM_ENTITYCONTAINER_HPP
CDPL::Chem::Entity3DContainer::getEntitiesBegin
ConstEntityIterator getEntitiesBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Entity3D objects.
CDPL::Chem::Entity3DContainer::EntityIterator
Util::IndexedElementIterator< Entity3D, EntityAccessor > EntityIterator
A mutable random access iterator used to iterate over the stored Chem::Entity3D objects.
Definition: Entity3DContainer.hpp:67
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::Entity3DContainer::getEntities
Entity3DContainer & getEntities()
Returns a reference to itself.
Definition: Entity3DContainer.hpp:152
CDPL::Math::operator==
GridEquality< E1, E2 >::ResultType operator==(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Definition: GridExpression.hpp:339
CDPL::Chem::Entity3DContainer::getEntity
virtual const Entity3D & getEntity(std::size_t idx) const =0
Returns a const reference to the Chem::Entity3D instance at index idx.
CDPL::Util::IndexedElementIterator
A STL compatible random access iterator for container elements accessible by index.
Definition: IndexedElementIterator.hpp:125
CDPL::Chem::Entity3DContainer::end
EntityIterator end()
Returns a mutable iterator pointing to the end of the stored Chem::Entity3D objects.
CDPL::Chem::Entity3DContainer::begin
ConstEntityIterator begin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Entity3D objects.
CDPL::Chem::Entity3DContainer::begin
EntityIterator begin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Entity3D objects.
CDPL::Chem::Entity3DContainer::getEntitiesEnd
EntityIterator getEntitiesEnd()
Returns a mutable iterator pointing to the end of the stored Chem::Entity3D objects.
CDPL::Chem::Entity3DContainer::getEntitiesBegin
EntityIterator getEntitiesBegin()
Returns a mutable iterator pointing to the beginning of the stored Chem::Entity3D objects.
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::Entity3DContainer::operator=
Entity3DContainer & operator=(const Entity3DContainer &cntnr)
Assignment operator.
CDPL::Chem::Entity3DContainer::ConstEntityIterator
Util::IndexedElementIterator< const Entity3D, ConstEntityAccessor > ConstEntityIterator
A constant random access iterator used to iterate over the stored const Chem::Entity3D objects.
Definition: Entity3DContainer.hpp:56
CDPL::Chem::Entity3DContainer::getEntities
const Entity3DContainer & getEntities() const
Returns a const reference to itself.
Definition: Entity3DContainer.hpp:143
CDPL::Chem::Entity3DContainer::end
ConstEntityIterator end() const
Returns a constant iterator pointing to the end of the stored const Chem::Entity3D objects.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::Entity3DContainer::getEntitiesEnd
ConstEntityIterator getEntitiesEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Entity3D objects.
CDPL::Chem::Entity3DContainer::~Entity3DContainer
virtual ~Entity3DContainer()
Virtual destructor.
Definition: Entity3DContainer.hpp:161
CDPL::Chem::Entity3DContainer::getEntity
virtual Entity3D & getEntity(std::size_t idx)=0
Returns a non-const reference to the entity at index idx.
CDPL::Chem::Entity3DContainer::getNumEntities
virtual std::size_t getNumEntities() const =0
Returns the number of stored Chem::Entity3D objects.
CDPL::Chem::Entity3D
Entity3D.
Definition: Entity3D.hpp:46