Changes in / [a77c96:cd032d]
- Location:
- src
- Files:
-
- 4 added
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/Action.cpp
ra77c96 rcd032d 17 17 { 18 18 if(_doRegister){ 19 ActionRegistry::get Registry()->registerAction(this);19 ActionRegistry::getInstance().registerAction(this); 20 20 } 21 21 } -
src/Actions/ActionRegistry.cpp
ra77c96 rcd032d 9 9 #include "Actions/Action.hpp" 10 10 11 #include "Patterns/Singleton_impl.hpp" 12 11 13 #include <string> 12 14 #include <cassert> … … 14 16 15 17 using namespace std; 16 17 ActionRegistry *ActionRegistry::theInstance=0;18 18 19 19 ActionRegistry::ActionRegistry() … … 43 43 } 44 44 45 // singleton stuff 46 ActionRegistry* ActionRegistry::getRegistry(){ 47 if(!theInstance){ 48 theInstance = new ActionRegistry(); 49 } 50 return theInstance; 51 } 52 53 void ActionRegistry::purgeRegistry(){ 54 if(theInstance){ 55 delete theInstance; 56 theInstance = 0; 57 } 58 } 45 CONSTRUCT_SINGLETON(ActionRegistry) -
src/Actions/ActionRegistry.hpp
ra77c96 rcd032d 12 12 #include <map> 13 13 14 #include "Patterns/Singleton.hpp" 15 14 16 class Action; 15 17 16 class ActionRegistry 18 class ActionRegistry : public Singleton<ActionRegistry> 17 19 { 20 friend class Singleton<ActionRegistry>; 18 21 public: 19 22 Action* getActionByName(const std::string); … … 23 26 std::map<const std::string,Action*> actionMap; 24 27 25 // singleton stuff26 public:27 static ActionRegistry* getRegistry();28 static void purgeRegistry();29 28 private: 30 29 ActionRegistry(); 31 30 virtual ~ActionRegistry(); 32 static ActionRegistry *theInstance;33 31 }; 34 32 -
src/Actions/AtomsCalculation_impl.hpp
ra77c96 rcd032d 29 29 template<typename T> 30 30 std::vector<T>* AtomsCalculation<T>::doCalc(){ 31 World* world = World::get ();31 World* world = World::getPointer(); 32 32 int steps = world->numAtoms(); 33 int count = 0;34 33 std::vector<T> *res = new std::vector<T>(); 35 34 res->reserve(steps); -
src/Actions/ManipulateAtomsProcess.cpp
ra77c96 rcd032d 23 23 24 24 void ManipulateAtomsProcess::call(){ 25 World::get ()->doManipulate(this);25 World::getInstance().doManipulate(this); 26 26 } 27 27 -
src/Actions/small_actions.cpp
ra77c96 rcd032d 27 27 string filename; 28 28 molecule *mol = NULL; 29 Dialog *dialog = UIFactory::get ()->makeDialog();29 Dialog *dialog = UIFactory::getInstance().makeDialog(); 30 30 31 31 dialog->queryMolecule("Enter index of molecule: ",&mol,molecules); -
src/Descriptors/AtomDescriptor.cpp
ra77c96 rcd032d 68 68 69 69 World::AtomSet& AtomDescriptor_impl::getAtoms(){ 70 return World::get ()->atoms;70 return World::getInstance().atoms; 71 71 } 72 72 -
src/Descriptors/AtomTypeDescriptor.cpp
ra77c96 rcd032d 29 29 30 30 AtomDescriptor AtomByType(int Z){ 31 element * elem = World::get ()->getPeriode()->FindElement(Z);31 element * elem = World::getInstance().getPeriode()->FindElement(Z); 32 32 return AtomByType(elem); 33 33 } -
src/Descriptors/MoleculeDescriptor.cpp
ra77c96 rcd032d 68 68 69 69 World::MoleculeSet& MoleculeDescriptor_impl::getMolecules(){ 70 return World::get ()->molecules;70 return World::getInstance().molecules; 71 71 } 72 72 -
src/Legacy/oldmenu.cpp
ra77c96 rcd032d 78 78 case 'a': // absolute coordinates of atom 79 79 Log() << Verbose(0) << "Enter absolute coordinates." << endl; 80 first = World::get ()->createAtom();80 first = World::getInstance().createAtom(); 81 81 first->x.AskPosition(mol->cell_size, false); 82 82 first->type = periode->AskElement(); // give type … … 85 85 86 86 case 'b': // relative coordinates of atom wrt to reference point 87 first = World::get ()->createAtom();87 first = World::getInstance().createAtom(); 88 88 valid = true; 89 89 do { … … 101 101 102 102 case 'c': // relative coordinates of atom wrt to already placed atom 103 first = World::get ()->createAtom();103 first = World::getInstance().createAtom(); 104 104 valid = true; 105 105 do { … … 117 117 118 118 case 'd': // two atoms, two angles and a distance 119 first = World::get ()->createAtom();119 first = World::getInstance().createAtom(); 120 120 valid = true; 121 121 do { … … 217 217 218 218 case 'e': // least square distance position to a set of atoms 219 first = World::get ()->createAtom();219 first = World::getInstance().createAtom(); 220 220 atoms = new (Vector*[128]); 221 221 valid = true; … … 239 239 mol->AddAtom(first); // add to molecule 240 240 } else { 241 World::get ()->destroyAtom(first);241 World::getInstance().destroyAtom(first); 242 242 Log() << Verbose(0) << "Please enter at least two vectors!\n"; 243 243 } … … 782 782 x.AddVector(&y); // per factor one cell width further 783 783 for (int k=count;k--;) { // go through every atom of the original cell 784 first = World::get ()->createAtom(); // create a new body784 first = World::getInstance().createAtom(); // create a new body 785 785 first->x.CopyVector(vectors[k]); // use coordinate of original atom 786 786 first->x.AddVector(&x); // translate the coordinates … … 912 912 void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) { 913 913 molecule *srcmol = NULL, *destmol = NULL; 914 Dialog *dialog = UIFactory::get ()->makeDialog();914 Dialog *dialog = UIFactory::getInstance().makeDialog(); 915 915 dialog->queryMolecule("Enter index of destination molecule: ",&destmol, molecules); 916 916 dialog->queryMolecule("Enter index of source molecule to add from: ",&srcmol, molecules); … … 926 926 void oldmenu::embeddMolecules(MoleculeListClass *molecules) { 927 927 molecule *srcmol = NULL, *destmol = NULL; 928 Dialog *dialog = UIFactory::get ()->makeDialog();928 Dialog *dialog = UIFactory::getInstance().makeDialog(); 929 929 dialog->queryMolecule("Enter index of matrix molecule (the variable one): ",&srcmol,molecules); 930 930 dialog->queryMolecule("Enter index of molecule to merge into (the fixed one): ",&destmol,molecules); … … 1089 1089 A++; 1090 1090 } 1091 World::get ()->destroyMolecule(mol);1091 World::getInstance().destroyMolecule(mol); 1092 1092 }; 1093 1093 -
src/Makefile.am
ra77c96 rcd032d 18 18 19 19 PATTERNSOURCE = Patterns/Observer.cpp 20 PATTERNHEADER = Patterns/Observer.hpp Patterns/Cacheable.hpp 20 PATTERNHEADER = Patterns/Cacheable.hpp \ 21 Patterns/Observer.hpp \ 22 Patterns/Singleton.hpp 21 23 22 24 VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp -
src/UIElements/QT4/QTDialog.cpp
ra77c96 rcd032d 266 266 parent(_parent) 267 267 { 268 periodentafel *periode = World::get ()->getPeriode();268 periodentafel *periode = World::getInstance().getPeriode(); 269 269 thisLayout = new QHBoxLayout(); 270 270 titleLabel = new QLabel(QString(getTitle().c_str())); … … 367 367 QVariant data = theBox->itemData(newIndex); 368 368 int idx = data.toInt(); 369 (*content) = World::get ()->getPeriode()->FindElement(idx);370 dialog->update(); 371 } 372 369 (*content) = World::getInstance().getPeriode()->FindElement(idx); 370 dialog->update(); 371 } 372 -
src/UIElements/TextDialog.cpp
ra77c96 rcd032d 136 136 Log() << Verbose(0) << getTitle(); 137 137 cin >> Z; 138 tmp = World::get ()->getPeriode()->FindElement(Z);138 tmp = World::getInstance().getPeriode()->FindElement(Z); 139 139 return tmp; 140 140 } -
src/UIElements/UIFactory.cpp
ra77c96 rcd032d 8 8 9 9 #include <cassert> 10 #include "Patterns/Singleton_impl.hpp" 10 11 #include "UIElements/UIFactory.hpp" 11 12 … … 15 16 #include "UIElements/QT4/QTUIFactory.hpp" 16 17 #endif 17 18 UIFactory *UIFactory::theFactory = 0;19 18 20 19 UIFactory::UIFactory() … … 30 29 31 30 void UIFactory::makeUserInterface(InterfaceTypes type) { 32 assert(theFactory == 0 && "makeUserInterface should only be called once");33 31 switch(type) { 34 32 case Text : 35 theFactory = new TextUIFactory();33 setInstance(new TextUIFactory()); 36 34 break; 37 35 #ifdef USE_GUI_QT 38 36 case QT4 : 39 theFactory = new QTUIFactory();37 setInstance(new QTUIFactory()); 40 38 break; 41 39 #endif … … 46 44 } 47 45 48 UIFactory* UIFactory::get(){ 49 assert(theFactory != 0 && "No UserInterface created prior to factory access"); 50 return theFactory; 51 } 52 53 54 void UIFactory::purgeInstance(){ 55 if(theFactory) { 56 delete theFactory; 57 theFactory = 0; 58 } 59 } 46 CONSTRUCT_SINGLETON(UIFactory) -
src/UIElements/UIFactory.hpp
ra77c96 rcd032d 17 17 18 18 struct menuPopulaters; 19 20 #include "Patterns/Singleton.hpp" 21 19 22 /** 20 23 * Abstract Factory to create any kind of User interface object needed by the programm. … … 24 27 * UIs can be handled in a concise abstract way. 25 28 */ 26 class UIFactory 29 class UIFactory : public Singleton<UIFactory,false> 27 30 { 28 31 … … 50 53 UIFactory(); 51 54 52 // singleton stuff53 private:54 static UIFactory *theFactory;55 56 55 public: 57 56 /** … … 60 59 static void makeUserInterface(InterfaceTypes type); 61 60 62 /**63 * get the previously created factory64 */65 static UIFactory* get();66 67 /**68 * Destroy the created factory.69 *70 * Make sure that all UIElements that were created by the factory are destroyed before calling this method.71 */72 static void purgeInstance();73 61 }; 74 62 -
src/Views/QT4/QTStatusBar.cpp
ra77c96 rcd032d 21 21 QStatusBar(_parent), 22 22 parent(_parent), 23 atomCount(World::get ()->numAtoms()),24 moleculeCount(World::get ()->numMolecules())23 atomCount(World::getInstance().numAtoms()), 24 moleculeCount(World::getInstance().numMolecules()) 25 25 { 26 World::get ()->signOn(this);26 World::getInstance().signOn(this); 27 27 Process::AddObserver(this); 28 28 statusLabel = new QLabel(this); … … 35 35 { 36 36 Process::RemoveObserver(this); 37 World::get ()->signOff(this);37 World::getInstance().signOff(this); 38 38 } 39 39 40 40 void QTStatusBar::update(Observable *subject){ 41 if (subject==World::get ()){42 atomCount = World::get ()->numAtoms();43 moleculeCount = World::get ()->numMolecules();41 if (subject==World::getPointer()){ 42 atomCount = World::getInstance().numAtoms(); 43 moleculeCount = World::getInstance().numMolecules(); 44 44 redrawStatus(); 45 45 } … … 47 47 // we probably have some process 48 48 Process *proc; 49 if( proc=dynamic_cast<Process*>(subject)){49 if((proc=dynamic_cast<Process*>(subject))){ 50 50 redrawProcess(proc); 51 51 } … … 55 55 void QTStatusBar::subjectKilled(Observable *subject){ 56 56 // Processes don't notify when they are killed 57 atomCount = World::get ()->numAtoms();58 moleculeCount = World::get ()->numMolecules();59 World::get ()->signOn(this);57 atomCount = World::getInstance().numAtoms(); 58 moleculeCount = World::getInstance().numMolecules(); 59 World::getInstance().signOn(this); 60 60 redrawStatus(); 61 61 } -
src/World.cpp
ra77c96 rcd032d 16 16 #include "Descriptors/MoleculeDescriptor_impl.hpp" 17 17 #include "Actions/ManipulateAtomsProcess.hpp" 18 19 #include "Patterns/Singleton_impl.hpp" 18 20 19 21 using namespace std; … … 229 231 /******************************* Singleton Stuff **************************/ 230 232 231 // TODO: Hide boost-thread using Autotools stuff when no threads are used232 World* World::theWorld = 0;233 boost::mutex World::worldLock;234 235 233 World::World() : 236 234 periode(new periodentafel), … … 261 259 } 262 260 263 World* World::get(){ 264 // boost supports RAII-Style locking, so we don't need to unlock 265 boost::mutex::scoped_lock guard(worldLock); 266 if(!theWorld) { 267 theWorld = new World(); 268 } 269 return theWorld; 270 } 271 272 void World::destroy(){ 273 // boost supports RAII-Style locking, so we don't need to unlock 274 boost::mutex::scoped_lock guard(worldLock); 275 delete theWorld; 276 theWorld = 0; 277 } 278 279 World* World::reset(){ 280 World* oldWorld = 0; 281 { 282 // boost supports RAII-Style locking, so we don't need to unlock 283 boost::mutex::scoped_lock guard(worldLock); 284 285 oldWorld = theWorld; 286 theWorld = new World(); 287 // oldworld does not need protection any more, 288 // since we should have the only reference 289 290 // worldLock handles access to the pointer, 291 // not to the object 292 } // scope-end releases the lock 293 294 // we have to let all the observers know that the 295 // oldWorld was destroyed. oldWorld calls subjectKilled 296 // upon destruction. Every Observer getting that signal 297 // should see that it gets the updated new world 298 delete oldWorld; 299 return theWorld; 300 } 261 // Explicit instantiation of the singleton mechanism at this point 262 263 CONSTRUCT_SINGLETON(World) 301 264 302 265 /******************************* deprecated Legacy Stuff ***********************/ -
src/World.hpp
ra77c96 rcd032d 19 19 #include "Patterns/Observer.hpp" 20 20 #include "Patterns/Cacheable.hpp" 21 #include "Patterns/Singleton.hpp" 22 21 23 22 24 // forward declarations … … 33 35 class AtomsCalculation; 34 36 35 class World : public Observable 37 38 39 class World : public Singleton<World>, public Observable 36 40 { 41 42 // Make access to constructor and destructor possible from inside the singleton 43 friend class Singleton<World>; 44 37 45 // necessary for coupling with descriptors 38 46 friend class AtomDescriptor_impl; … … 45 53 template<typename> friend class AtomsCalculation; 46 54 public: 55 56 // Types for Atom and Molecule structures 47 57 typedef std::map<atomId_t,atom*> AtomSet; 48 58 typedef std::map<moleculeId_t,molecule*> MoleculeSet; … … 151 161 // Atoms 152 162 153 class AtomIterator { 163 class AtomIterator : 164 public std::iterator<std::iterator_traits<AtomSet::iterator>::difference_type, 165 std::iterator_traits<AtomSet::iterator>::value_type, 166 std::iterator_traits<AtomSet::iterator>::pointer, 167 std::iterator_traits<AtomSet::iterator>::reference> 168 { 154 169 public: 170 171 typedef AtomSet::iterator _Iter; 172 typedef _Iter::value_type value_type; 173 typedef _Iter::difference_type difference_type; 174 typedef _Iter::pointer pointer; 175 typedef _Iter::reference reference; 176 typedef _Iter::iterator_category iterator_category; 177 178 155 179 AtomIterator(); 156 180 AtomIterator(AtomDescriptor, World*); … … 191 215 // Molecules 192 216 193 class MoleculeIterator { 217 class MoleculeIterator : 218 public std::iterator<std::iterator_traits<MoleculeSet::iterator>::difference_type, 219 std::iterator_traits<MoleculeSet::iterator>::value_type, 220 std::iterator_traits<MoleculeSet::iterator>::pointer, 221 std::iterator_traits<MoleculeSet::iterator>::reference> 222 { 194 223 public: 224 225 typedef MoleculeSet::iterator _Iter; 226 typedef _Iter::value_type value_type; 227 typedef _Iter::difference_type difference_type; 228 typedef _Iter::pointer pointer; 229 typedef _Iter::reference reference; 230 typedef _Iter::iterator_category iterator_category; 231 195 232 MoleculeIterator(); 196 233 MoleculeIterator(MoleculeDescriptor, World*); … … 245 282 MoleculeSet molecules; 246 283 moleculeId_t currMoleculeId; 247 248 249 /***** singleton Stuff *****/250 public:251 252 /**253 * get the currently active instance of the World.254 */255 static World* get();256 257 /**258 * destroy the currently active instance of the World.259 */260 static void destroy();261 262 /**263 * destroy the currently active instance of the World and immidiately264 * create a new one. Use this to reset while somebody is still Observing265 * the world and should reset the observed instance. All observers will be266 * sent the subjectKille() message from the old world.267 */268 static World* reset();269 270 284 private: 271 285 /** … … 280 294 */ 281 295 virtual ~World(); 282 283 static World *theWorld;284 // this mutex only saves the singleton pattern...285 // use other mutexes to protect internal data as well286 // this mutex handles access to the pointer, not to the object!!!287 static boost::mutex worldLock;288 296 289 297 /***** -
src/WorldIterators.cpp
ra77c96 rcd032d 17 17 18 18 World::AtomIterator::AtomIterator(){ 19 state = World::get ()->atomEnd();19 state = World::getInstance().atomEnd(); 20 20 } 21 21 … … 95 95 96 96 World::MoleculeIterator::MoleculeIterator(){ 97 state = World::get ()->moleculeEnd();97 state = World::getInstance().moleculeEnd(); 98 98 } 99 99 -
src/atom.cpp
ra77c96 rcd032d 50 50 res->FixedIon = FixedIon; 51 51 res->node = &x; 52 World::get ()->registerAtom(res);52 World::getInstance().registerAtom(res); 53 53 return res; 54 54 } -
src/atom_atominfo.cpp
ra77c96 rcd032d 29 29 30 30 void AtomInfo::setType(int Z) { 31 element *elem = World::get ()->getPeriode()->FindElement(Z);31 element *elem = World::getInstance().getPeriode()->FindElement(Z); 32 32 setType(elem); 33 33 } -
src/boundary.cpp
ra77c96 rcd032d 801 801 { 802 802 Info FunctionInfo(__func__); 803 molecule *Filling = World::get ()->createMolecule();803 molecule *Filling = World::getInstance().createMolecule(); 804 804 Vector CurrentPosition; 805 805 int N[NDIM]; -
src/builder.cpp
ra77c96 rcd032d 1433 1433 } 1434 1434 if (mol == NULL) { 1435 mol = World::get ()->createMolecule();1435 mol = World::getInstance().createMolecule(); 1436 1436 mol->ActiveFlag = true; 1437 1437 if (ConfigFileName != NULL) … … 1482 1482 SaveFlag = true; 1483 1483 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), "; 1484 first = World::get ()->createAtom();1484 first = World::getInstance().createAtom(); 1485 1485 first->type = periode->FindElement(atoi(argv[argptr])); 1486 1486 if (first->type != NULL) … … 1635 1635 Log() << Verbose(1) << "Filling Box with water molecules." << endl; 1636 1636 // construct water molecule 1637 molecule *filler = World::get ()->createMolecule();1637 molecule *filler = World::getInstance().createMolecule(); 1638 1638 molecule *Filling = NULL; 1639 1639 atom *second = NULL, *third = NULL; … … 1642 1642 // first->x.Zero(); 1643 1643 // filler->AddAtom(first); 1644 first = World::get ()->createAtom();1644 first = World::getInstance().createAtom(); 1645 1645 first->type = periode->FindElement(1); 1646 1646 first->x.Init(0.441, -0.143, 0.); 1647 1647 filler->AddAtom(first); 1648 second = World::get ()->createAtom();1648 second = World::getInstance().createAtom(); 1649 1649 second->type = periode->FindElement(1); 1650 1650 second->x.Init(-0.464, 1.137, 0.0); 1651 1651 filler->AddAtom(second); 1652 third = World::get ()->createAtom();1652 third = World::getInstance().createAtom(); 1653 1653 third->type = periode->FindElement(8); 1654 1654 third->x.Init(-0.464, 0.177, 0.); … … 1665 1665 molecules->insert(Filling); 1666 1666 } 1667 World::get ()->destroyMolecule(filler);1667 World::getInstance().destroyMolecule(filler); 1668 1668 argptr+=6; 1669 1669 } … … 2098 2098 x.AddVector(&y); // per factor one cell width further 2099 2099 for (int k=count;k--;) { // go through every atom of the original cell 2100 first = World::get ()->createAtom(); // create a new body2100 first = World::getInstance().createAtom(); // create a new body 2101 2101 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2102 2102 first->x.AddVector(&x); // translate the coordinates … … 2169 2169 void cleanUp(config *configuration){ 2170 2170 UIFactory::purgeInstance(); 2171 World:: destroy();2171 World::purgeInstance(); 2172 2172 delete(configuration); 2173 2173 Log() << Verbose(0) << "Maximum of allocated memory: " … … 2178 2178 logger::purgeInstance(); 2179 2179 errorLogger::purgeInstance(); 2180 ActionRegistry::purge Registry();2180 ActionRegistry::purgeInstance(); 2181 2181 } 2182 2182 … … 2193 2193 setVerbosity(0); 2194 2194 /* structure of ParseCommandLineOptions will be refactored later */ 2195 j = ParseCommandLineOptions(argc, argv, World::get ()->getMolecules(), World::get()->getPeriode(), *configuration, ConfigFileName);2195 j = ParseCommandLineOptions(argc, argv, World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName); 2196 2196 switch (j){ 2197 2197 case 255: … … 2203 2203 break; 2204 2204 } 2205 if(World::get ()->numMolecules() == 0){2206 mol = World::get ()->createMolecule();2207 World::get ()->getMolecules()->insert(mol);2205 if(World::getInstance().numMolecules() == 0){ 2206 mol = World::getInstance().createMolecule(); 2207 World::getInstance().getMolecules()->insert(mol); 2208 2208 if(mol->cell_size[0] == 0.){ 2209 2209 Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl; … … 2228 2228 UIFactory::makeUserInterface(UIFactory::Text); 2229 2229 #endif 2230 MainWindow *mainWindow = UIFactory::get ()->makeMainWindow(populaters,World::get()->getMolecules(), configuration, World::get()->getPeriode(), ConfigFileName);2230 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName); 2231 2231 mainWindow->display(); 2232 2232 … … 2234 2234 } 2235 2235 2236 if(World::get ()->getPeriode()->StorePeriodentafel(configuration->databasepath))2236 if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath)) 2237 2237 Log() << Verbose(0) << "Saving of elements.db successful." << endl; 2238 2238 -
src/config.cpp
ra77c96 rcd032d 733 733 sprintf(keyword,"%s_%i",name, j+1); 734 734 if (repetition == 0) { 735 neues = World::get ()->createAtom();735 neues = World::getInstance().createAtom(); 736 736 AtomList[i][j] = neues; 737 737 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 812 812 sprintf(keyword,"%s_%i",name, j+1); 813 813 if (repetition == 0) { 814 neues = World::get ()->createAtom();814 neues = World::getInstance().createAtom(); 815 815 AtomList[i][j] = neues; 816 816 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 851 851 void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList) 852 852 { 853 molecule *mol = World::get ()->createMolecule();853 molecule *mol = World::getInstance().createMolecule(); 854 854 ifstream *file = new ifstream(filename); 855 855 if (file == NULL) { … … 1089 1089 void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList) 1090 1090 { 1091 molecule *mol = World::get ()->createMolecule();1091 molecule *mol = World::getInstance().createMolecule(); 1092 1092 ifstream *file = new ifstream(filename); 1093 1093 if (file == NULL) { … … 1288 1288 } 1289 1289 istringstream input2(zeile); 1290 atom *neues = World::get ()->createAtom();1290 atom *neues = World::getInstance().createAtom(); 1291 1291 input2 >> neues->x.x[0]; // x 1292 1292 input2 >> neues->x.x[1]; // y … … 1788 1788 char filename[MAXSTRINGSIZE]; 1789 1789 ofstream output; 1790 molecule *mol = World::get ()->createMolecule();1790 molecule *mol = World::getInstance().createMolecule(); 1791 1791 mol->SetNameFromFilename(ConfigFileName); 1792 1792 … … 1899 1899 } 1900 1900 1901 World::get ()->destroyMolecule(mol);1901 World::getInstance().destroyMolecule(mol); 1902 1902 }; 1903 1903 -
src/errorlogger.cpp
ra77c96 rcd032d 9 9 #include "errorlogger.hpp" 10 10 #include "verbose.hpp" 11 #include "Patterns/Singleton_impl.hpp" 11 12 12 13 ofstream null("/dev/null"); 13 14 errorLogger* errorLogger::instance = NULL;15 14 int errorLogger::verbosity = 2; 16 15 ostream* errorLogger::nix = &null; … … 23 22 errorLogger::errorLogger() 24 23 { 25 instance = NULL;26 24 verbosity = 2; 27 25 }; … … 34 32 } 35 33 36 /** 37 * Returns the singleton errorLogger instance. 38 * 39 * \return errorLogger instance 40 */ 41 errorLogger* errorLogger::getInstance() { 42 if (instance == NULL) { 43 instance = new errorLogger(); 44 } 45 46 return instance; 47 } 48 49 50 /** 51 * Purges the current errorLogger instance. 52 */ 53 void errorLogger::purgeInstance() { 54 if (instance != NULL) { 55 delete instance; 56 } 57 58 instance = NULL; 59 } 34 CONSTRUCT_SINGLETON(errorLogger) 60 35 61 36 /** -
src/errorlogger.hpp
ra77c96 rcd032d 11 11 #include <iostream> 12 12 13 #include "Patterns/Singleton.hpp" 14 13 15 using namespace std; 14 16 15 17 class Verbose; 16 18 17 class errorLogger { 19 class errorLogger : public Singleton<errorLogger>{ 20 friend class Singleton<errorLogger>; 18 21 public : 19 22 static ostream *nix; 20 23 static int verbosity; 21 24 22 static errorLogger* getInstance();23 static void purgeInstance();24 25 static bool DoOutput(); 25 26 static void setVerbosity(int verbosityLevel); … … 31 32 ~errorLogger(); 32 33 33 private:34 static errorLogger* instance;35 34 }; 36 35 -
src/log.cpp
ra77c96 rcd032d 15 15 */ 16 16 void setVerbosity(int verbosityLevel) { 17 logger::getInstance() ->setVerbosity(verbosityLevel);18 errorLogger::getInstance() ->setVerbosity(verbosityLevel);17 logger::getInstance().setVerbosity(verbosityLevel); 18 errorLogger::getInstance().setVerbosity(verbosityLevel); 19 19 } 20 20 … … 24 24 * \param indentation level of the message to log 25 25 */ 26 class logger *Log() {26 class logger& Log() { 27 27 return logger::getInstance(); 28 28 } … … 33 33 * \param indentation level of the message to log 34 34 */ 35 class errorLogger *eLog() {35 class errorLogger & eLog() { 36 36 return errorLogger::getInstance(); 37 37 } -
src/logger.cpp
ra77c96 rcd032d 9 9 #include "logger.hpp" 10 10 #include "verbose.hpp" 11 #include "Patterns/Singleton_impl.hpp" 11 12 12 13 ofstream nullStream("/dev/null"); 13 14 14 logger* logger::instance = NULL;15 15 int logger::verbosity = 2; 16 16 ostream* logger::nix = &nullStream; … … 23 23 logger::logger() 24 24 { 25 instance = NULL;26 25 verbosity = 2; 27 26 }; … … 34 33 } 35 34 36 /** 37 * Returns the singleton logger instance. 38 * 39 * \return logger instance 40 */ 41 logger* logger::getInstance() { 42 if (instance == NULL) { 43 instance = new logger(); 44 } 45 46 return instance; 47 } 48 49 50 /** 51 * Purges the current logger instance. 52 */ 53 void logger::purgeInstance() { 54 if (instance != NULL) { 55 delete instance; 56 } 57 58 instance = NULL; 59 } 35 CONSTRUCT_SINGLETON(logger) 60 36 61 37 /** -
src/logger.hpp
ra77c96 rcd032d 11 11 #include <iostream> 12 12 13 #include "Patterns/Singleton.hpp" 14 13 15 using namespace std; 14 16 15 17 class Verbose; 16 18 17 class logger { 19 class logger : public Singleton<logger> { 20 friend class Singleton<logger>; 18 21 public : 19 22 static ostream *nix; 20 23 static int verbosity; 21 24 22 static logger* getInstance();23 static void purgeInstance();24 25 static bool DoOutput(); 25 26 static void setVerbosity(int verbosityLevel); … … 30 31 /** Do not call this destructor directly, use purgeInstance() instead. */ 31 32 ~logger(); 32 33 private:34 static logger* instance;35 33 }; 36 34 -
src/molecule.cpp
ra77c96 rcd032d 31 31 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 32 32 */ 33 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get ()->createAtom()), end(World::get()->createAtom()),33 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::getInstance().createAtom()), end(World::getInstance().createAtom()), 34 34 first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0), 35 35 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.), … … 56 56 57 57 molecule *NewMolecule(){ 58 return new molecule(World::get ()->getPeriode());58 return new molecule(World::getInstance().getPeriode()); 59 59 } 60 60 … … 261 261 switch(TopBond->BondDegree) { 262 262 case 1: 263 FirstOtherAtom = World::get ()->createAtom(); // new atom263 FirstOtherAtom = World::getInstance().createAtom(); // new atom 264 264 FirstOtherAtom->type = elemente->FindElement(1); // element is Hydrogen 265 265 FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity … … 318 318 319 319 // create the two Hydrogens ... 320 FirstOtherAtom = World::get ()->createAtom();321 SecondOtherAtom = World::get ()->createAtom();320 FirstOtherAtom = World::getInstance().createAtom(); 321 SecondOtherAtom = World::getInstance().createAtom(); 322 322 FirstOtherAtom->type = elemente->FindElement(1); 323 323 SecondOtherAtom->type = elemente->FindElement(1); … … 373 373 case 3: 374 374 // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid) 375 FirstOtherAtom = World::get ()->createAtom();376 SecondOtherAtom = World::get ()->createAtom();377 ThirdOtherAtom = World::get ()->createAtom();375 FirstOtherAtom = World::getInstance().createAtom(); 376 SecondOtherAtom = World::getInstance().createAtom(); 377 ThirdOtherAtom = World::getInstance().createAtom(); 378 378 FirstOtherAtom->type = elemente->FindElement(1); 379 379 SecondOtherAtom->type = elemente->FindElement(1); … … 494 494 MDSteps++; 495 495 for(i=0;i<NumberOfAtoms;i++){ 496 Walker = World::get ()->createAtom();496 Walker = World::getInstance().createAtom(); 497 497 getline(xyzfile,line,'\n'); 498 498 istringstream *item = new istringstream(line); -
src/molecule_dynamics.cpp
ra77c96 rcd032d 486 486 bool status = true; 487 487 int MaxSteps = configuration.MaxOuterStep; 488 MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::get ());488 MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::getPointer()); 489 489 // Get the Permutation Map by MinimiseConstrainedPotential 490 490 atom **PermutationMap = NULL; … … 506 506 Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl; 507 507 for (int step = 0; step <= MaxSteps; step++) { 508 mol = World::get ()->createMolecule();508 mol = World::getInstance().createMolecule(); 509 509 MoleculePerStep->insert(mol); 510 510 Walker = start; -
src/molecule_fragmentation.cpp
ra77c96 rcd032d 676 676 //if (FragmentationToDo) { // we should always store the fragments again as coordination might have changed slightly without changing bond structure 677 677 // allocate memory for the pointer array and transmorph graphs into full molecular fragments 678 BondFragments = new MoleculeListClass(World::get ());678 BondFragments = new MoleculeListClass(World::getPointer()); 679 679 int k=0; 680 680 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) { … … 927 927 { 928 928 atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList"); 929 molecule *Leaf = World::get ()->createMolecule();929 molecule *Leaf = World::getInstance().createMolecule(); 930 930 931 931 // Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl; -
src/moleculelist.cpp
ra77c96 rcd032d 215 215 // remove src 216 216 ListOfMolecules.remove(srcmol); 217 World::get ()->destroyMolecule(srcmol);217 World::getInstance().destroyMolecule(srcmol); 218 218 return true; 219 219 }; … … 750 750 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration) 751 751 { 752 molecule *mol = World::get ()->createMolecule();752 molecule *mol = World::getInstance().createMolecule(); 753 753 atom *Walker = NULL; 754 754 atom *Advancer = NULL; … … 775 775 } 776 776 // remove the molecule 777 World::get ()->destroyMolecule(*MolRunner);777 World::getInstance().destroyMolecule(*MolRunner); 778 778 ListOfMolecules.erase(MolRunner); 779 779 } … … 797 797 molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules"); 798 798 for (int i=0;i<MolCount;i++) { 799 molecules[i] = World::get ()->createMolecule();799 molecules[i] = World::getInstance().createMolecule(); 800 800 molecules[i]->ActiveFlag = true; 801 801 strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE); … … 895 895 OBSERVE; 896 896 molecule *mol = NULL; 897 mol = World::get ()->createMolecule();897 mol = World::getInstance().createMolecule(); 898 898 insert(mol); 899 899 }; … … 904 904 char filename[MAXSTRINGSIZE]; 905 905 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl; 906 mol = World::get ()->createMolecule();906 mol = World::getInstance().createMolecule(); 907 907 do { 908 908 Log() << Verbose(0) << "Enter file name: "; … … 962 962 mol = *ListRunner; 963 963 ListOfMolecules.erase(ListRunner); 964 World::get ()->destroyMolecule(mol);964 World::getInstance().destroyMolecule(mol); 965 965 break; 966 966 } … … 1009 1009 // remove the leaf itself 1010 1010 if (Leaf != NULL) { 1011 World::get ()->destroyMolecule(Leaf);1011 World::getInstance().destroyMolecule(Leaf); 1012 1012 Leaf = NULL; 1013 1013 } -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
ra77c96 rcd032d 57 57 58 58 // construct periodentafel 59 tafel = World::get ()->getPeriode();59 tafel = World::getInstance().getPeriode(); 60 60 tafel->AddElement(hydrogen); 61 61 62 62 // construct molecule (tetraeder of hydrogens) 63 TestMolecule = World::get ()->createMolecule();64 Walker = World::get ()->createAtom();63 TestMolecule = World::getInstance().createMolecule(); 64 Walker = World::getInstance().createAtom(); 65 65 Walker->type = hydrogen; 66 66 Walker->node->Init(1., 0., 1. ); 67 67 TestMolecule->AddAtom(Walker); 68 Walker = World::get ()->createAtom();68 Walker = World::getInstance().createAtom(); 69 69 Walker->type = hydrogen; 70 70 Walker->node->Init(0., 1., 1. ); 71 71 TestMolecule->AddAtom(Walker); 72 Walker = World::get ()->createAtom();72 Walker = World::getInstance().createAtom(); 73 73 Walker->type = hydrogen; 74 74 Walker->node->Init(1., 1., 0. ); 75 75 TestMolecule->AddAtom(Walker); 76 Walker = World::get ()->createAtom();76 Walker = World::getInstance().createAtom(); 77 77 Walker->type = hydrogen; 78 78 Walker->node->Init(0., 0., 0. ); … … 82 82 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 83 83 84 TestList = World::get ()->getMolecules();84 TestList = World::getInstance().getMolecules(); 85 85 TestMolecule->ActiveFlag = true; 86 86 TestList->insert(TestMolecule); … … 104 104 105 105 delete(point); 106 World:: destroy();106 World::purgeInstance(); 107 107 MemoryUsageObserver::purgeInstance(); 108 108 logger::purgeInstance(); -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
ra77c96 rcd032d 61 61 62 62 // construct periodentafel 63 tafel = World::get ()->getPeriode();63 tafel = World::getInstance().getPeriode(); 64 64 tafel->AddElement(hydrogen); 65 65 tafel->AddElement(carbon); 66 66 67 67 // construct molecule (tetraeder of hydrogens) base 68 TestMolecule = World::get ()->createMolecule();69 Walker = World::get ()->createAtom();68 TestMolecule = World::getInstance().createMolecule(); 69 Walker = World::getInstance().createAtom(); 70 70 Walker->type = hydrogen; 71 71 Walker->node->Init(1., 0., 1. ); 72 72 TestMolecule->AddAtom(Walker); 73 Walker = World::get ()->createAtom();73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 75 Walker->node->Init(0., 1., 1. ); 76 76 TestMolecule->AddAtom(Walker); 77 Walker = World::get ()->createAtom();77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 79 Walker->node->Init(1., 1., 0. ); 80 80 TestMolecule->AddAtom(Walker); 81 Walker = World::get ()->createAtom();81 Walker = World::getInstance().createAtom(); 82 82 Walker->type = hydrogen; 83 83 Walker->node->Init(0., 0., 0. ); … … 87 87 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 88 88 89 TestList = World::get ()->getMolecules();89 TestList = World::getInstance().getMolecules(); 90 90 TestMolecule->ActiveFlag = true; 91 91 TestList->insert(TestMolecule); … … 100 100 101 101 // add outer atoms 102 Walker = World::get ()->createAtom();102 Walker = World::getInstance().createAtom(); 103 103 Walker->type = carbon; 104 104 Walker->node->Init(4., 0., 4. ); 105 105 TestMolecule->AddAtom(Walker); 106 Walker = World::get ()->createAtom();106 Walker = World::getInstance().createAtom(); 107 107 Walker->type = carbon; 108 108 Walker->node->Init(0., 4., 4. ); 109 109 TestMolecule->AddAtom(Walker); 110 Walker = World::get ()->createAtom();110 Walker = World::getInstance().createAtom(); 111 111 Walker->type = carbon; 112 112 Walker->node->Init(4., 4., 0. ); 113 113 TestMolecule->AddAtom(Walker); 114 114 // add inner atoms 115 Walker = World::get ()->createAtom();115 Walker = World::getInstance().createAtom(); 116 116 Walker->type = carbon; 117 117 Walker->node->Init(0.5, 0.5, 0.5 ); … … 135 135 // note that all the atoms are cleaned by TestMolecule 136 136 delete(LC); 137 World:: destroy();137 World::purgeInstance(); 138 138 MemoryUsageObserver::purgeInstance(); 139 139 logger::purgeInstance(); -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
ra77c96 rcd032d 56 56 57 57 // construct periodentafel 58 tafel = World::get ()->getPeriode();58 tafel = World::getInstance().getPeriode(); 59 59 tafel->AddElement(hydrogen); 60 60 61 61 // construct molecule (tetraeder of hydrogens) 62 TestMolecule = World::get ()->createMolecule();63 Walker = World::get ()->createAtom();62 TestMolecule = World::getInstance().createMolecule(); 63 Walker = World::getInstance().createAtom(); 64 64 Walker->type = hydrogen; 65 65 Walker->node->Init(1., 0., 1. ); 66 66 TestMolecule->AddAtom(Walker); 67 Walker = World::get ()->createAtom();67 Walker = World::getInstance().createAtom(); 68 68 Walker->type = hydrogen; 69 69 Walker->node->Init(0., 1., 1. ); 70 70 TestMolecule->AddAtom(Walker); 71 Walker = World::get ()->createAtom();71 Walker = World::getInstance().createAtom(); 72 72 Walker->type = hydrogen; 73 73 Walker->node->Init(1., 1., 0. ); 74 74 TestMolecule->AddAtom(Walker); 75 Walker = World::get ()->createAtom();75 Walker = World::getInstance().createAtom(); 76 76 Walker->type = hydrogen; 77 77 Walker->node->Init(0., 0., 0. ); … … 81 81 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 82 82 83 TestList = World::get ()->getMolecules();83 TestList = World::getInstance().getMolecules(); 84 84 TestMolecule->ActiveFlag = true; 85 85 TestList->insert(TestMolecule); … … 100 100 101 101 // note that all the atoms are cleaned by TestMolecule 102 World:: destroy();102 World::purgeInstance(); 103 103 MemoryUsageObserver::purgeInstance(); 104 104 logger::purgeInstance(); -
src/unittests/AtomDescriptorTest.cpp
ra77c96 rcd032d 29 29 // set up and tear down 30 30 void AtomDescriptorTest::setUp(){ 31 World::get ();31 World::getInstance(); 32 32 for(int i=0;i<ATOM_COUNT;++i){ 33 atoms[i]= World::get ()->createAtom();33 atoms[i]= World::getInstance().createAtom(); 34 34 atomIds[i]= atoms[i]->getId(); 35 35 } … … 37 37 38 38 void AtomDescriptorTest::tearDown(){ 39 World:: destroy();39 World::purgeInstance(); 40 40 } 41 41 … … 73 73 74 74 void AtomDescriptorTest::AtomBaseSetsTest(){ 75 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());75 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 76 76 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds)); 77 77 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms)); 78 78 79 std::vector<atom*> noAtoms = World::get ()->getAllAtoms(NoAtoms());79 std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms()); 80 80 CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty()); 81 81 } … … 83 83 // test Atoms from boundaries and middle of the set 84 84 atom* testAtom; 85 testAtom = World::get ()->getAtom(AtomById(atomIds[0]));85 testAtom = World::getInstance().getAtom(AtomById(atomIds[0])); 86 86 CPPUNIT_ASSERT(testAtom); 87 87 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId()); 88 testAtom = World::get ()->getAtom(AtomById(atomIds[ATOM_COUNT/2]));88 testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT/2])); 89 89 CPPUNIT_ASSERT(testAtom); 90 90 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId()); 91 testAtom = World::get ()->getAtom(AtomById(atomIds[ATOM_COUNT-1]));91 testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT-1])); 92 92 CPPUNIT_ASSERT(testAtom); 93 93 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId()); … … 103 103 } 104 104 // test from outside of set 105 testAtom = World::get ()->getAtom(AtomById(outsideId));105 testAtom = World::getInstance().getAtom(AtomById(outsideId)); 106 106 CPPUNIT_ASSERT(!testAtom); 107 107 } … … 109 109 // test some elementary set operations 110 110 { 111 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(AllAtoms()||NoAtoms());111 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms()); 112 112 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 113 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); … … 115 115 116 116 { 117 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(NoAtoms()||AllAtoms());117 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms()); 118 118 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 119 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); … … 121 121 122 122 { 123 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(NoAtoms()&&AllAtoms());123 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms()); 124 124 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty()); 125 125 } 126 126 127 127 { 128 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(AllAtoms()&&NoAtoms());128 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms()); 129 129 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty()); 130 130 } 131 131 132 132 { 133 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(!AllAtoms());133 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms()); 134 134 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty()); 135 135 } 136 136 137 137 { 138 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(!NoAtoms());138 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms()); 139 139 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 140 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); … … 143 143 // exclude and include some atoms 144 144 { 145 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));145 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2]))); 146 146 std::set<atomId_t> excluded; 147 147 excluded.insert(atomIds[ATOM_COUNT/2]); … … 152 152 153 153 { 154 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));154 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2]))); 155 155 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 156 156 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId()); -
src/unittests/Makefile.am
ra77c96 rcd032d 29 29 MoleculeDescriptorTest \ 30 30 ObserverTest \ 31 SingletonTest \ 31 32 StackClassUnitTest \ 32 33 TesselationUnitTest \ … … 66 67 MoleculeDescriptorTest.cpp \ 67 68 ObserverTest.cpp \ 69 SingletonTest.cpp \ 68 70 stackclassunittest.cpp \ 69 71 tesselationunittest.cpp \ … … 123 125 MoleculeDescriptorTest_LDADD = ${ALLLIBS} 124 126 127 SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp 128 SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB} 129 125 130 StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp 126 131 StackClassUnitTest_LDADD = ${ALLLIBS} -
src/unittests/MoleculeDescriptorTest.cpp
ra77c96 rcd032d 29 29 // set up and tear down 30 30 void MoleculeDescriptorTest::setUp(){ 31 World::get ();31 World::getInstance(); 32 32 for(int i=0;i<MOLECULE_COUNT;++i){ 33 molecules[i]= World::get ()->createMolecule();33 molecules[i]= World::getInstance().createMolecule(); 34 34 moleculeIds[i]= molecules[i]->getId(); 35 35 } … … 37 37 38 38 void MoleculeDescriptorTest::tearDown(){ 39 World:: destroy();39 World::purgeInstance(); 40 40 } 41 41 … … 73 73 74 74 void MoleculeDescriptorTest::MoleculeBaseSetsTest(){ 75 std::vector<molecule*> allMolecules = World::get ()->getAllMolecules(AllMolecules());75 std::vector<molecule*> allMolecules = World::getInstance().getAllMolecules(AllMolecules()); 76 76 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(allMolecules,moleculeIds)); 77 77 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(allMolecules)); 78 78 79 std::vector<molecule*> noMolecules = World::get ()->getAllMolecules(NoMolecules());79 std::vector<molecule*> noMolecules = World::getInstance().getAllMolecules(NoMolecules()); 80 80 CPPUNIT_ASSERT_EQUAL( true , noMolecules.empty()); 81 81 } … … 83 83 // test Molecules from boundaries and middle of the set 84 84 molecule* testMolecule; 85 testMolecule = World::get ()->getMolecule(MoleculeById(moleculeIds[0]));85 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[0])); 86 86 CPPUNIT_ASSERT(testMolecule); 87 87 CPPUNIT_ASSERT_EQUAL( moleculeIds[0], testMolecule->getId()); 88 testMolecule = World::get ()->getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2]));88 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2])); 89 89 CPPUNIT_ASSERT(testMolecule); 90 90 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecule->getId()); 91 testMolecule = World::get ()->getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1]));91 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1])); 92 92 CPPUNIT_ASSERT(testMolecule); 93 93 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT-1], testMolecule->getId()); … … 103 103 } 104 104 // test from outside of set 105 testMolecule = World::get ()->getMolecule(MoleculeById(outsideId));105 testMolecule = World::getInstance().getMolecule(MoleculeById(outsideId)); 106 106 CPPUNIT_ASSERT(!testMolecule); 107 107 } … … 109 109 // test some elementary set operations 110 110 { 111 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(AllMolecules()||NoMolecules());111 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()||NoMolecules()); 112 112 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds)); 113 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules)); … … 115 115 116 116 { 117 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(NoMolecules()||AllMolecules());117 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||AllMolecules()); 118 118 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds)); 119 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules)); … … 121 121 122 122 { 123 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(NoMolecules()&&AllMolecules());123 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()&&AllMolecules()); 124 124 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty()); 125 125 } 126 126 127 127 { 128 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(AllMolecules()&&NoMolecules());128 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&NoMolecules()); 129 129 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty()); 130 130 } 131 131 132 132 { 133 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(!AllMolecules());133 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!AllMolecules()); 134 134 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty()); 135 135 } 136 136 137 137 { 138 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(!NoMolecules());138 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!NoMolecules()); 139 139 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds)); 140 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules)); … … 143 143 // exclude and include some molecules 144 144 { 145 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2])));145 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2]))); 146 146 std::set<moleculeId_t> excluded; 147 147 excluded.insert(moleculeIds[MOLECULE_COUNT/2]); … … 152 152 153 153 { 154 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2])));154 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2]))); 155 155 CPPUNIT_ASSERT_EQUAL( (size_t)1, testMolecules.size()); 156 156 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecules[0]->getId()); -
src/unittests/analysisbondsunittest.cpp
ra77c96 rcd032d 61 61 62 62 // construct periodentafel 63 tafel = World::get ()->getPeriode();63 tafel = World::getInstance().getPeriode(); 64 64 tafel->AddElement(hydrogen); 65 65 tafel->AddElement(carbon); 66 66 67 67 // construct molecule (tetraeder of hydrogens) 68 TestMolecule = World::get ()->createMolecule();69 Walker = World::get ()->createAtom();68 TestMolecule = World::getInstance().createMolecule(); 69 Walker = World::getInstance().createAtom(); 70 70 Walker->type = hydrogen; 71 71 Walker->node->Init(1.5, 0., 1.5 ); 72 72 TestMolecule->AddAtom(Walker); 73 Walker = World::get ()->createAtom();73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 75 Walker->node->Init(0., 1.5, 1.5 ); 76 76 TestMolecule->AddAtom(Walker); 77 Walker = World::get ()->createAtom();77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 79 Walker->node->Init(1.5, 1.5, 0. ); 80 80 TestMolecule->AddAtom(Walker); 81 Walker = World::get ()->createAtom();81 Walker = World::getInstance().createAtom(); 82 82 Walker->type = hydrogen; 83 83 Walker->node->Init(0., 0., 0. ); 84 84 TestMolecule->AddAtom(Walker); 85 Walker = World::get ()->createAtom();85 Walker = World::getInstance().createAtom(); 86 86 Walker->type = carbon; 87 87 Walker->node->Init(0.5, 0.5, 0.5 ); … … 117 117 118 118 // remove molecule 119 World::get ()->destroyMolecule(TestMolecule);119 World::getInstance().destroyMolecule(TestMolecule); 120 120 // note that all the atoms are cleaned by TestMolecule 121 World:: destroy();121 World::purgeInstance(); 122 122 }; 123 123 -
src/unittests/atomsCalculationTest.cpp
ra77c96 rcd032d 23 23 #include "World_calculations.hpp" 24 24 #include "atom.hpp" 25 26 #ifdef HAVE_TESTRUNNER 27 #include "UnitTestMain.hpp" 28 #endif /*HAVE_TESTRUNNER*/ 25 29 26 30 // Registers the fixture into the 'registry' … … 51 55 // set up and tear down 52 56 void atomsCalculationTest::setUp(){ 53 World::get ();57 World::getInstance(); 54 58 for(int i=0;i<ATOM_COUNT;++i){ 55 59 atoms[i]= new AtomStub(i); 56 World::get ()->registerAtom(atoms[i]);60 World::getInstance().registerAtom(atoms[i]); 57 61 } 58 62 } 59 63 void atomsCalculationTest::tearDown(){ 60 World:: destroy();61 ActionRegistry::purge Registry();64 World::purgeInstance(); 65 ActionRegistry::purgeInstance(); 62 66 } 63 67 … … 92 96 } 93 97 94 static void operation(atom* _atom){95 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);96 assert(atom);97 atom->doSomething();98 }99 100 101 98 void atomsCalculationTest::testCalculateSimple(){ 102 AtomsCalculation<int> *calc = World::get ()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());99 AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms()); 103 100 std::vector<int> allIds = (*calc)(); 104 101 CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT)); … … 108 105 void atomsCalculationTest::testCalculateExcluded(){ 109 106 int excluded = ATOM_COUNT/2; 110 AtomsCalculation<int> *calc = World::get ()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));107 AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded)); 111 108 std::vector<int> allIds = (*calc)(); 112 109 std::set<int> excluded_set; -
src/unittests/bondgraphunittest.cpp
ra77c96 rcd032d 57 57 58 58 // construct periodentafel 59 tafel = World::get ()->getPeriode();59 tafel = World::getInstance().getPeriode(); 60 60 tafel->AddElement(hydrogen); 61 61 tafel->AddElement(carbon); 62 62 63 63 // construct molecule (tetraeder of hydrogens) 64 TestMolecule = World::get ()->createMolecule();65 Walker = World::get ()->createAtom();64 TestMolecule = World::getInstance().createMolecule(); 65 Walker = World::getInstance().createAtom(); 66 66 Walker->type = hydrogen; 67 67 Walker->node->Init(1., 0., 1. ); 68 68 TestMolecule->AddAtom(Walker); 69 Walker = World::get ()->createAtom();69 Walker = World::getInstance().createAtom(); 70 70 Walker->type = hydrogen; 71 71 Walker->node->Init(0., 1., 1. ); 72 72 TestMolecule->AddAtom(Walker); 73 Walker = World::get ()->createAtom();73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 75 Walker->node->Init(1., 1., 0. ); 76 76 TestMolecule->AddAtom(Walker); 77 Walker = World::get ()->createAtom();77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 79 Walker->node->Init(0., 0., 0. ); … … 102 102 103 103 // remove molecule 104 World::get ()->destroyMolecule(TestMolecule);104 World::getInstance().destroyMolecule(TestMolecule); 105 105 // note that all the atoms, molecules, the tafel and the elements 106 106 // are all cleaned when the world is destroyed 107 World:: destroy();107 World::purgeInstance(); 108 108 MemoryUsageObserver::purgeInstance(); 109 109 logger::purgeInstance(); -
src/unittests/listofbondsunittest.cpp
ra77c96 rcd032d 51 51 52 52 // construct periodentafel 53 tafel = World::get ()->getPeriode();53 tafel = World::getInstance().getPeriode(); 54 54 tafel->AddElement(hydrogen); 55 55 56 56 // construct molecule (tetraeder of hydrogens) 57 TestMolecule = World::get ()->createMolecule();58 Walker = World::get ()->createAtom();57 TestMolecule = World::getInstance().createMolecule(); 58 Walker = World::getInstance().createAtom(); 59 59 Walker->type = hydrogen; 60 60 Walker->node->Init(1., 0., 1. ); 61 61 TestMolecule->AddAtom(Walker); 62 Walker = World::get ()->createAtom();62 Walker = World::getInstance().createAtom(); 63 63 Walker->type = hydrogen; 64 64 Walker->node->Init(0., 1., 1. ); 65 65 TestMolecule->AddAtom(Walker); 66 Walker = World::get ()->createAtom();66 Walker = World::getInstance().createAtom(); 67 67 Walker->type = hydrogen; 68 68 Walker->node->Init(1., 1., 0. ); 69 69 TestMolecule->AddAtom(Walker); 70 Walker = World::get ()->createAtom();70 Walker = World::getInstance().createAtom(); 71 71 Walker->type = hydrogen; 72 72 Walker->node->Init(0., 0., 0. ); … … 82 82 { 83 83 // remove 84 World::get ()->destroyMolecule(TestMolecule);84 World::getInstance().destroyMolecule(TestMolecule); 85 85 // note that all the atoms, molecules, the tafel and the elements 86 86 // are all cleaned when the world is destroyed 87 World:: destroy();87 World::purgeInstance(); 88 88 MemoryUsageObserver::purgeInstance(); 89 89 logger::purgeInstance(); … … 250 250 251 251 // remove atom2 252 World::get ()->destroyAtom(atom2);252 World::getInstance().destroyAtom(atom2); 253 253 254 254 // check bond if removed from other atom -
src/unittests/logunittest.cpp
ra77c96 rcd032d 40 40 void LogTest::logTest() 41 41 { 42 logger::getInstance() ->setVerbosity(2);42 logger::getInstance().setVerbosity(2); 43 43 Log() << Verbose(0) << "Verbosity level is set to 2." << endl; 44 44 Log() << Verbose(0) << "Test level 0" << endl; -
src/unittests/manipulateAtomsTest.cpp
ra77c96 rcd032d 22 22 #include "atom.hpp" 23 23 24 #ifdef HAVE_TESTRUNNER 25 #include "UnitTestMain.hpp" 26 #endif /*HAVE_TESTRUNNER*/ 27 24 28 // Registers the fixture into the 'registry' 25 29 CPPUNIT_TEST_SUITE_REGISTRATION( manipulateAtomsTest ); … … 30 34 AtomStub(int _id) : 31 35 atom(), 32 id(_id),33 manipulated(false)36 manipulated(false), 37 id(_id) 34 38 {} 35 39 … … 66 70 // set up and tear down 67 71 void manipulateAtomsTest::setUp(){ 68 World::get ();72 World::getInstance(); 69 73 for(int i=0;i<ATOM_COUNT;++i){ 70 74 atoms[i]= new AtomStub(i); 71 World::get ()->registerAtom(atoms[i]);75 World::getInstance().registerAtom(atoms[i]); 72 76 } 73 77 } 74 78 void manipulateAtomsTest::tearDown(){ 75 World::destroy(); 76 ActionRegistry::purgeRegistry(); 77 } 78 79 // some helper functions 80 static bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){ 81 for(int i=min;i<max;++i){ 82 if(!excluded.count(i)){ 83 std::vector<atom*>::iterator iter; 84 bool res=false; 85 for(iter=atoms.begin();iter!=atoms.end();++iter){ 86 res |= (*iter)->getId() == i; 87 } 88 if(!res) { 89 cout << "Atom " << i << " missing in returned list" << endl; 90 return false; 91 } 92 } 93 } 94 return true; 95 } 96 97 static bool hasNoDuplicates(std::vector<atom*> atoms){ 98 std::set<int> found; 99 std::vector<atom*>::iterator iter; 100 for(iter=atoms.begin();iter!=atoms.end();++iter){ 101 int id = (*iter)->getId(); 102 if(found.count(id)) 103 return false; 104 found.insert(id); 105 } 106 return true; 79 World::purgeInstance(); 80 ActionRegistry::purgeInstance(); 107 81 } 108 82 … … 115 89 116 90 void manipulateAtomsTest::testManipulateSimple(){ 117 ManipulateAtomsProcess *proc = World::get ()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());91 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms()); 118 92 proc->call(); 119 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());93 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 120 94 std::vector<atom*>::iterator iter; 121 95 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){ … … 128 102 129 103 void manipulateAtomsTest::testManipulateExcluded(){ 130 ManipulateAtomsProcess *proc = World::get ()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));104 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2)); 131 105 proc->call(); 132 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());106 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 133 107 std::vector<atom*>::iterator iter; 134 108 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){ … … 145 119 void manipulateAtomsTest::testObserver(){ 146 120 countObserver *obs = new countObserver(); 147 World::get ()->signOn(obs);148 ManipulateAtomsProcess *proc = World::get ()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));121 World::getInstance().signOn(obs); 122 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2)); 149 123 proc->call(); 150 124 151 125 CPPUNIT_ASSERT_EQUAL(1,obs->count); 152 World::get ()->signOff(obs);126 World::getInstance().signOff(obs); 153 127 delete obs; 154 128 }
Note:
See TracChangeset
for help on using the changeset viewer.