| 1 | /*
 | 
|---|
| 2 |  * World.hpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Feb 3, 2010
 | 
|---|
| 5 |  *      Author: crueger
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef WORLD_HPP_
 | 
|---|
| 9 | #define WORLD_HPP_
 | 
|---|
| 10 | 
 | 
|---|
| 11 | // include config.h
 | 
|---|
| 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 13 | #include <config.h>
 | 
|---|
| 14 | #endif
 | 
|---|
| 15 | 
 | 
|---|
| 16 | /*********************************************** includes ***********************************/
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <string>
 | 
|---|
| 19 | #include <map>
 | 
|---|
| 20 | #include <vector>
 | 
|---|
| 21 | #include <set>
 | 
|---|
| 22 | #include <boost/thread.hpp>
 | 
|---|
| 23 | #include <boost/shared_ptr.hpp>
 | 
|---|
| 24 | 
 | 
|---|
| 25 | #include "Actions/ActionTrait.hpp"
 | 
|---|
| 26 | #include "Atom/AtomSet.hpp"
 | 
|---|
| 27 | #include "Descriptors/SelectiveConstIterator.hpp"
 | 
|---|
| 28 | #include "Descriptors/SelectiveIterator.hpp"
 | 
|---|
| 29 | #include "CodePatterns/Observer/Observable.hpp"
 | 
|---|
| 30 | #include "CodePatterns/Observer/Observer.hpp"
 | 
|---|
| 31 | #include "CodePatterns/Cacheable.hpp"
 | 
|---|
| 32 | #include "CodePatterns/Singleton.hpp"
 | 
|---|
| 33 | #include "CodePatterns/Observer/ObservedContainer.hpp"
 | 
|---|
| 34 | #include "CodePatterns/Range.hpp"
 | 
|---|
| 35 | #include "IdPool_policy.hpp"
 | 
|---|
| 36 | #include "IdPool.hpp"
 | 
|---|
| 37 | #include "LinkedCell/LinkedCell_View.hpp"
 | 
|---|
| 38 | #include "types.hpp"
 | 
|---|
| 39 | 
 | 
|---|
| 40 | 
 | 
|---|
| 41 | // forward declarations
 | 
|---|
| 42 | class atom;
 | 
|---|
| 43 | class AtomDescriptor;
 | 
|---|
| 44 | class AtomDescriptor_impl;
 | 
|---|
| 45 | class BondGraph;
 | 
|---|
| 46 | class Box;
 | 
|---|
| 47 | class config;
 | 
|---|
| 48 | class RealSpaceMatrix;
 | 
|---|
| 49 | class molecule;
 | 
|---|
| 50 | class MoleculeDescriptor;
 | 
|---|
| 51 | class MoleculeDescriptor_impl;
 | 
|---|
| 52 | class MoleculeListClass;
 | 
|---|
| 53 | class periodentafel;
 | 
|---|
| 54 | class ThermoStatContainer;
 | 
|---|
| 55 | 
 | 
|---|
| 56 | namespace LinkedCell {
 | 
|---|
| 57 |   class LinkedCell_Controller;
 | 
|---|
| 58 | }
 | 
|---|
| 59 | 
 | 
|---|
| 60 | namespace MoleCuilder {
 | 
|---|
| 61 |   class ManipulateAtomsProcess;
 | 
|---|
| 62 |   template<typename T> class AtomsCalculation;
 | 
|---|
| 63 | }
 | 
|---|
| 64 | 
 | 
|---|
| 65 | /****************************************** forward declarations *****************************/
 | 
|---|
| 66 | 
 | 
|---|
| 67 | /********************************************** Class World *******************************/
 | 
|---|
| 68 | 
 | 
|---|
| 69 | namespace detail {
 | 
|---|
| 70 |   template <class T> const T* lastChanged()
 | 
|---|
| 71 |   {
 | 
|---|
| 72 |     ASSERT(0, "detail::lastChanged() - only specializations may be used.");
 | 
|---|
| 73 |     return NULL;
 | 
|---|
| 74 |   }
 | 
|---|
| 75 | }
 | 
|---|
| 76 | 
 | 
|---|
| 77 | class World : public Singleton<World>, public Observable
 | 
|---|
| 78 | {
 | 
|---|
| 79 | 
 | 
|---|
| 80 | // Make access to constructor and destructor possible from inside the singleton
 | 
|---|
| 81 | friend class Singleton<World>;
 | 
|---|
| 82 | 
 | 
|---|
| 83 | // necessary for coupling with descriptors
 | 
|---|
| 84 | friend class AtomDescriptor_impl;
 | 
|---|
| 85 | friend class AtomDescriptor;
 | 
|---|
| 86 | friend class MoleculeDescriptor_impl;
 | 
|---|
| 87 | friend class MoleculeDescriptor;
 | 
|---|
| 88 | // coupling with descriptors over selection
 | 
|---|
| 89 | friend class AtomSelectionDescriptor_impl;
 | 
|---|
| 90 | friend class AtomOfMoleculeSelectionDescriptor_impl;
 | 
|---|
| 91 | friend class AtomOrderDescriptor_impl;
 | 
|---|
| 92 | friend class MoleculeOfAtomSelectionDescriptor_impl;
 | 
|---|
| 93 | friend class MoleculeOrderDescriptor_impl;
 | 
|---|
| 94 | friend class MoleculeSelectionDescriptor_impl;
 | 
|---|
| 95 | 
 | 
|---|
| 96 | // Actions, calculations etc associated with the World
 | 
|---|
| 97 | friend class MoleCuilder::ManipulateAtomsProcess;
 | 
|---|
| 98 | template<typename> friend class MoleCuilder::AtomsCalculation;
 | 
|---|
| 99 | public:
 | 
|---|
| 100 |   // some typedefs for the CONSTRUCT_... macros (no "," allows in a single parameter name)
 | 
|---|
| 101 |   typedef std::map<atomId_t,atom*> AtomSTLSet;
 | 
|---|
| 102 |   typedef std::map<moleculeId_t,molecule*> MoleculeSTLSet;
 | 
|---|
| 103 | 
 | 
|---|
| 104 |   // Types for Atom and Molecule structures
 | 
|---|
| 105 |   typedef ObservedContainer< AtomSTLSet > AtomSet;
 | 
|---|
| 106 |   typedef ObservedContainer< MoleculeSTLSet > MoleculeSet;
 | 
|---|
| 107 | 
 | 
|---|
| 108 |   typedef ATOMSET(std::vector) AtomComposite;
 | 
|---|
| 109 | 
 | 
|---|
| 110 |     /******* Notifications *******/
 | 
|---|
| 111 | 
 | 
|---|
| 112 |   //!> enumeration of present notification types: only insertion/removal of atoms or molecules
 | 
|---|
| 113 |   enum NotificationType {
 | 
|---|
| 114 |     AtomInserted,
 | 
|---|
| 115 |     AtomRemoved,
 | 
|---|
| 116 |     MoleculeInserted,
 | 
|---|
| 117 |     MoleculeRemoved,
 | 
|---|
| 118 |     SelectionChanged,
 | 
|---|
| 119 |     NotificationType_MAX
 | 
|---|
| 120 |   };
 | 
|---|
| 121 | 
 | 
|---|
| 122 |   //>! access to last changed element (atom or molecule)
 | 
|---|
| 123 |   template <class T> const T* lastChanged() const
 | 
|---|
| 124 |   { return detail::lastChanged<T>(); }
 | 
|---|
| 125 | 
 | 
|---|
| 126 |     /***** getter and setter *****/
 | 
|---|
| 127 |   // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
 | 
|---|
| 128 |   /**
 | 
|---|
| 129 |    * returns the periodentafel for the world.
 | 
|---|
| 130 |    */
 | 
|---|
| 131 |   periodentafel *&getPeriode();
 | 
|---|
| 132 | 
 | 
|---|
| 133 |   /** Returns the BondGraph for the World.
 | 
|---|
| 134 |    *
 | 
|---|
| 135 |    * @return reference to BondGraph
 | 
|---|
| 136 |    */
 | 
|---|
| 137 |   BondGraph *&getBondGraph();
 | 
|---|
| 138 | 
 | 
|---|
| 139 |   /** Sets the World's BondGraph.
 | 
|---|
| 140 |    *
 | 
|---|
| 141 |    * @param _BG new BondGraph
 | 
|---|
| 142 |    */
 | 
|---|
| 143 |   void setBondGraph(BondGraph *_BG);
 | 
|---|
| 144 |   /**
 | 
|---|
| 145 |    * returns the configuration for the world.
 | 
|---|
| 146 |    */
 | 
|---|
| 147 |   config *&getConfig();
 | 
|---|
| 148 | 
 | 
|---|
| 149 |   /** Returns a notification_ptr for a specific type.
 | 
|---|
| 150 |    *
 | 
|---|
| 151 |    * @param type request type
 | 
|---|
| 152 |    * @return reference to instance
 | 
|---|
| 153 |    */
 | 
|---|
| 154 |   Notification_ptr getNotification(enum NotificationType type) const;
 | 
|---|
| 155 | 
 | 
|---|
| 156 |   /**
 | 
|---|
| 157 |    * returns the first atom that matches a given descriptor.
 | 
|---|
| 158 |    * Do not rely on ordering for descriptors that match more than one atom.
 | 
|---|
| 159 |    */
 | 
|---|
| 160 |   atom* getAtom(AtomDescriptor descriptor);
 | 
|---|
| 161 | 
 | 
|---|
| 162 |   /**
 | 
|---|
| 163 |    * returns a vector containing all atoms that match a given descriptor
 | 
|---|
| 164 |    */
 | 
|---|
| 165 |   AtomComposite getAllAtoms(AtomDescriptor descriptor);
 | 
|---|
| 166 |   AtomComposite getAllAtoms();
 | 
|---|
| 167 | 
 | 
|---|
| 168 |   /**
 | 
|---|
| 169 |    * returns a calculation that calls a given function on all atoms matching a descriptor.
 | 
|---|
| 170 |    * the calculation is not called at this point and can be used as an action, i.e. be stored in
 | 
|---|
| 171 |    * menus, be kept around for later use etc.
 | 
|---|
| 172 |    */
 | 
|---|
| 173 |   template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait,AtomDescriptor);
 | 
|---|
| 174 |   template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait);
 | 
|---|
| 175 | 
 | 
|---|
| 176 |   /**
 | 
|---|
| 177 |    * get the number of atoms in the World
 | 
|---|
| 178 |    */
 | 
|---|
| 179 |   int numAtoms();
 | 
|---|
| 180 | 
 | 
|---|
| 181 |   /**
 | 
|---|
| 182 |    * returns the first molecule that matches a given descriptor.
 | 
|---|
| 183 |    * Do not rely on ordering for descriptors that match more than one molecule.
 | 
|---|
| 184 |    */
 | 
|---|
| 185 |   molecule *getMolecule(MoleculeDescriptor descriptor);
 | 
|---|
| 186 | 
 | 
|---|
| 187 |   /**
 | 
|---|
| 188 |    * returns a vector containing all molecules that match a given descriptor
 | 
|---|
| 189 |    */
 | 
|---|
| 190 |   std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
 | 
|---|
| 191 |   std::vector<molecule*> getAllMolecules();
 | 
|---|
| 192 | 
 | 
|---|
| 193 |   /**
 | 
|---|
| 194 |    * get the number of molecules in the World
 | 
|---|
| 195 |    */
 | 
|---|
| 196 |   int numMolecules();
 | 
|---|
| 197 | 
 | 
|---|
| 198 |   /**
 | 
|---|
| 199 |    * get the domain size as a symmetric matrix (6 components)
 | 
|---|
| 200 |    */
 | 
|---|
| 201 |   Box& getDomain();
 | 
|---|
| 202 | 
 | 
|---|
| 203 |   /**
 | 
|---|
| 204 |    * Set the domain size from a matrix object
 | 
|---|
| 205 |    *
 | 
|---|
| 206 |    * Matrix needs to be symmetric
 | 
|---|
| 207 |    */
 | 
|---|
| 208 |   void setDomain(const RealSpaceMatrix &mat);
 | 
|---|
| 209 | 
 | 
|---|
| 210 |   /**
 | 
|---|
| 211 |    * set the domain size as a symmetric matrix (6 components)
 | 
|---|
| 212 |    */
 | 
|---|
| 213 |   void setDomain(double * matrix);
 | 
|---|
| 214 | 
 | 
|---|
| 215 |   /** Returns a LinkedCell structure for obtaining neighbors quickly.
 | 
|---|
| 216 |    *
 | 
|---|
| 217 |    * @param distance desired linked cell edge length
 | 
|---|
| 218 |    * @return view of restricted underlying LinkedCell_Model
 | 
|---|
| 219 |    */
 | 
|---|
| 220 |   LinkedCell::LinkedCell_View getLinkedCell(const double distance);
 | 
|---|
| 221 | 
 | 
|---|
| 222 |   /**
 | 
|---|
| 223 |    * set the current time of the world.
 | 
|---|
| 224 |    *
 | 
|---|
| 225 |    * @param _step time step to set to
 | 
|---|
| 226 |    */
 | 
|---|
| 227 |   void setTime(const unsigned int _step);
 | 
|---|
| 228 | 
 | 
|---|
| 229 |   /**
 | 
|---|
| 230 |    * get the default name
 | 
|---|
| 231 |    */
 | 
|---|
| 232 |   std::string getDefaultName();
 | 
|---|
| 233 | 
 | 
|---|
| 234 |   /**
 | 
|---|
| 235 |    * set the default name
 | 
|---|
| 236 |    */
 | 
|---|
| 237 |   void setDefaultName(std::string name);
 | 
|---|
| 238 | 
 | 
|---|
| 239 |   /**
 | 
|---|
| 240 |    * get pointer to World's ThermoStatContainer
 | 
|---|
| 241 |    */
 | 
|---|
| 242 |   ThermoStatContainer * getThermostats();
 | 
|---|
| 243 | 
 | 
|---|
| 244 |   /*
 | 
|---|
| 245 |    * get the ExitFlag
 | 
|---|
| 246 |    */
 | 
|---|
| 247 |   int getExitFlag();
 | 
|---|
| 248 | 
 | 
|---|
| 249 |   /*
 | 
|---|
| 250 |    * set the ExitFlag
 | 
|---|
| 251 |    */
 | 
|---|
| 252 |   void setExitFlag(int flag);
 | 
|---|
| 253 | 
 | 
|---|
| 254 |   /***** Methods to work with the World *****/
 | 
|---|
| 255 | 
 | 
|---|
| 256 |   /**
 | 
|---|
| 257 |    * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
 | 
|---|
| 258 |    * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
 | 
|---|
| 259 |    */
 | 
|---|
| 260 |   molecule *createMolecule();
 | 
|---|
| 261 | 
 | 
|---|
| 262 |   void destroyMolecule(molecule*);
 | 
|---|
| 263 |   void destroyMolecule(moleculeId_t);
 | 
|---|
| 264 | 
 | 
|---|
| 265 |   /**
 | 
|---|
| 266 |    * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
 | 
|---|
| 267 |    * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
 | 
|---|
| 268 |    */
 | 
|---|
| 269 |   atom *createAtom();
 | 
|---|
| 270 | 
 | 
|---|
| 271 |   /**
 | 
|---|
| 272 |    * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
 | 
|---|
| 273 |    * Do not re-register Atoms already known to the world since this will cause double-frees.
 | 
|---|
| 274 |    */
 | 
|---|
| 275 |   int registerAtom(atom*);
 | 
|---|
| 276 | 
 | 
|---|
| 277 |   /**
 | 
|---|
| 278 |      * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
 | 
|---|
| 279 |      * atom directly since this will leave the pointer inside the world.
 | 
|---|
| 280 |    */
 | 
|---|
| 281 |   void destroyAtom(atom*);
 | 
|---|
| 282 | 
 | 
|---|
| 283 |   /**
 | 
|---|
| 284 |    * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
 | 
|---|
| 285 |    * atom directly since this will leave the pointer inside the world.
 | 
|---|
| 286 |    */
 | 
|---|
| 287 |   void destroyAtom(atomId_t);
 | 
|---|
| 288 | 
 | 
|---|
| 289 |   /**
 | 
|---|
| 290 |    * used when changing an atom Id.
 | 
|---|
| 291 |    * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
 | 
|---|
| 292 |    *
 | 
|---|
| 293 |    * Return value indicates whether the change could be done or not.
 | 
|---|
| 294 |    */
 | 
|---|
| 295 |   bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
 | 
|---|
| 296 | 
 | 
|---|
| 297 |   /**
 | 
|---|
| 298 |    * used when changing an molecule Id.
 | 
|---|
| 299 |    * Unless you are calling this method from inside an molecule don't fiddle with the third parameter.
 | 
|---|
| 300 |    *
 | 
|---|
| 301 |    * Return value indicates whether the change could be done or not.
 | 
|---|
| 302 |    */
 | 
|---|
| 303 |   bool changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target=0);
 | 
|---|
| 304 | 
 | 
|---|
| 305 |   /**
 | 
|---|
| 306 |    * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
 | 
|---|
| 307 |    * called at this time, so it can be passed around, stored inside menuItems etc.
 | 
|---|
| 308 |    */
 | 
|---|
| 309 |   MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
 | 
|---|
| 310 |   MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
 | 
|---|
| 311 | 
 | 
|---|
| 312 |   /****
 | 
|---|
| 313 |    * Iterators to use internal data structures
 | 
|---|
| 314 |    * All these iterators are observed to track changes.
 | 
|---|
| 315 |    * There is a corresponding protected section with unobserved iterators,
 | 
|---|
| 316 |    * which can be used internally when the extra speed is needed
 | 
|---|
| 317 |    */
 | 
|---|
| 318 | 
 | 
|---|
| 319 |   typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor>       AtomIterator;
 | 
|---|
| 320 |   typedef SelectiveConstIterator<atom*,AtomSet,AtomDescriptor>       AtomConstIterator;
 | 
|---|
| 321 | 
 | 
|---|
| 322 |   /**
 | 
|---|
| 323 |    * returns an iterator over all Atoms matching a given descriptor.
 | 
|---|
| 324 |    * This iterator is observed, so don't keep it around unnecessary to
 | 
|---|
| 325 |    * avoid unintended blocking.
 | 
|---|
| 326 |    */
 | 
|---|
| 327 |   AtomIterator getAtomIter(AtomDescriptor descr);
 | 
|---|
| 328 |   AtomConstIterator getAtomIter(AtomDescriptor descr) const;
 | 
|---|
| 329 |   AtomIterator getAtomIter();
 | 
|---|
| 330 |   AtomConstIterator getAtomIter() const;
 | 
|---|
| 331 | 
 | 
|---|
| 332 |   AtomIterator atomEnd();
 | 
|---|
| 333 |   AtomConstIterator atomEnd() const;
 | 
|---|
| 334 | 
 | 
|---|
| 335 |   typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor>   MoleculeIterator;
 | 
|---|
| 336 |   typedef SelectiveConstIterator<molecule*,MoleculeSet,MoleculeDescriptor>   MoleculeConstIterator;
 | 
|---|
| 337 | 
 | 
|---|
| 338 |   /**
 | 
|---|
| 339 |    * returns an iterator over all Molecules matching a given descriptor.
 | 
|---|
| 340 |    * This iterator is observed, so don't keep it around unnecessary to
 | 
|---|
| 341 |    * avoid unintended blocking.
 | 
|---|
| 342 |    */
 | 
|---|
| 343 |   MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
 | 
|---|
| 344 |   MoleculeConstIterator getMoleculeIter(MoleculeDescriptor descr) const;
 | 
|---|
| 345 |   MoleculeIterator getMoleculeIter();
 | 
|---|
| 346 |   MoleculeConstIterator getMoleculeIter() const;
 | 
|---|
| 347 | 
 | 
|---|
| 348 |   MoleculeIterator moleculeEnd();
 | 
|---|
| 349 |   MoleculeConstIterator moleculeEnd() const;
 | 
|---|
| 350 | 
 | 
|---|
| 351 |   /******** Selections of molecules and Atoms *************/
 | 
|---|
| 352 |   void clearAtomSelection();
 | 
|---|
| 353 |   void invertAtomSelection();
 | 
|---|
| 354 |   void selectAtom(const atom*);
 | 
|---|
| 355 |   void selectAtom(const atomId_t);
 | 
|---|
| 356 |   void selectAllAtoms(AtomDescriptor);
 | 
|---|
| 357 |   void selectAtomsOfMolecule(const molecule*);
 | 
|---|
| 358 |   void selectAtomsOfMolecule(const moleculeId_t);
 | 
|---|
| 359 |   void unselectAtom(const atom*);
 | 
|---|
| 360 |   void unselectAtom(const atomId_t);
 | 
|---|
| 361 |   void unselectAllAtoms(AtomDescriptor);
 | 
|---|
| 362 |   void unselectAtomsOfMolecule(const molecule*);
 | 
|---|
| 363 |   void unselectAtomsOfMolecule(const moleculeId_t);
 | 
|---|
| 364 |   size_t countSelectedAtoms() const;
 | 
|---|
| 365 |   bool isSelected(const atom *_atom) const;
 | 
|---|
| 366 |   bool isAtomSelected(const atomId_t no) const;
 | 
|---|
| 367 |   const std::vector<atom *> getSelectedAtoms() const;
 | 
|---|
| 368 | 
 | 
|---|
| 369 |   void clearMoleculeSelection();
 | 
|---|
| 370 |   void invertMoleculeSelection();
 | 
|---|
| 371 |   void selectMolecule(const molecule*);
 | 
|---|
| 372 |   void selectMolecule(const moleculeId_t);
 | 
|---|
| 373 |   void selectAllMolecules(MoleculeDescriptor);
 | 
|---|
| 374 |   void selectMoleculeOfAtom(const atom*);
 | 
|---|
| 375 |   void selectMoleculeOfAtom(const atomId_t);
 | 
|---|
| 376 |   void unselectMolecule(const molecule*);
 | 
|---|
| 377 |   void unselectMolecule(const moleculeId_t);
 | 
|---|
| 378 |   void unselectAllMolecules(MoleculeDescriptor);
 | 
|---|
| 379 |   void unselectMoleculeOfAtom(const atom*);
 | 
|---|
| 380 |   void unselectMoleculeOfAtom(const atomId_t);
 | 
|---|
| 381 |   size_t countSelectedMolecules() const;
 | 
|---|
| 382 |   bool isSelected(const molecule *_mol) const;
 | 
|---|
| 383 |   bool isMoleculeSelected(const moleculeId_t no) const;
 | 
|---|
| 384 |   const std::vector<molecule *> getSelectedMolecules() const;
 | 
|---|
| 385 | 
 | 
|---|
| 386 |   /******************** Iterators to selections *****************/
 | 
|---|
| 387 |   typedef AtomSet::iterator AtomSelectionIterator;
 | 
|---|
| 388 |   AtomSelectionIterator beginAtomSelection();
 | 
|---|
| 389 |   AtomSelectionIterator endAtomSelection();
 | 
|---|
| 390 |   typedef AtomSet::const_iterator AtomSelectionConstIterator;
 | 
|---|
| 391 |   AtomSelectionConstIterator beginAtomSelection() const;
 | 
|---|
| 392 |   AtomSelectionConstIterator endAtomSelection() const;
 | 
|---|
| 393 | 
 | 
|---|
| 394 |   typedef MoleculeSet::iterator MoleculeSelectionIterator;
 | 
|---|
| 395 |   MoleculeSelectionIterator beginMoleculeSelection();
 | 
|---|
| 396 |   MoleculeSelectionIterator endMoleculeSelection();
 | 
|---|
| 397 |   typedef MoleculeSet::const_iterator MoleculeSelectionConstIterator;
 | 
|---|
| 398 |   MoleculeSelectionConstIterator beginMoleculeSelection() const;
 | 
|---|
| 399 |   MoleculeSelectionConstIterator endMoleculeSelection() const;
 | 
|---|
| 400 | 
 | 
|---|
| 401 | protected:
 | 
|---|
| 402 |   /****
 | 
|---|
| 403 |    * Iterators to use internal data structures
 | 
|---|
| 404 |    * All these iterators are unobserved for speed reasons.
 | 
|---|
| 405 |    * There is a corresponding public section to these methods,
 | 
|---|
| 406 |    * which produce observed iterators.*/
 | 
|---|
| 407 | 
 | 
|---|
| 408 |   // Atoms
 | 
|---|
| 409 |   typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor>        internal_AtomIterator;
 | 
|---|
| 410 | 
 | 
|---|
| 411 |   /**
 | 
|---|
| 412 |    * returns an iterator over all Atoms matching a given descriptor.
 | 
|---|
| 413 |    * used for internal purposes, like AtomProcesses and AtomCalculations.
 | 
|---|
| 414 |    */
 | 
|---|
| 415 |   internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
 | 
|---|
| 416 | 
 | 
|---|
| 417 |   /**
 | 
|---|
| 418 |    * returns an iterator to the end of the AtomSet. Due to overloading this iterator
 | 
|---|
| 419 |    * can be compared to iterators produced by getAtomIter (see the mis-matching types).
 | 
|---|
| 420 |    * Thus it can be used to detect when such an iterator is at the end of the list.
 | 
|---|
| 421 |    * used for internal purposes, like AtomProcesses and AtomCalculations.
 | 
|---|
| 422 |    */
 | 
|---|
| 423 |   internal_AtomIterator atomEnd_internal();
 | 
|---|
| 424 | 
 | 
|---|
| 425 |   // Molecules
 | 
|---|
| 426 |   typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor>   internal_MoleculeIterator;
 | 
|---|
| 427 | 
 | 
|---|
| 428 | 
 | 
|---|
| 429 |   /**
 | 
|---|
| 430 |    * returns an iterator over all Molecules matching a given descriptor.
 | 
|---|
| 431 |    * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
 | 
|---|
| 432 |    */
 | 
|---|
| 433 |   internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
 | 
|---|
| 434 | 
 | 
|---|
| 435 |   /**
 | 
|---|
| 436 |    * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
 | 
|---|
| 437 |    * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
 | 
|---|
| 438 |    * Thus it can be used to detect when such an iterator is at the end of the list.
 | 
|---|
| 439 |    * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
 | 
|---|
| 440 |    */
 | 
|---|
| 441 |   internal_MoleculeIterator moleculeEnd_internal();
 | 
|---|
| 442 | 
 | 
|---|
| 443 | 
 | 
|---|
| 444 |   /******* Internal manipulation routines for double callback and Observer mechanism ******/
 | 
|---|
| 445 |   void doManipulate(MoleCuilder::ManipulateAtomsProcess *);
 | 
|---|
| 446 | 
 | 
|---|
| 447 | private:
 | 
|---|
| 448 | 
 | 
|---|
| 449 |   friend const atom *detail::lastChanged<atom>();
 | 
|---|
| 450 |   friend const molecule *detail::lastChanged<molecule>();
 | 
|---|
| 451 |   static atom *_lastchangedatom;
 | 
|---|
| 452 |   static molecule*_lastchangedmol;
 | 
|---|
| 453 | 
 | 
|---|
| 454 |   BondGraph *BG;
 | 
|---|
| 455 |   periodentafel *periode;
 | 
|---|
| 456 |   config *configuration;
 | 
|---|
| 457 |   Box *cell_size;
 | 
|---|
| 458 |   LinkedCell::LinkedCell_Controller *LCcontroller;
 | 
|---|
| 459 |   std::string defaultName;
 | 
|---|
| 460 |   class ThermoStatContainer *Thermostats;
 | 
|---|
| 461 |   int ExitFlag;
 | 
|---|
| 462 | private:
 | 
|---|
| 463 | 
 | 
|---|
| 464 |   AtomSet atoms;
 | 
|---|
| 465 |   AtomSet selectedAtoms;
 | 
|---|
| 466 |   /**
 | 
|---|
| 467 |    * stores the pool for all available AtomIds below currAtomId
 | 
|---|
| 468 |    *
 | 
|---|
| 469 |    * The pool contains ranges of free ids in the form [bottom,top).
 | 
|---|
| 470 |    */
 | 
|---|
| 471 |   IdPool<atomId_t, uniqueId> atomIdPool;
 | 
|---|
| 472 | 
 | 
|---|
| 473 |   MoleculeSet molecules;
 | 
|---|
| 474 |   MoleculeSet selectedMolecules;
 | 
|---|
| 475 |   /**
 | 
|---|
| 476 |    * stores the pool for all available AtomIds below currAtomId
 | 
|---|
| 477 |    *
 | 
|---|
| 478 |    * The pool contains ranges of free ids in the form [bottom,top).
 | 
|---|
| 479 |    */
 | 
|---|
| 480 |   IdPool<moleculeId_t, continuousId> moleculeIdPool;
 | 
|---|
| 481 | 
 | 
|---|
| 482 | private:
 | 
|---|
| 483 |   /**
 | 
|---|
| 484 |    * private constructor to ensure creation of the world using
 | 
|---|
| 485 |    * the singleton pattern.
 | 
|---|
| 486 |    */
 | 
|---|
| 487 |   World();
 | 
|---|
| 488 | 
 | 
|---|
| 489 |   /**
 | 
|---|
| 490 |    * private destructor to ensure destruction of the world using the
 | 
|---|
| 491 |    * singleton pattern.
 | 
|---|
| 492 |    */
 | 
|---|
| 493 |   virtual ~World();
 | 
|---|
| 494 | 
 | 
|---|
| 495 |   /*****
 | 
|---|
| 496 |    * some legacy stuff that is include for now but will be removed later
 | 
|---|
| 497 |    *****/
 | 
|---|
| 498 | public:
 | 
|---|
| 499 |   MoleculeListClass *&getMolecules();
 | 
|---|
| 500 | 
 | 
|---|
| 501 | private:
 | 
|---|
| 502 |   MoleculeListClass *molecules_deprecated;
 | 
|---|
| 503 | };
 | 
|---|
| 504 | 
 | 
|---|
| 505 | /** Externalized stuff as member functions cannot be specialized without
 | 
|---|
| 506 |  *  specializing the class, too.
 | 
|---|
| 507 |  */
 | 
|---|
| 508 | namespace detail {
 | 
|---|
| 509 |   template <>       inline  const atom* lastChanged<atom>() { return World::_lastchangedatom; }
 | 
|---|
| 510 |   template <>       inline  const molecule* lastChanged<molecule>() { return World::_lastchangedmol; }
 | 
|---|
| 511 | }
 | 
|---|
| 512 | 
 | 
|---|
| 513 | 
 | 
|---|
| 514 | #endif /* WORLD_HPP_ */
 | 
|---|