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