Changes in / [9131f3:4415da]
- Files:
-
- 13 added
- 1 deleted
- 95 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/Doxyfile
r9131f3 r4415da 127 127 #--------------------------------------------------------------------------- 128 128 SOURCE_BROWSER = YES 129 INLINE_SOURCES = NO130 STRIP_CODE_COMMENTS = YES129 INLINE_SOURCES = YES 130 STRIP_CODE_COMMENTS = NO 131 131 REFERENCED_BY_RELATION = NO 132 132 REFERENCES_RELATION = NO -
src/Actions/Action.cpp
r9131f3 r4415da 10 10 #include "Actions/Action.hpp" 11 11 #include "Actions/ActionRegistry.hpp" 12 #include "Actions/ActionHistory.hpp" 12 13 13 14 using namespace std; 15 16 // An empty state to indicate success 17 Action::state_ptr Action::success = Action::state_ptr(new ActionState()); 18 Action::state_ptr Action::failure = Action::state_ptr(new ActionState()); 14 19 15 20 Action::Action(std::string _name,bool _doRegister) : … … 17 22 { 18 23 if(_doRegister){ 19 ActionRegistry::get Registry()->registerAction(this);24 ActionRegistry::getInstance().registerAction(this); 20 25 } 21 26 } … … 27 32 return name; 28 33 } 34 35 void Action::call(){ 36 // forward to private virtual 37 state_ptr state = performCall(); 38 if(shouldUndo() && state != failure){ 39 if(canUndo()){ 40 ActionHistory::getInstance().addElement(this,state); 41 } 42 else{ 43 ActionHistory::getInstance().clear(); 44 } 45 } 46 } 47 Action::state_ptr Action::undo(state_ptr _state) { 48 // forward to private virtual 49 return performUndo(_state); 50 } 51 Action::state_ptr Action::redo(state_ptr _state) { 52 // forward to private virtual 53 return performRedo(_state); 54 } 55 56 57 bool Action::isActive(){ 58 return true; 59 } -
src/Actions/Action.hpp
r9131f3 r4415da 10 10 11 11 #include <string> 12 #include <boost/shared_ptr.hpp> 13 14 // forward declaration 15 16 class ActionState; 17 class ActionSequence; 12 18 13 19 /** … … 21 27 class Action 22 28 { 23 protected: 29 friend class ActionSequence; 24 30 public: 31 32 typedef boost::shared_ptr<ActionState> state_ptr; 33 25 34 Action(std::string _name,bool _doRegister=true); 26 35 virtual ~Action(); 27 36 28 virtual void call()=0; 29 virtual void undo()=0; 37 // this method only handles the infrastructure 38 // actuall action is passed on to a private virtual 39 void call(); 40 state_ptr undo(state_ptr); 41 state_ptr redo(state_ptr); 42 30 43 virtual bool canUndo()=0; 31 //virtual bool shouldUndo()=0; 44 virtual bool shouldUndo()=0; 45 46 virtual bool isActive(); 32 47 33 48 virtual const std::string getName(); 34 49 50 protected: 51 static state_ptr success; 52 static state_ptr failure; 53 35 54 private: 55 virtual state_ptr performCall()=0; 56 virtual state_ptr performUndo(state_ptr)=0; 57 virtual state_ptr performRedo(state_ptr)=0; 58 36 59 std::string name; 37 60 }; 38 61 62 /** 63 * This class can be used by actions to save the state. 64 * 65 * It is implementing a memento pattern. The base class is completely empty, 66 * since no general state internals can be given. The Action performing 67 * the Undo should downcast to the apropriate type. 68 */ 69 class ActionState{ 70 public: 71 ActionState(){} 72 virtual ~ActionState(){} 73 }; 74 39 75 #endif /* ACTION_H_ */ -
src/Actions/ActionRegistry.cpp
r9131f3 r4415da 9 9 #include "Actions/Action.hpp" 10 10 11 #include "Patterns/Singleton_impl.hpp" 12 11 13 #include <string> 12 #include <cassert>14 #include "Helpers/Assert.hpp" 13 15 #include <iostream> 14 16 15 17 using namespace std; 16 17 ActionRegistry *ActionRegistry::theInstance=0;18 18 19 19 ActionRegistry::ActionRegistry() … … 33 33 map<const string,Action*>::iterator iter; 34 34 iter = actionMap.find(name); 35 assert(iter!=actionMap.end() &&"Query for an action not stored in registry");35 ASSERT(iter!=actionMap.end(),"Query for an action not stored in registry"); 36 36 return iter->second; 37 37 } … … 40 40 pair<map<const string,Action*>::iterator,bool> ret; 41 41 ret = actionMap.insert(pair<const string,Action*>(action->getName(),action)); 42 assert(ret.second &&"Two actions with the same name added to registry");42 ASSERT(ret.second,"Two actions with the same name added to registry"); 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
r9131f3 r4415da 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/ActionSequence.cpp
r9131f3 r4415da 8 8 #include "Actions/ActionSequence.hpp" 9 9 #include "Actions/Action.hpp" 10 11 #include "Helpers/Assert.hpp" 10 12 11 13 using namespace std; … … 34 36 } 35 37 36 void ActionSequence::callAll(){ 37 deque<Action*>::iterator it; 38 for(it=actions.begin(); it!=actions.end(); it++) 39 (*it)->call(); 38 ActionSequence::stateSet ActionSequence::callAll(){ 39 stateSet states; 40 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){ 41 // we want to have a global bookkeeping for all actions in the sequence, so 42 // we bypass the normal call 43 Action::state_ptr state = (*it)->performCall(); 44 states.push_back(state); 45 } 46 return states; 40 47 } 41 48 42 void ActionSequence::undoAll(){ 43 deque<Action*>::reverse_iterator rit; 44 for(rit=actions.rbegin(); rit!=actions.rend(); rit++) 45 (*rit)->undo(); 49 ActionSequence::stateSet ActionSequence::undoAll(stateSet states){ 50 ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone"); 51 stateSet res; 52 actionSet::reverse_iterator actionRit = actions.rbegin(); 53 stateSet::reverse_iterator stateRit = states.rbegin(); 54 for(;actionRit!=actions.rend();++actionRit,++stateRit){ 55 ASSERT(stateRit!=states.rend(),"End of states prematurely reached."); 56 if((*actionRit)->shouldUndo()){ 57 Action::state_ptr newState = (*actionRit)->performUndo(*stateRit); 58 // The order of the states has to correspond to the order of the actions 59 // this is why we have to add at the beginning 60 res.push_front(newState); 61 } 62 else{ 63 res.push_front(Action::success); 64 } 65 } 66 return res; 67 } 68 69 ActionSequence::stateSet ActionSequence::redoAll(stateSet states){ 70 stateSet res; 71 actionSet::iterator actionIt = actions.begin(); 72 stateSet::iterator stateIt = states.begin(); 73 for(;actionIt!=actions.end();++actionIt,++stateIt){ 74 ASSERT(stateIt!=states.end(),"End of states prematurely reached."); 75 if((*actionIt)->shouldUndo()){ 76 Action::state_ptr newState =(*actionIt)->performRedo(*stateIt); 77 res.push_back(newState); 78 } 79 else{ 80 res.push_back(Action::success); 81 } 82 } 83 return res; 46 84 } 47 85 48 86 bool ActionSequence::canUndo(){ 49 87 bool canUndo=true; 50 deque<Action*>::iterator it; 51 for(it=actions.begin(); it!=actions.end(); it++) 52 canUndo &= (*it)->canUndo(); 88 for(deque<Action*>::iterator it=actions.begin(); it!=actions.end(); ++it){ 89 if((*it)->shouldUndo()){ 90 canUndo &= (*it)->canUndo(); 91 } 92 } 53 93 return canUndo; 54 94 } 95 96 bool ActionSequence::shouldUndo(){ 97 bool shouldUndo = false; 98 for(deque<Action*>::iterator it=actions.begin();it!=actions.end();++it){ 99 shouldUndo |= (*it)->shouldUndo(); 100 } 101 return shouldUndo; 102 } -
src/Actions/ActionSequence.hpp
r9131f3 r4415da 9 9 #define ACTIONSEQUENZE_HPP_ 10 10 11 #include "Actions/Action.hpp" 12 11 13 #include <deque> 12 13 class Action;14 14 15 15 /** … … 19 19 { 20 20 public: 21 typedef std::deque<Action*> actionSet; 22 typedef std::deque<Action::state_ptr> stateSet; 23 21 24 ActionSequence(); 22 25 virtual ~ActionSequence(); … … 25 28 Action* removeLastAction(); 26 29 27 void callAll(); 28 void undoAll(); 30 stateSet callAll(); 31 stateSet undoAll(stateSet); 32 stateSet redoAll(stateSet); 29 33 30 34 bool canUndo(); 35 bool shouldUndo(); 31 36 32 37 private: 33 std::deque<Action*>actions;38 actionSet actions; 34 39 }; 35 40 -
src/Actions/AtomsCalculation_impl.hpp
r9131f3 r4415da 19 19 AtomsCalculation<T>::AtomsCalculation(boost::function<T(atom*)> _op,std::string name,AtomDescriptor _descr) : 20 20 Calculation<std::vector<T> >(0,name,false), 21 op(_op),22 descr(_descr)21 descr(_descr), 22 op(_op) 23 23 {} 24 24 … … 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); 36 35 Process::setMaxSteps(steps); 37 36 Process::start(); 38 World::AtomIterator iter; 39 for(iter=world->getAtomIter(descr);iter!=world->atomEnd();++iter){ 37 for(World::AtomIterator iter=world->getAtomIter(descr);iter!=world->atomEnd();++iter){ 40 38 Process::setCurrStep(iter.getCount()); 41 39 res->push_back(op(*iter)); -
src/Actions/Calculation.hpp
r9131f3 r4415da 29 29 * from menu Items or other places. 30 30 */ 31 virtual void call();32 virtual void undo();33 31 virtual bool canUndo(); 32 33 virtual bool shouldUndo(); 34 34 35 35 /** … … 64 64 virtual T* doCalc()=0; 65 65 private: 66 virtual Action::state_ptr performCall(); 67 virtual Action::state_ptr performUndo(Action::state_ptr); 68 virtual Action::state_ptr performRedo(Action::state_ptr); 69 66 70 bool done; 67 71 }; -
src/Actions/Calculation_impl.hpp
r9131f3 r4415da 16 16 Calculation<T>::Calculation(int _maxSteps, std::string _name, bool _doRegister) : 17 17 Process(_maxSteps,_name,_doRegister), 18 done(false),19 result(0)18 result(0), 19 done(false) 20 20 {} 21 21 … … 29 29 30 30 template<typename T> 31 void Calculation<T>::call(){31 Action::state_ptr Calculation<T>::performCall(){ 32 32 reset(); 33 33 (*this)(); 34 return Action::success; 34 35 } 35 36 36 37 template<typename T> 37 void Calculation<T>::undo(){} 38 Action::state_ptr Calculation<T>::performUndo(Action::state_ptr){ 39 ASSERT(0,"Cannot undo a calculation"); 40 return Action::success; 41 } 42 template<typename T> 43 Action::state_ptr Calculation<T>::performRedo(Action::state_ptr){ 44 ASSERT(0,"Cannot redo a calculation"); 45 return Action::success; 46 } 38 47 39 48 template<typename T> 40 49 bool Calculation<T>::canUndo() 50 { 51 return false; 52 } 53 54 template<typename T> 55 bool Calculation<T>::shouldUndo() 41 56 { 42 57 return false; -
src/Actions/ErrorAction.cpp
r9131f3 r4415da 11 11 #include "log.hpp" 12 12 #include "verbose.hpp" 13 #include "Helpers/Assert.hpp" 13 14 14 15 using namespace std; … … 24 25 } 25 26 26 void ErrorAction::call() {27 Action::state_ptr ErrorAction::performCall() { 27 28 Log() << Verbose(0) << errorMsg << endl; 29 return Action::success; 28 30 } 29 void ErrorAction::undo() { 31 Action::state_ptr ErrorAction::performUndo(Action::state_ptr) { 32 ASSERT(0,"Undo called for an ErrorAction"); 33 return Action::success; 34 } 35 36 Action::state_ptr ErrorAction::performRedo(Action::state_ptr) { 37 ASSERT(0,"Redo called for an ErrorAction"); 38 return Action::success; 30 39 } 31 40 … … 33 42 return false; 34 43 } 44 45 bool ErrorAction::shouldUndo(){ 46 return false; 47 } -
src/Actions/ErrorAction.hpp
r9131f3 r4415da 18 18 virtual ~ErrorAction(); 19 19 20 virtual void call();21 virtual void undo();22 20 virtual bool canUndo(); 21 virtual bool shouldUndo(); 23 22 24 23 private: 24 25 virtual Action::state_ptr performCall(); 26 virtual Action::state_ptr performUndo(Action::state_ptr); 27 virtual Action::state_ptr performRedo(Action::state_ptr); 28 25 29 std::string errorMsg; 26 30 }; -
src/Actions/MakroAction.cpp
r9131f3 r4415da 11 11 #include "Actions/Action.hpp" 12 12 #include "Actions/ActionSequence.hpp" 13 #include "Helpers/Assert.hpp" 13 14 14 15 using namespace std; 16 17 class MakroActionState : public ActionState{ 18 public: 19 MakroActionState(ActionSequence::stateSet _states) : 20 states(_states) 21 {} 22 virtual ~MakroActionState(){ 23 // All contained states are destroyed by the shared ptrs 24 } 25 26 ActionSequence::stateSet states; 27 }; 15 28 16 29 MakroAction::MakroAction(string _name,ActionSequence* _actions,bool _doRegister) : … … 30 43 31 44 32 void MakroAction::call(){ 33 actions->callAll(); 45 Action::state_ptr MakroAction::performCall(){ 46 ActionSequence::stateSet states = actions->callAll(); 47 return Action::state_ptr(new MakroActionState(states)); 34 48 } 35 49 36 void MakroAction::undo() { 37 actions->undoAll(); 50 Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) { 51 MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get()); 52 ASSERT(state,"Type mismatch for the state of the MakroAction"); 53 ActionSequence::stateSet states = actions->undoAll(state->states); 54 return Action::state_ptr(new MakroActionState(states)); 55 } 56 57 Action::state_ptr MakroAction::performRedo(Action::state_ptr _state){ 58 MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get()); 59 ASSERT(state,"Type mismatch for the state of the MakroAction"); 60 ActionSequence::stateSet states = actions->redoAll(state->states); 61 return Action::state_ptr(new MakroActionState(states)); 38 62 } 39 63 … … 41 65 return actions->canUndo(); 42 66 } 67 68 bool MakroAction::shouldUndo() { 69 return actions->shouldUndo(); 70 } -
src/Actions/MakroAction.hpp
r9131f3 r4415da 26 26 virtual ~MakroAction(); 27 27 28 virtual void call(); 29 virtual void undo(); 30 virtual bool canUndo(); 28 bool canUndo(); 29 bool shouldUndo(); 31 30 32 31 private: 32 virtual Action::state_ptr performCall(); 33 virtual Action::state_ptr performUndo(Action::state_ptr); 34 virtual Action::state_ptr performRedo(Action::state_ptr); 35 33 36 ActionSequence *actions; 34 37 }; -
src/Actions/ManipulateAtomsProcess.cpp
r9131f3 r4415da 9 9 10 10 #include <iostream> 11 12 #include "World.hpp" 13 #include "Helpers/Assert.hpp" 11 14 12 15 using namespace std; … … 22 25 {} 23 26 24 void ManipulateAtomsProcess::call(){ 25 World::get()->doManipulate(this); 27 Action::state_ptr ManipulateAtomsProcess::performCall(){ 28 World::getInstance().doManipulate(this); 29 return Action::success; 26 30 } 27 31 28 void ManipulateAtomsProcess::undo(){ 32 Action::state_ptr ManipulateAtomsProcess::performUndo(Action::state_ptr){ 33 ASSERT(0,"Undo called for a ManipulateAtomsProcess"); 34 return Action::success; 35 } 29 36 37 Action::state_ptr ManipulateAtomsProcess::performRedo(Action::state_ptr){ 38 ASSERT(0,"Redo called for a ManipulateAtomsProcess"); 39 return Action::success; 30 40 } 31 41 … … 34 44 } 35 45 46 bool ManipulateAtomsProcess::shouldUndo(){ 47 return true; 48 } 49 36 50 void ManipulateAtomsProcess::doManipulate(World *world){ 37 51 setMaxSteps(world->numAtoms()); 38 52 start(); 39 World::AtomIterator iter; 40 for(iter=world->getAtomIter(descr);iter!=world->atomEnd();++iter){ 53 for(World::AtomIterator iter=world->getAtomIter(descr);iter!=world->atomEnd();++iter){ 41 54 setCurrStep(iter.getCount()); 42 55 operation(*iter); -
src/Actions/ManipulateAtomsProcess.hpp
r9131f3 r4415da 10 10 11 11 #include "Actions/Process.hpp" 12 13 #include<boost/function.hpp> 14 12 15 #include "Descriptors/AtomDescriptor.hpp" 16 17 class World; 13 18 14 19 class ManipulateAtomsProcess : public Process … … 18 23 virtual ~ManipulateAtomsProcess(); 19 24 20 virtual void call();21 virtual void undo();22 25 virtual bool canUndo(); 26 virtual bool shouldUndo(); 23 27 24 28 virtual void doManipulate(World *); 25 29 private: 30 31 virtual Action::state_ptr performCall(); 32 virtual Action::state_ptr performUndo(Action::state_ptr); 33 virtual Action::state_ptr performRedo(Action::state_ptr); 34 26 35 AtomDescriptor descr; 27 36 boost::function<void(atom*)> operation; -
src/Actions/MethodAction.cpp
r9131f3 r4415da 10 10 #include <string> 11 11 12 #include "MethodAction.hpp" 12 #include "Actions/MethodAction.hpp" 13 #include "Helpers/Assert.hpp" 13 14 14 15 using namespace std; … … 21 22 22 23 MethodAction::~MethodAction() 23 { 24 // TODO Auto-generated destructor stub 24 {} 25 26 27 Action::state_ptr MethodAction::performCall() { 28 executeMethod(); 29 // we don't have a state to save so we return Action::success 30 return Action::success; 25 31 } 26 32 33 Action::state_ptr MethodAction::performUndo(Action::state_ptr) { 34 ASSERT(0,"Cannot undo a MethodAction"); 35 return Action::success; 36 } 27 37 28 void MethodAction::call() { 29 executeMethod(); 30 } 31 void MethodAction::undo() { 32 38 Action::state_ptr MethodAction::performRedo(Action::state_ptr){ 39 ASSERT(0,"Cannot redo a MethodAction"); 40 return Action::success; 33 41 } 34 42 … … 36 44 return false; 37 45 } 46 47 bool MethodAction::shouldUndo(){ 48 return true; 49 } -
src/Actions/MethodAction.hpp
r9131f3 r4415da 22 22 MethodAction(std::string _name,boost::function<void()> _executeMethod,bool _doRegister=true); 23 23 virtual ~MethodAction(); 24 virtual bool canUndo(); 25 virtual bool shouldUndo(); 24 26 25 virtual void call(); 26 virtual void undo(); 27 virtual bool canUndo(); 27 private: 28 virtual Action::state_ptr performCall(); 29 virtual Action::state_ptr performUndo(Action::state_ptr); 30 virtual Action::state_ptr performRedo(Action::state_ptr); 31 28 32 29 33 boost::function<void()> executeMethod; //!< this stores the method to be called 30 31 32 34 }; 33 35 -
src/Actions/small_actions.cpp
r9131f3 r4415da 14 14 /****** ChangeMoleculeNameAction *****/ 15 15 16 char ChangeMoleculeNameAction::NAME[] = "Change filename of Molecule"; 16 // memento to remember the state when undoing 17 18 class ChangeMoleculeNameState : public ActionState { 19 public: 20 ChangeMoleculeNameState(molecule* _mol,std::string _lastName) : 21 mol(_mol), 22 lastName(_lastName) 23 {} 24 molecule* mol; 25 std::string lastName; 26 }; 27 28 const char ChangeMoleculeNameAction::NAME[] = "Change filename of Molecule"; 17 29 18 30 ChangeMoleculeNameAction::ChangeMoleculeNameAction(MoleculeListClass *_molecules) : … … 24 36 {} 25 37 26 void ChangeMoleculeNameAction::call() {38 Action::state_ptr ChangeMoleculeNameAction::performCall() { 27 39 string filename; 28 40 molecule *mol = NULL; 29 Dialog *dialog = UIFactory::get ()->makeDialog();41 Dialog *dialog = UIFactory::getInstance().makeDialog(); 30 42 31 43 dialog->queryMolecule("Enter index of molecule: ",&mol,molecules); 32 44 dialog->queryString("Enter name: ",&filename); 45 33 46 if(dialog->display()) { 47 string oldName = mol->getName(); 34 48 mol->setName(filename); 49 delete dialog; 50 return Action::state_ptr(new ChangeMoleculeNameState(mol,oldName)); 35 51 } 36 37 52 delete dialog; 53 return Action::failure; 38 54 } 39 55 40 void ChangeMoleculeNameAction::undo() { 56 Action::state_ptr ChangeMoleculeNameAction::performUndo(Action::state_ptr _state) { 57 ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state.get()); 58 ASSERT(state,"State passed to ChangeMoleculeNameAction::performUndo did not have correct type"); 41 59 60 string newName = state->mol->getName(); 61 state->mol->setName(state->lastName); 62 63 return Action::state_ptr(new ChangeMoleculeNameState(state->mol,newName)); 64 } 65 66 Action::state_ptr ChangeMoleculeNameAction::performRedo(Action::state_ptr _state){ 67 // Undo and redo have to do the same for this action 68 return performUndo(_state); 42 69 } 43 70 44 71 bool ChangeMoleculeNameAction::canUndo() { 45 return false;72 return true; 46 73 } 47 74 -
src/Actions/small_actions.hpp
r9131f3 r4415da 14 14 virtual ~ChangeMoleculeNameAction(); 15 15 16 void call();17 void undo();18 16 bool canUndo(); 19 17 bool shouldUndo(); … … 21 19 virtual const std::string getName(); 22 20 private: 21 virtual Action::state_ptr performCall(); 22 virtual Action::state_ptr performUndo(Action::state_ptr); 23 virtual Action::state_ptr performRedo(Action::state_ptr); 24 23 25 MoleculeListClass *molecules; 24 static c har NAME[];26 static const char NAME[]; 25 27 }; 26 28 -
src/Descriptors/AtomDescriptor.cpp
r9131f3 r4415da 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/AtomDescriptor.hpp
r9131f3 r4415da 36 36 friend atom* World::getAtom(AtomDescriptor descriptor); 37 37 friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor); 38 friend class World::AtomIterator;38 template <class,class,class> friend class SelectiveIterator; 39 39 40 40 friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs); -
src/Descriptors/AtomTypeDescriptor.cpp
r9131f3 r4415da 13 13 #include "periodentafel.hpp" 14 14 15 AtomTypeDescriptor_impl::AtomTypeDescriptor_impl( element* _type) :15 AtomTypeDescriptor_impl::AtomTypeDescriptor_impl(const element* _type) : 16 16 type(_type) 17 17 {} … … 24 24 } 25 25 26 AtomDescriptor AtomByType( element *elem){26 AtomDescriptor AtomByType(const element *elem){ 27 27 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomTypeDescriptor_impl(elem))); 28 28 } 29 29 30 30 AtomDescriptor AtomByType(int Z){ 31 element * elem = World::get()->getPeriode()->FindElement(Z);31 const element * elem = World::getInstance().getPeriode()->FindElement(Z); 32 32 return AtomByType(elem); 33 33 } -
src/Descriptors/AtomTypeDescriptor.hpp
r9131f3 r4415da 13 13 class element; 14 14 15 AtomDescriptor AtomByType( element *);15 AtomDescriptor AtomByType(const element *); 16 16 AtomDescriptor AtomByType(int); 17 17 -
src/Descriptors/AtomTypeDescriptor_impl.hpp
r9131f3 r4415da 14 14 { 15 15 public: 16 AtomTypeDescriptor_impl( element* _type);16 AtomTypeDescriptor_impl(const element* _type); 17 17 virtual ~AtomTypeDescriptor_impl(); 18 18 19 19 bool predicate(std::pair<atomId_t,atom*> atom); 20 20 private: 21 element *type;21 const element * const type; 22 22 }; 23 23 -
src/Descriptors/MoleculeDescriptor.cpp
r9131f3 r4415da 68 68 69 69 World::MoleculeSet& MoleculeDescriptor_impl::getMolecules(){ 70 return World::get ()->molecules;70 return World::getInstance().molecules; 71 71 } 72 72 -
src/Descriptors/MoleculeDescriptor.hpp
r9131f3 r4415da 36 36 friend molecule* World::getMolecule(MoleculeDescriptor descriptor); 37 37 friend std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor); 38 friend class World::MoleculeIterator;38 template <class,class,class> friend class SelectiveIterator; 39 39 40 40 friend MoleculeDescriptor operator&&(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs); … … 43 43 44 44 public: 45 typedef boost::shared_ptr<MoleculeDescriptor_impl> impl_ptr; //!< Allow easy changes of the pointer-to-implementation type 45 typedef MoleculeDescriptor_impl impl_t; 46 typedef boost::shared_ptr<impl_t> impl_ptr; //!< Allow easy changes of the pointer-to-implementation type 46 47 47 48 MoleculeDescriptor(impl_ptr); -
src/Legacy/oldmenu.cpp
r9131f3 r4415da 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 } … … 748 748 int axis,faktor,count,j; 749 749 atom *first = NULL; 750 element **Elements;750 const element **Elements; 751 751 Vector x,y; 752 752 Vector **vectors; … … 764 764 if (mol->AtomCount != 0) { // if there is more than none 765 765 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand 766 Elements = new element *[count];766 Elements = new const element *[count]; 767 767 vectors = new Vector *[count]; 768 768 j = 0; … … 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
r9131f3 r4415da 8 8 ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp 9 9 10 ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ManipulateAtomsProcess.cpp Actions/ActionRegistry.cpp 11 ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/Calculation.hpp Actions/Calculation_impl.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ManipulateAtomsProcess.hpp Actions/ActionRegistry.hpp 10 ACTIONSSOURCE = Actions/Action.cpp \ 11 Actions/ActionHistory.cpp \ 12 Actions/ActionRegistry.cpp \ 13 Actions/ActionSequence.cpp \ 14 Actions/ErrorAction.cpp \ 15 Actions/MakroAction.cpp \ 16 Actions/ManipulateAtomsProcess.cpp \ 17 Actions/MethodAction.cpp \ 18 Actions/Process.cpp \ 19 Actions/small_actions.cpp 20 21 22 ACTIONSHEADER = Actions/Action.hpp \ 23 Actions/ActionHistory.hpp \ 24 Actions/ActionRegistry.hpp \ 25 Actions/ActionSequence.hpp \ 26 Actions/Calculation.hpp \ 27 Actions/Calculation_impl.hpp \ 28 Actions/ErrorAction.hpp \ 29 Actions/MakroAction.hpp \ 30 Actions/ManipulateAtomsProcess.hpp \ 31 Actions/MethodAction.hpp \ 32 Actions/Process.hpp \ 33 Actions/small_actions.hpp 34 35 12 36 13 37 PARSERSOURCE = Parser/ChangeTracker.cpp Parser/FormatParser.cpp Parser/TremoloParser.cpp Parser/XyzParser.cpp … … 15 39 16 40 PATTERNSOURCE = Patterns/Observer.cpp 17 PATTERNHEADER = Patterns/Observer.hpp Patterns/Cacheable.hpp 41 PATTERNHEADER = Patterns/Cacheable.hpp \ 42 Patterns/Observer.hpp \ 43 Patterns/Singleton.hpp 18 44 19 45 VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp … … 36 62 Descriptors/AtomTypeDescriptor.cpp \ 37 63 Descriptors/MoleculeDescriptor.cpp \ 38 Descriptors/MoleculeIdDescriptor.cpp 64 Descriptors/MoleculeIdDescriptor.cpp 65 39 66 40 67 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \ … … 43 70 Descriptors/MoleculeDescriptor.hpp \ 44 71 Descriptors/MoleculeIdDescriptor.hpp 72 45 73 46 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PARSERSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp lists.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp WorldIterators.cpp 47 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PARSERHEADER} ${PATTERNHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp 74 75 SOURCE = ${ANALYSISSOURCE} \ 76 ${ATOMSOURCE} \ 77 ${PATTERNSOURCE} \ 78 ${PARSERSOURCE} \ 79 ${UISOURCE} \ 80 ${DESCRIPTORSOURCE} \ 81 ${LEGACYSOURCE} \ 82 bond.cpp \ 83 bondgraph.cpp \ 84 boundary.cpp \ 85 config.cpp \ 86 element.cpp \ 87 ellipsoid.cpp \ 88 errorlogger.cpp \ 89 graph.cpp \ 90 helpers.cpp \ 91 Helpers/Assert.cpp \ 92 info.cpp \ 93 leastsquaremin.cpp \ 94 linkedcell.cpp \ 95 lists.cpp \ 96 log.cpp \ 97 logger.cpp \ 98 memoryusageobserver.cpp \ 99 moleculelist.cpp \ 100 molecule.cpp \ 101 molecule_dynamics.cpp \ 102 molecule_fragmentation.cpp \ 103 molecule_geometry.cpp \ 104 molecule_graph.cpp \ 105 molecule_pointcloud.cpp \ 106 parser.cpp \ 107 periodentafel.cpp \ 108 tesselation.cpp \ 109 tesselationhelpers.cpp \ 110 vector.cpp \ 111 verbose.cpp \ 112 World.cpp 113 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${PARSERHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp 48 114 49 115 BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB) -
src/Menu/ActionMenuItem.cpp
r9131f3 r4415da 20 20 21 21 ActionMenuItem::~ActionMenuItem() 22 { 23 // TODO Auto-generated destructor stub 24 } 22 {} 25 23 26 24 void ActionMenuItem::doTrigger() { 27 25 action->call(); 28 26 } 27 28 bool ActionMenuItem::isActive() { 29 return action->isActive(); 30 } -
src/Menu/ActionMenuItem.hpp
r9131f3 r4415da 26 26 virtual void doTrigger(); 27 27 28 virtual bool isActive(); 29 28 30 private: 29 31 Action* action; //!< this action will be called when the trigger matches -
src/Menu/MenuItem.cpp
r9131f3 r4415da 78 78 return added; 79 79 } 80 81 bool MenuItem::isActive(){ 82 return true; 83 } -
src/Menu/MenuItem.hpp
r9131f3 r4415da 21 21 */ 22 22 class MenuItem { 23 private:24 char trigger;25 string *description;26 bool added;27 28 23 public: 29 24 MenuItem(char,const char*,Menu*); … … 41 36 bool wasAdded(); 42 37 38 virtual bool isActive(); 39 43 40 protected: 44 41 void setDescription(string); 42 43 private: 44 char trigger; 45 string *description; 46 bool added; 45 47 }; 46 48 -
src/Menu/TextMenu.cpp
r9131f3 r4415da 11 11 #include "Menu/TextMenu.hpp" 12 12 #include "Menu/MenuItem.hpp" 13 #include "Helpers/Assert.hpp" 13 14 14 15 … … 51 52 52 53 void TextMenu::showEntry(MenuItem* entry){ 53 outputter << entry->formatEntry() << "\n"; 54 if(entry->isActive()==false){ 55 outputter << "("; 56 } 57 outputter << entry->formatEntry(); 58 if(entry->isActive()==false){ 59 outputter << ")"; 60 } 61 outputter << "\n"; 54 62 } 55 63 … … 74 82 list<MenuItem*>::iterator iter; 75 83 for(iter = items.begin(); iter!=items.end();iter++){ 76 somethingChosen |= (*iter)->checkTrigger(choice); 84 if((*iter)->isActive()){ 85 somethingChosen |= (*iter)->checkTrigger(choice); 86 } 77 87 } 78 88 // see if something was chosen and call default Item if not … … 88 98 } 89 99 100 string TextMenu::getTitle(){ 101 return title; 102 } 103 90 104 void TextMenu::addDefault(MenuItem* _defaultItem) { 91 105 defaultItem = _defaultItem; 92 106 } 107 108 /****************************** Contained Actions ****************/ 109 110 const string TextMenu::LeaveAction::nameBase = "Leave menu: "; 111 112 TextMenu::LeaveAction::LeaveAction(TextMenu* _menu) : 113 Action(nameBase+_menu->getTitle()), 114 menu(_menu) 115 {} 116 117 TextMenu::LeaveAction::~LeaveAction(){} 118 119 bool TextMenu::LeaveAction::canUndo(){ 120 return false; 121 } 122 123 bool TextMenu::LeaveAction::shouldUndo(){ 124 return false; 125 } 126 127 Action::state_ptr TextMenu::LeaveAction::performCall(){ 128 menu->doQuit(); 129 return Action::success; 130 } 131 132 133 Action::state_ptr TextMenu::LeaveAction::performUndo(Action::state_ptr){ 134 ASSERT(0,"Cannot undo leaving a menu"); 135 return Action::success; 136 } 137 138 Action::state_ptr TextMenu::LeaveAction::performRedo(Action::state_ptr){ 139 ASSERT(0,"Cannot redo leaving a menu"); 140 return Action::success; 141 } -
src/Menu/TextMenu.hpp
r9131f3 r4415da 14 14 15 15 #include "Menu/Menu.hpp" 16 #include "Actions/Action.hpp" 16 17 #include "defs.hpp" 17 18 … … 26 27 { 27 28 public: 29 class LeaveAction : public Action { 30 public: 31 LeaveAction(TextMenu*); 32 virtual ~LeaveAction(); 33 34 bool canUndo(); 35 bool shouldUndo(); 36 37 private: 38 virtual Action::state_ptr performCall(); 39 virtual Action::state_ptr performUndo(Action::state_ptr); 40 virtual Action::state_ptr performRedo(Action::state_ptr); 41 42 TextMenu* menu; 43 44 static const string nameBase; 45 }; 46 28 47 TextMenu(ostream& _outputter, string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH); 29 48 virtual ~TextMenu(); … … 32 51 virtual void removeItem(MenuItem*); 33 52 virtual void display(); 53 virtual string getTitle(); 34 54 35 55 /** -
src/Parser/ChangeTracker.cpp
r9131f3 r4415da 15 15 ChangeTracker::ChangeTracker() { 16 16 isConsistent = true; 17 World::get ()->signOn(this);17 World::getInstance().signOn(this); 18 18 } 19 19 … … 22 22 */ 23 23 ChangeTracker::~ChangeTracker() { 24 World::get ()->signOff(this);24 World::getInstance().signOff(this); 25 25 } 26 26 -
src/Parser/TremoloParser.cpp
r9131f3 r4415da 20 20 */ 21 21 TremoloParser::TremoloParser() { 22 knownKeys[" "] = noKey; // so we can detect invalid keys 22 23 knownKeys["x"] = x; 23 24 knownKeys["u"] = u; … … 61 62 while (lineStream.good()) { 62 63 lineStream >> keyword; 64 if (knownKeys[keyword.substr(0, keyword.find("="))] == noKey) { 65 // throw exception about unknown key 66 cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl; 67 break; 68 } 63 69 usedFields.push_back(keyword); 64 70 } … … 74 80 vector<string>::iterator it; 75 81 stringstream lineStream; 82 atom* newAtom = World::getInstance().createAtom(); 83 TremoloAtomInfoContainer atomInfo = *(new TremoloAtomInfoContainer()); 84 atomDataKey currentField; 76 85 string word; 77 86 … … 79 88 for (it=usedFields.begin(); it < usedFields.end(); it++) { 80 89 cout << *it << " -- " << it->substr(0, it->find("=")) << " -- " << knownKeys[it->substr(0, it->find("="))] << endl; 81 switch (knownKeys[it->substr(0, it->find("="))]) { 90 currentField = knownKeys[it->substr(0, it->find("="))]; 91 switch (currentField) { 82 92 case x : 83 lineStream >> word; 84 cout<< "Found an x: word: " << word << endl; 93 // for the moment, assume there are always three dimensions 94 lineStream >> newAtom->x.x[0]; 95 lineStream >> newAtom->x.x[1]; 96 lineStream >> newAtom->x.x[2]; 97 break; 98 case u : 99 // for the moment, assume there are always three dimensions 100 lineStream >> newAtom->v.x[0]; 101 lineStream >> newAtom->v.x[1]; 102 lineStream >> newAtom->v.x[2]; 103 break; 104 case F : 105 lineStream >> word; 106 atomInfo.F = word; 107 break; 108 case stress : 109 lineStream >> word; 110 atomInfo.F = word; 111 break; 112 case Id : 113 // this ID is not used 114 break; 115 case neighbors : 116 // TODO neighbor information 117 lineStream >> word; 118 break; 119 case imprData : 120 lineStream >> word; 121 atomInfo.imprData = word; 122 break; 123 case GroupMeasureTypeNo : 124 lineStream >> word; 125 atomInfo.GroupMeasureTypeNo = word; 126 break; 127 case Type : 128 char type[3]; 129 lineStream >> type; 130 newAtom->setType(World::getInstance().getPeriode()->FindElement(type)); 131 break; 132 case extType : 133 lineStream >> word; 134 atomInfo.extType = word; 135 break; 136 case name : 137 lineStream >> word; 138 atomInfo.name = word; 139 break; 140 case resName : 141 lineStream >> word; 142 atomInfo.resName = word; 143 break; 144 case chainID : 145 lineStream >> word; 146 atomInfo.chainID = word; 147 break; 148 case resSeq : 149 lineStream >> word; 150 atomInfo.resSeq = word; 151 break; 152 case occupancy : 153 lineStream >> word; 154 atomInfo.occupancy = word; 155 break; 156 case tempFactor : 157 lineStream >> word; 158 atomInfo.segID = word; 159 break; 160 case segID : 161 lineStream >> word; 162 atomInfo.F = word; 163 break; 164 case Charge : 165 lineStream >> word; 166 atomInfo.Charge = word; 167 break; 168 case charge : 169 lineStream >> word; 170 atomInfo.charge = word; 171 break; 172 case GrpTypeNo : 173 lineStream >> word; 174 atomInfo.GrpTypeNo = word; 85 175 break; 86 176 default : … … 90 180 } 91 181 } 182 moreData[newAtom->getId()] = atomInfo; 92 183 } 93 184 … … 117 208 } 118 209 119 /*120 #ATOMDATA <record_entry_1> ... <record_entry_n>121 # <record_entry>: <dataname>[=<n>]122 # <dataname> : x | u | F | stress | Id | neighbors | imprData123 # | GroupMeasureTypeNo | Type | extType124 # | name | resName | chainID | resSeq125 # | occupancy | tempFactor | segID | Charge126 # | charge127 ATOMDATA name Id x=3 mass charge epsilon sigma eps14 sig14 name type protein protno neighbors=4128 */129 130 //MatrixContainer* data = readData(fileName, getHeaderSize('#'), 0);131 132 133 210 /** 134 211 * Saves the World's current state into as a tremolo file. … … 144 221 */ 145 222 } 223 224 TremoloAtomInfoContainer::TremoloAtomInfoContainer() { 225 name = "none"; 226 /* Add suitable default values. 227 std::string F; 228 std::string stress; 229 std::string imprData; 230 std::string GroupMeasureTypeNo; 231 std::string extType; 232 std::string name; 233 std::string resName; 234 std::string chainID; 235 std::string resSeq; 236 std::string occupancy; 237 std::string tempFactor; 238 std::string segID; 239 std::string Charge; 240 std::string charge; 241 std::string GrpTypeNo; 242 */ 243 }; -
src/Parser/TremoloParser.hpp
r9131f3 r4415da 12 12 #include "FormatParser.hpp" 13 13 14 /** 15 * Holds tremolo-specific information which is not store in the atom class. 16 */ 17 class TremoloAtomInfoContainer { 18 public: 19 TremoloAtomInfoContainer(); 20 std::string F; 21 std::string stress; 22 std::string imprData; 23 std::string GroupMeasureTypeNo; 24 std::string extType; 25 std::string name; 26 std::string resName; 27 std::string chainID; 28 std::string resSeq; 29 std::string occupancy; 30 std::string tempFactor; 31 std::string segID; 32 std::string Charge; 33 std::string charge; 34 std::string GrpTypeNo; 35 }; 36 37 /** 38 * Loads a tremolo file into the World and saves the World as a tremolo file. 39 */ 14 40 class TremoloParser:public FormatParser 15 41 { … … 27 53 * Known keys for the ATOMDATA line. 28 54 */ 29 enum StringValue { 55 enum atomDataKey { 56 noKey, 30 57 x, 31 58 u, … … 53 80 * Map to associate the known keys with numbers. 54 81 */ 55 std::map<std::string, StringValue> knownKeys;82 std::map<std::string, atomDataKey> knownKeys; 56 83 57 84 /** … … 64 91 * file. 65 92 */ 66 std::map< std::string, std::string> moreData;93 std::map<int, TremoloAtomInfoContainer> moreData; 67 94 }; 68 95 -
src/Parser/XyzParser.cpp
r9131f3 r4415da 44 44 45 45 for (int i = 0; i < numberOfAtoms; i++) { 46 newAtom = World::get ()->createAtom();46 newAtom = World::getInstance().createAtom(); 47 47 *file >> type >> ws >> newAtom->x.x[0] >> ws >> newAtom->x.x[1] >> ws >> newAtom->x.x[2]; 48 newAtom->setType(World::get ()->getPeriode()->FindElement(type));48 newAtom->setType(World::getInstance().getPeriode()->FindElement(type)); 49 49 } 50 50 } … … 56 56 */ 57 57 void XyzParser::save(ostream* file) { 58 *file << World::get ()->numAtoms() << endl << comment << endl;58 *file << World::getInstance().numAtoms() << endl << comment << endl; 59 59 60 vector<atom*> atoms = World::get ()->getAllAtoms();60 vector<atom*> atoms = World::getInstance().getAllAtoms(); 61 61 for(vector<atom*>::iterator it = atoms.begin(); it < atoms.end(); it++) { 62 62 *file << fixed << (*it)->getType()->symbol << "\t" << (*it)->x.x[0] << "\t" << (*it)->x.x[1] << "\t" << (*it)->x.x[2] << endl; -
src/Patterns/Cacheable.hpp
r9131f3 r4415da 11 11 #include "Patterns/Observer.hpp" 12 12 #include <boost/function.hpp> 13 #include <boost/shared_ptr.hpp> 14 #include <iostream> 15 16 #include "Helpers/Assert.hpp" 13 17 14 18 #ifndef NO_CACHING … … 17 21 class Cacheable : public Observer 18 22 { 23 // we define the states of the cacheable so we can do very fast state-checks 24 class State{ 25 public: 26 State(Cacheable *_owner) : 27 busy(false), 28 owner(_owner) 29 {} 30 virtual T getValue()=0; 31 virtual void invalidate()=0; 32 virtual bool isValid()=0; 33 virtual void enter()=0; 34 bool isBusy(){ 35 return busy; 36 } 37 protected: 38 bool busy; 39 Cacheable *owner; 40 }; 41 42 class InvalidState : public State{ 43 public: 44 InvalidState(Cacheable *_owner): 45 State(_owner) 46 {} 47 48 virtual T getValue(){ 49 // set the state to valid 50 State::owner->switchState(State::owner->validState); 51 // get the value from the now valid state 52 return State::owner->state->getValue(); 53 } 54 55 virtual void invalidate(){ 56 // nothing to do on this message 57 } 58 59 virtual bool isValid(){ 60 return false; 61 } 62 63 virtual void enter(){ 64 // nothing to do when entering this 65 } 66 }; 67 68 class ValidState : public State{ 69 public: 70 ValidState(Cacheable *_owner) : 71 State(_owner) 72 {} 73 74 virtual T getValue(){ 75 return content; 76 } 77 78 virtual void invalidate(){ 79 State::owner->switchState(State::owner->invalidState); 80 } 81 82 virtual bool isValid(){ 83 return true; 84 } 85 86 virtual void enter(){ 87 State::busy= true; 88 // as soon as we enter the valid state we recalculate 89 content = State::owner->recalcMethod(); 90 State::busy = false; 91 } 92 private: 93 T content; 94 }; 95 96 class DestroyedState : public State { 97 public: 98 DestroyedState(Cacheable *_owner) : 99 State(_owner) 100 {} 101 102 virtual T getValue(){ 103 ASSERT(0,"Cannot get a value from a Cacheable after it's Observable has died"); 104 // we have to return a grossly invalid reference, because no value can be produced anymore 105 return *(static_cast<T*>(0)); 106 } 107 108 virtual void invalidate(){ 109 ASSERT(0,"Cannot invalidate a Cacheable after it's Observable has died"); 110 } 111 112 virtual bool isValid(){ 113 ASSERT(0,"Cannot check validity of a Cacheable after it's Observable has died"); 114 return false; 115 } 116 117 virtual void enter(){ 118 // nothing to do when entering this state 119 } 120 }; 121 122 123 typedef boost::shared_ptr<State> state_ptr; 124 19 125 public: 20 126 Cacheable(Observable *_owner, boost::function<T()> _recalcMethod); 21 127 virtual ~Cacheable(); 22 128 23 const bool isValid(); 24 const T& operator*(); 25 const bool operator==(const T&); 26 const bool operator!=(const T&); 129 const bool isValid() const; 130 const T operator*() const; 27 131 28 132 // methods implemented for base-class Observer … … 30 134 void subjectKilled(Observable *subject); 31 135 private: 32 void checkValid(); 33 34 T content; 136 137 void switchState(state_ptr newState); 138 139 mutable state_ptr state; 140 // pre-defined state so we don't have to construct to much 141 state_ptr invalidState; 142 state_ptr validState; 143 // destroyed state is not predefined, because we rarely enter that state and never leave 144 35 145 Observable *owner; 36 bool valid; 37 bool canBeUsed; 146 38 147 boost::function<T()> recalcMethod; 148 149 // de-activated copy constructor 150 Cacheable(const Cacheable&); 39 151 }; 40 152 … … 43 155 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) : 44 156 owner(_owner), 45 valid(false),46 canBeUsed(true),47 157 recalcMethod(_recalcMethod) 48 158 { 159 // create all states needed for this object 160 invalidState = state_ptr(new InvalidState(this)); 161 validState = state_ptr(new ValidState(this)); 162 state = invalidState; 49 163 // we sign on with the best(=lowest) priority, so cached values are recalculated before 50 164 // anybody else might ask for updated values … … 52 166 } 53 167 54 template<typename T> 55 const T& Cacheable<T>::operator*(){ 56 checkValid(); 57 return content; 58 } 59 60 template<typename T> 61 const bool Cacheable<T>::operator==(const T& rval){ 62 checkValid(); 63 return (content == rval); 64 } 65 66 template<typename T> 67 const bool Cacheable<T>::operator!=(const T& rval){ 68 checkValid(); 69 return (content != rval); 168 // de-activated copy constructor 169 template<typename T> 170 Cacheable<T>::Cacheable(const Cacheable&){ 171 ASSERT(0,"Cacheables should never be copied"); 172 } 173 174 template<typename T> 175 const T Cacheable<T>::operator*() const{ 176 // we can only use the cacheable when the owner is not changing at the moment 177 if(!owner->isBlocked()){ 178 return state->getValue(); 179 } 180 else{ 181 return recalcMethod(); 182 } 70 183 } 71 184 … … 77 190 78 191 template<typename T> 79 const bool Cacheable<T>::isValid() {80 return valid;192 const bool Cacheable<T>::isValid() const{ 193 return state->isValid(); 81 194 } 82 195 83 196 template<typename T> 84 197 void Cacheable<T>::update(Observable *subject) { 85 valid = false;198 state->invalidate(); 86 199 } 87 200 88 201 template<typename T> 89 202 void Cacheable<T>::subjectKilled(Observable *subject) { 90 valid = false;91 canBeUsed = false;92 } 93 94 template<typename T> 95 void Cacheable<T>:: checkValid(){96 assert(canBeUsed && "Cacheable used after owner was deleted");97 if(!isValid()){98 content = recalcMethod();99 100 } 203 state_ptr destroyed = state_ptr(new DestroyedState(this)); 204 switchState(destroyed); 205 } 206 207 template<typename T> 208 void Cacheable<T>::switchState(state_ptr newState){ 209 ASSERT(!state->isBusy(),"LOOP DETECTED: Cacheable state switched while recalculating.\nDid the recalculation trigger the Observable?"); 210 state = newState; 211 state->enter(); 212 } 213 101 214 #else 102 215 template<typename T> … … 107 220 virtual ~Cacheable(); 108 221 109 const bool isValid(); 110 const T& operator*(); 111 const bool operator==(const T&); 112 const bool operator!=(const T&); 222 const bool isValid() const; 223 const T operator*() const; 113 224 114 225 // methods implemented for base-class Observer … … 126 237 127 238 template<typename T> 128 const T & Cacheable<T>::operator*(){239 const T Cacheable<T>::operator*() const{ 129 240 return recalcMethod(); 130 }131 132 template<typename T>133 const bool Cacheable<T>::operator==(const T& rval){134 return (recalcMethod() == rval);135 }136 137 template<typename T>138 const bool Cacheable<T>::operator!=(const T& rval){139 return (recalcMethod() != rval);140 241 } 141 242 … … 145 246 146 247 template<typename T> 147 const bool Cacheable<T>::isValid() {248 const bool Cacheable<T>::isValid() const{ 148 249 return true; 149 250 } … … 151 252 template<typename T> 152 253 void Cacheable<T>::update(Observable *subject) { 153 assert(0 &&"Cacheable::update should never be called when caching is disabled");154 } 155 156 template<typename T> 157 void Cacheable<T>::subjectKilled(Observable *subject) 158 assert(0 &&"Cacheable::subjectKilled should never be called when caching is disabled");254 ASSERT(0, "Cacheable::update should never be called when caching is disabled"); 255 } 256 257 template<typename T> 258 void Cacheable<T>::subjectKilled(Observable *subject){ 259 ASSERT(0, "Cacheable::subjectKilled should never be called when caching is disabled"); 159 260 } 160 261 #endif -
src/Patterns/Observer.cpp
r9131f3 r4415da 10 10 11 11 #include <iostream> 12 #include <cassert> 12 13 #include "Helpers/Assert.hpp" 13 14 14 15 using namespace std; … … 127 128 // observers, but still we are called by one of our sub-Observables 128 129 // we cannot be sure observation will still work at this point 129 cerr << "Circle detected in observation-graph." << endl;130 cerr << "Observation-graph always needs to be a DAG to work correctly!" << endl;131 cerr << "Please check your observation code and fix this!" << endl;130 ASSERT(0,"Circle detected in observation-graph.\n" 131 "Observation-graph always needs to be a DAG to work correctly!\n" 132 "Please check your observation code and fix this!\n"); 132 133 return; 133 134 } … … 148 149 */ 149 150 void Observable::signOn(Observer *target,int priority) { 150 assert(priority>=-20 && priority<=+20 && "Priority out of range [-20:+20]");151 ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer"); 151 152 bool res = false; 152 153 callees_t *callees = 0; … … 172 173 */ 173 174 void Observable::signOff(Observer *target) { 174 assert(callTable.count(this) &&"SignOff called for an Observable without Observers.");175 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 175 176 callees_t *callees = callTable[this]; 176 177 callees_t::iterator iter; … … 188 189 delete callees; 189 190 } 191 } 192 193 bool Observable::isBlocked(){ 194 return depth.count(this) > 0; 190 195 } 191 196 -
src/Patterns/Observer.hpp
r9131f3 r4415da 95 95 virtual void signOff(Observer *target); 96 96 97 /** 98 * Ask an Observer if it is currently in a blocked state, i.e. if 99 * Changes are in Progress, that are not yet published. 100 */ 101 virtual bool isBlocked(); 102 97 103 protected: 98 104 virtual void update(Observable *publisher); … … 119 125 static std::set<Observable*> busyObservables; 120 126 127 //! @cond 121 128 // Structure for RAII-Style notification 122 129 protected: … … 133 140 Observable *protege; 134 141 }; 142 //! @endcond 135 143 }; 136 144 -
src/UIElements/Dialog.cpp
r9131f3 r4415da 133 133 *target = *tmp; 134 134 } 135 136 // Element Queries 137 Dialog::ElementQuery::ElementQuery(std::string title, const element **_target) : 138 Query(title), 139 tmp(0), 140 target(_target) 141 {} 142 143 Dialog::ElementQuery::~ElementQuery(){} 144 145 void Dialog::ElementQuery::setResult(){ 146 *target=tmp; 147 } -
src/UIElements/Dialog.hpp
r9131f3 r4415da 15 15 class molecule; 16 16 class Vector; 17 class element; 17 18 18 19 class Dialog … … 27 28 virtual void queryMolecule(const char*,molecule**,MoleculeListClass*)=0; 28 29 virtual void queryVector(const char*,Vector *,const double *const,bool)=0; 30 virtual void queryElement(const char*,const element **)=0; 29 31 30 32 virtual bool display(); … … 45 47 public: 46 48 Query(std::string _title); 47 ~Query();49 virtual ~Query(); 48 50 virtual bool handle()=0; 49 51 virtual void setResult()=0; … … 58 60 public: 59 61 IntQuery(std::string title,int *_target); 60 ~IntQuery();62 virtual ~IntQuery(); 61 63 virtual bool handle()=0; 62 64 virtual void setResult(); … … 70 72 public: 71 73 DoubleQuery(std::string title,double *_target); 72 ~DoubleQuery();74 virtual ~DoubleQuery(); 73 75 virtual bool handle()=0; 74 76 virtual void setResult(); … … 82 84 public: 83 85 StringQuery(std::string title,std::string *_target); 84 ~StringQuery();86 virtual ~StringQuery(); 85 87 virtual bool handle()=0; 86 88 virtual void setResult(); … … 95 97 public: 96 98 MoleculeQuery(std::string title, molecule **_target, MoleculeListClass *_molecules); 97 ~MoleculeQuery();99 virtual ~MoleculeQuery(); 98 100 virtual bool handle()=0; 99 101 virtual void setResult(); … … 108 110 public: 109 111 VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check); 110 ~VectorQuery();112 virtual ~VectorQuery(); 111 113 virtual bool handle()=0; 112 114 virtual void setResult(); … … 119 121 }; 120 122 123 class ElementQuery : public Query { 124 public: 125 ElementQuery(std::string title, const element**_target); 126 virtual ~ElementQuery(); 127 virtual bool handle()=0; 128 virtual void setResult(); 129 protected: 130 const element *tmp; 131 private: 132 const element **target; 133 }; 134 121 135 void registerQuery(Query* query); 122 136 -
src/UIElements/TextDialog.cpp
r9131f3 r4415da 10 10 #include "UIElements/TextDialog.hpp" 11 11 12 #include "World.hpp" 13 #include "periodentafel.hpp" 12 14 #include "atom.hpp" 13 15 #include "molecule.hpp" … … 45 47 void TextDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check) { 46 48 registerQuery(new VectorTextQuery(title,target,cellSize,check)); 49 } 50 51 void TextDialog::queryElement(const char* title, const element **target){ 52 registerQuery(new ElementTextQuery(title,target)); 47 53 } 48 54 … … 113 119 114 120 bool TextDialog::VectorTextQuery::handle() { 121 Log() << Verbose(0) << getTitle(); 115 122 tmp->AskPosition(cellSize,check); 116 123 return true; 117 124 } 125 126 127 TextDialog::ElementTextQuery::ElementTextQuery(std::string title, const element **target) : 128 Dialog::ElementQuery(title,target) 129 {} 130 131 TextDialog::ElementTextQuery::~ElementTextQuery() 132 {} 133 134 bool TextDialog::ElementTextQuery::handle() { 135 int Z; 136 Log() << Verbose(0) << getTitle(); 137 cin >> Z; 138 tmp = World::getInstance().getPeriode()->FindElement(Z); 139 return tmp; 140 } -
src/UIElements/TextDialog.hpp
r9131f3 r4415da 24 24 virtual void queryMolecule(const char*,molecule**,MoleculeListClass*); 25 25 virtual void queryVector(const char*,Vector *,const double * const,bool); 26 virtual void queryElement(const char*,const element **); 26 27 27 28 protected: … … 30 31 public: 31 32 IntTextQuery(std::string title, int *_target); 32 ~IntTextQuery();33 virtual ~IntTextQuery(); 33 34 virtual bool handle(); 34 35 }; … … 37 38 public: 38 39 DoubleTextQuery(std::string title, double *_target); 39 ~DoubleTextQuery();40 virtual ~DoubleTextQuery(); 40 41 virtual bool handle(); 41 42 }; … … 44 45 public: 45 46 StringTextQuery(std::string title, std::string *_target); 46 ~StringTextQuery();47 virtual ~StringTextQuery(); 47 48 virtual bool handle(); 48 49 }; … … 51 52 public: 52 53 MoleculeTextQuery(std::string title, molecule **_target, MoleculeListClass *_molecules); 53 ~MoleculeTextQuery();54 virtual ~MoleculeTextQuery(); 54 55 virtual bool handle(); 55 56 }; … … 58 59 public: 59 60 VectorTextQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check); 60 ~VectorTextQuery(); 61 virtual ~VectorTextQuery(); 62 virtual bool handle(); 63 }; 64 65 class ElementTextQuery : public Dialog::ElementQuery { 66 public: 67 ElementTextQuery(std::string title, const element **_target); 68 virtual ~ElementTextQuery(); 61 69 virtual bool handle(); 62 70 }; -
src/UIElements/TextWindow.cpp
r9131f3 r4415da 39 39 #include "Actions/MethodAction.hpp" 40 40 #include "Actions/ErrorAction.hpp" 41 #include "Actions/ActionRegistry.hpp" 41 42 #include "Views/StreamStringView.hpp" 42 43 #include "Views/MethodStringView.hpp" … … 56 57 moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1)); 57 58 new DisplayMenuItem(main_menu,moleculeView,"Molecule List"); 59 60 new SeperatorItem(main_menu); 61 62 Action* undoAction = ActionRegistry::getInstance().getActionByName("Undo"); 63 new ActionMenuItem('u',"Undo last operation",main_menu,undoAction); 64 65 Action* redoAction = ActionRegistry::getInstance().getActionByName("Redo"); 66 new ActionMenuItem('r',"Redo last operation",main_menu,redoAction); 58 67 59 68 new SeperatorItem(main_menu); … … 94 103 populaters.MakeEditMoleculesMenu(editMoleculesMenu,molecules,configuration,periode); 95 104 96 returnFromEditMoleculeAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,editMoleculesMenu),false);105 Action *returnFromEditMoleculeAction = new TextMenu::LeaveAction(editMoleculesMenu); 97 106 MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnFromEditMoleculeAction); 98 107 … … 108 117 delete old_menu; 109 118 delete quitAction; 110 delete returnFromEditMoleculeAction;111 119 delete moleculeView; 112 120 delete statusIndicator; -
src/UIElements/TextWindow.hpp
r9131f3 r4415da 29 29 // some actions only needed in textMenus 30 30 Action *quitAction; 31 Action *returnFromEditMoleculeAction;32 31 // all views that are contained in the main Menu 33 32 StringView *moleculeView; -
src/UIElements/UIFactory.cpp
r9131f3 r4415da 8 8 9 9 #include <cassert> 10 #include "Patterns/Singleton_impl.hpp" 10 11 #include "UIElements/UIFactory.hpp" 11 12 12 13 // all factories that can be used: 13 14 #include "UIElements/TextUIFactory.hpp" 14 15 UIFactory *UIFactory::theFactory = 0;16 15 17 16 UIFactory::UIFactory() … … 27 26 28 27 void UIFactory::makeUserInterface(InterfaceTypes type) { 29 assert(theFactory == 0 && "makeUserInterface should only be called once");30 28 switch(type) { 31 29 case Text : 32 theFactory = new TextUIFactory();30 setInstance(new TextUIFactory()); 33 31 break; 34 32 … … 39 37 } 40 38 41 UIFactory* UIFactory::get(){ 42 assert(theFactory != 0 && "No UserInterface created prior to factory access"); 43 return theFactory; 44 } 45 46 47 void UIFactory::purgeInstance(){ 48 if(theFactory) { 49 delete theFactory; 50 theFactory = 0; 51 } 52 } 39 CONSTRUCT_SINGLETON(UIFactory) -
src/UIElements/UIFactory.hpp
r9131f3 r4415da 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 … … 45 48 UIFactory(); 46 49 47 // singleton stuff48 private:49 static UIFactory *theFactory;50 51 50 public: 52 51 /** … … 55 54 static void makeUserInterface(InterfaceTypes type); 56 55 57 /**58 * get the previously created factory59 */60 static UIFactory* get();61 62 /**63 * Destroy the created factory.64 *65 * Make sure that all UIElements that were created by the factory are destroyed before calling this method.66 */67 static void purgeInstance();68 56 }; 69 57 -
src/World.cpp
r9131f3 r4415da 15 15 #include "Descriptors/MoleculeDescriptor.hpp" 16 16 #include "Descriptors/MoleculeDescriptor_impl.hpp" 17 #include "Descriptors/SelectiveIterator_impl.hpp" 17 18 #include "Actions/ManipulateAtomsProcess.hpp" 19 20 #include "Patterns/Singleton_impl.hpp" 18 21 19 22 using namespace std; … … 170 173 atomId_t id = *(atomIdPool.begin()); 171 174 atomIdPool.erase(id); 175 return id; 172 176 } 173 177 } … … 206 210 /******************************* Iterators ********************************/ 207 211 208 / *209 * Actual Implementation of the iterators can be found in WorldIterators.cpp 210 */ 212 // Build the AtomIterator from template 213 CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor); 214 211 215 212 216 World::AtomIterator World::getAtomIter(AtomDescriptor descr){ 213 return AtomIterator(descr,this); 214 } 215 216 World::AtomSet::iterator World::atomEnd(){ 217 return atoms.end(); 218 } 217 return AtomIterator(descr,atoms); 218 } 219 220 World::AtomIterator World::atomEnd(){ 221 return AtomIterator(AllAtoms(),atoms,atoms.end()); 222 } 223 224 // build the MoleculeIterator from template 225 CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor); 219 226 220 227 World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){ 221 return MoleculeIterator(descr, this);222 } 223 224 World::Molecule Set::iterator World::moleculeEnd(){225 return molecules.end();228 return MoleculeIterator(descr,molecules); 229 } 230 231 World::MoleculeIterator World::moleculeEnd(){ 232 return MoleculeIterator(AllMolecules(),molecules,molecules.end()); 226 233 } 227 234 228 235 /******************************* Singleton Stuff **************************/ 229 230 // TODO: Hide boost-thread using Autotools stuff when no threads are used231 World* World::theWorld = 0;232 boost::mutex World::worldLock;233 236 234 237 World::World() : … … 260 263 } 261 264 262 World* World::get(){ 263 // boost supports RAII-Style locking, so we don't need to unlock 264 boost::mutex::scoped_lock guard(worldLock); 265 if(!theWorld) { 266 theWorld = new World(); 267 } 268 return theWorld; 269 } 270 271 void World::destroy(){ 272 // boost supports RAII-Style locking, so we don't need to unlock 273 boost::mutex::scoped_lock guard(worldLock); 274 delete theWorld; 275 theWorld = 0; 276 } 277 278 World* World::reset(){ 279 World* oldWorld = 0; 280 { 281 // boost supports RAII-Style locking, so we don't need to unlock 282 boost::mutex::scoped_lock guard(worldLock); 283 284 oldWorld = theWorld; 285 theWorld = new World(); 286 // oldworld does not need protection any more, 287 // since we should have the only reference 288 289 // worldLock handles access to the pointer, 290 // not to the object 291 } // scope-end releases the lock 292 293 // we have to let all the observers know that the 294 // oldWorld was destroyed. oldWorld calls subjectKilled 295 // upon destruction. Every Observer getting that signal 296 // should see that it gets the updated new world 297 delete oldWorld; 298 return theWorld; 299 } 265 // Explicit instantiation of the singleton mechanism at this point 266 267 CONSTRUCT_SINGLETON(World) 300 268 301 269 /******************************* deprecated Legacy Stuff ***********************/ -
src/World.hpp
r9131f3 r4415da 16 16 #include <boost/shared_ptr.hpp> 17 17 18 #include "defs.hpp" 18 #include "types.hpp" 19 #include "Descriptors/SelectiveIterator.hpp" 19 20 #include "Patterns/Observer.hpp" 20 21 #include "Patterns/Cacheable.hpp" 22 #include "Patterns/Singleton.hpp" 23 21 24 22 25 // forward declarations … … 33 36 class AtomsCalculation; 34 37 35 class World : public Observable 38 39 40 class World : public Singleton<World>, public Observable 36 41 { 42 43 // Make access to constructor and destructor possible from inside the singleton 44 friend class Singleton<World>; 45 37 46 // necessary for coupling with descriptors 38 47 friend class AtomDescriptor_impl; … … 45 54 template<typename> friend class AtomsCalculation; 46 55 public: 56 57 // Types for Atom and Molecule structures 47 58 typedef std::map<atomId_t,atom*> AtomSet; 48 59 typedef std::map<moleculeId_t,molecule*> MoleculeSet; … … 150 161 151 162 // Atoms 152 153 class AtomIterator : 154 public std::iterator<std::iterator_traits<AtomSet::iterator>::difference_type, 155 std::iterator_traits<AtomSet::iterator>::value_type, 156 std::iterator_traits<AtomSet::iterator>::pointer, 157 std::iterator_traits<AtomSet::iterator>::reference> 158 { 159 public: 160 161 typedef AtomSet::iterator _Iter; 162 typedef _Iter::value_type value_type; 163 typedef _Iter::difference_type difference_type; 164 typedef _Iter::pointer pointer; 165 typedef _Iter::reference reference; 166 typedef _Iter::iterator_category iterator_category; 167 168 169 AtomIterator(); 170 AtomIterator(AtomDescriptor, World*); 171 AtomIterator(const AtomIterator&); 172 AtomIterator& operator=(const AtomIterator&); 173 AtomIterator& operator++(); // prefix 174 AtomIterator operator++(int); // postfix with dummy parameter 175 bool operator==(const AtomIterator&); 176 bool operator==(const AtomSet::iterator&); 177 bool operator!=(const AtomIterator&); 178 bool operator!=(const AtomSet::iterator&); 179 atom* operator*(); 180 181 int getCount(); 182 protected: 183 void advanceState(); 184 AtomSet::iterator state; 185 boost::shared_ptr<AtomDescriptor_impl> descr; 186 int index; 187 188 World* world; 189 }; 163 typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator; 190 164 191 165 /** … … 201 175 * used for internal purposes, like AtomProcesses and AtomCalculations. 202 176 */ 203 Atom Set::iterator atomEnd();177 AtomIterator atomEnd(); 204 178 205 179 // Molecules 206 180 207 class MoleculeIterator : 208 public std::iterator<std::iterator_traits<MoleculeSet::iterator>::difference_type, 209 std::iterator_traits<MoleculeSet::iterator>::value_type, 210 std::iterator_traits<MoleculeSet::iterator>::pointer, 211 std::iterator_traits<MoleculeSet::iterator>::reference> 212 { 213 public: 214 215 typedef MoleculeSet::iterator _Iter; 216 typedef _Iter::value_type value_type; 217 typedef _Iter::difference_type difference_type; 218 typedef _Iter::pointer pointer; 219 typedef _Iter::reference reference; 220 typedef _Iter::iterator_category iterator_category; 221 222 MoleculeIterator(); 223 MoleculeIterator(MoleculeDescriptor, World*); 224 MoleculeIterator(const MoleculeIterator&); 225 MoleculeIterator& operator=(const MoleculeIterator&); 226 MoleculeIterator& operator++(); // prefix 227 MoleculeIterator operator++(int); // postfix with dummy parameter 228 bool operator==(const MoleculeIterator&); 229 bool operator==(const MoleculeSet::iterator&); 230 bool operator!=(const MoleculeIterator&); 231 bool operator!=(const MoleculeSet::iterator&); 232 molecule* operator*(); 233 234 int getCount(); 235 protected: 236 void advanceState(); 237 MoleculeSet::iterator state; 238 boost::shared_ptr<MoleculeDescriptor_impl> descr; 239 int index; 240 241 World* world; 242 }; 181 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator; 243 182 244 183 /** … … 254 193 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. 255 194 */ 256 Molecule Set::iterator moleculeEnd();195 MoleculeIterator moleculeEnd(); 257 196 258 197 … … 267 206 268 207 periodentafel *periode; 208 public: 269 209 AtomSet atoms; 210 private: 270 211 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId 271 212 atomId_t currAtomId; //!< stores the next available Id for atoms 272 213 MoleculeSet molecules; 273 214 moleculeId_t currMoleculeId; 274 275 276 /***** singleton Stuff *****/277 public:278 279 /**280 * get the currently active instance of the World.281 */282 static World* get();283 284 /**285 * destroy the currently active instance of the World.286 */287 static void destroy();288 289 /**290 * destroy the currently active instance of the World and immidiately291 * create a new one. Use this to reset while somebody is still Observing292 * the world and should reset the observed instance. All observers will be293 * sent the subjectKille() message from the old world.294 */295 static World* reset();296 297 215 private: 298 216 /** … … 307 225 */ 308 226 virtual ~World(); 309 310 static World *theWorld;311 // this mutex only saves the singleton pattern...312 // use other mutexes to protect internal data as well313 // this mutex handles access to the pointer, not to the object!!!314 static boost::mutex worldLock;315 227 316 228 /***** -
src/atom.cpp
r9131f3 r4415da 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.hpp
r9131f3 r4415da 28 28 #include "atom_trajectoryparticle.hpp" 29 29 #include "tesselation.hpp" 30 #include "types.hpp" 30 31 31 32 /****************************************** forward declarations *****************************/ -
src/atom_atominfo.cpp
r9131f3 r4415da 20 20 }; 21 21 22 element *AtomInfo::getType(){22 const element *AtomInfo::getType(){ 23 23 return type; 24 24 } 25 25 26 void AtomInfo::setType( element* _type) {26 void AtomInfo::setType(const element* _type) { 27 27 type = _type; 28 28 } 29 29 30 30 void AtomInfo::setType(int Z) { 31 element *elem = World::get()->getPeriode()->FindElement(Z);31 const element *elem = World::getInstance().getPeriode()->FindElement(Z); 32 32 setType(elem); 33 33 } -
src/atom_atominfo.hpp
r9131f3 r4415da 32 32 Vector v; //!< velocity vector of atom, giving last velocity within cell 33 33 Vector F; //!< Force vector of atom, giving last force within cell 34 element *type; //!< pointing to element34 const element *type; //!< pointing to element 35 35 36 36 AtomInfo(); 37 37 ~AtomInfo(); 38 38 39 element *getType();40 void setType( element *);39 const element *getType(); 40 void setType(const element *); 41 41 void setType(int); 42 42 -
src/boundary.cpp
r9131f3 r4415da 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
r9131f3 r4415da 74 74 #include "Menu/ActionMenuItem.hpp" 75 75 #include "Actions/ActionRegistry.hpp" 76 #include "Actions/ActionHistory.hpp" 76 77 #include "Actions/MethodAction.hpp" 77 78 #include "Actions/small_actions.hpp" … … 1432 1433 } 1433 1434 if (mol == NULL) { 1434 mol = World::get ()->createMolecule();1435 mol = World::getInstance().createMolecule(); 1435 1436 mol->ActiveFlag = true; 1436 1437 if (ConfigFileName != NULL) … … 1481 1482 SaveFlag = true; 1482 1483 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), "; 1483 first = World::get ()->createAtom();1484 first = World::getInstance().createAtom(); 1484 1485 first->type = periode->FindElement(atoi(argv[argptr])); 1485 1486 if (first->type != NULL) … … 1593 1594 } 1594 1595 LCList = new LinkedCell(Boundary, 2.*radius); 1595 element *elemental = periode->FindElement((const int) atoi(argv[argptr]));1596 const element *elemental = periode->FindElement((atomicNumber_t) atoi(argv[argptr])); 1596 1597 FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL); 1597 1598 int ranges[NDIM] = {1,1,1}; … … 1634 1635 Log() << Verbose(1) << "Filling Box with water molecules." << endl; 1635 1636 // construct water molecule 1636 molecule *filler = World::get ()->createMolecule();1637 molecule *filler = World::getInstance().createMolecule(); 1637 1638 molecule *Filling = NULL; 1638 1639 atom *second = NULL, *third = NULL; … … 1641 1642 // first->x.Zero(); 1642 1643 // filler->AddAtom(first); 1643 first = World::get ()->createAtom();1644 first = World::getInstance().createAtom(); 1644 1645 first->type = periode->FindElement(1); 1645 1646 first->x.Init(0.441, -0.143, 0.); 1646 1647 filler->AddAtom(first); 1647 second = World::get ()->createAtom();1648 second = World::getInstance().createAtom(); 1648 1649 second->type = periode->FindElement(1); 1649 1650 second->x.Init(-0.464, 1.137, 0.0); 1650 1651 filler->AddAtom(second); 1651 third = World::get ()->createAtom();1652 third = World::getInstance().createAtom(); 1652 1653 third->type = periode->FindElement(8); 1653 1654 third->x.Init(-0.464, 0.177, 0.); … … 1664 1665 molecules->insert(Filling); 1665 1666 } 1666 World::get ()->destroyMolecule(filler);1667 World::getInstance().destroyMolecule(filler); 1667 1668 argptr+=6; 1668 1669 } … … 2070 2071 int faktor = atoi(argv[argptr++]); 2071 2072 int count; 2072 element ** Elements;2073 const element ** Elements; 2073 2074 Vector ** vectors; 2074 2075 if (faktor < 1) { 2075 eLog() << Verbose(1) << "Repetition factor mus be greater than 1!" << endl;2076 eLog() << Verbose(1) << "Repetition factor must be greater than 1!" << endl; 2076 2077 faktor = 1; 2077 2078 } … … 2079 2080 if (mol->AtomCount != 0) { // if there is more than none 2080 2081 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand 2081 Elements = new element *[count];2082 Elements = new const element *[count]; 2082 2083 vectors = new Vector *[count]; 2083 2084 j = 0; … … 2097 2098 x.AddVector(&y); // per factor one cell width further 2098 2099 for (int k=count;k--;) { // go through every atom of the original cell 2099 first = World::get ()->createAtom(); // create a new body2100 first = World::getInstance().createAtom(); // create a new body 2100 2101 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2101 2102 first->x.AddVector(&x); // translate the coordinates … … 2168 2169 void cleanUp(config *configuration){ 2169 2170 UIFactory::purgeInstance(); 2170 World:: destroy();2171 World::purgeInstance(); 2171 2172 delete(configuration); 2172 2173 Log() << Verbose(0) << "Maximum of allocated memory: " … … 2177 2178 logger::purgeInstance(); 2178 2179 errorLogger::purgeInstance(); 2179 ActionRegistry::purge Registry();2180 ActionRegistry::purgeInstance(); 2180 2181 } 2181 2182 … … 2190 2191 char *ConfigFileName = NULL; 2191 2192 int j; 2193 2192 2194 setVerbosity(0); 2195 // need to init the history before any action is created 2196 ActionHistory::init(); 2193 2197 /* structure of ParseCommandLineOptions will be refactored later */ 2194 j = ParseCommandLineOptions(argc, argv, World::get ()->getMolecules(), World::get()->getPeriode(), *configuration, ConfigFileName);2198 j = ParseCommandLineOptions(argc, argv, World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName); 2195 2199 switch (j){ 2196 2200 case 255: … … 2202 2206 break; 2203 2207 } 2204 if(World::get ()->numMolecules() == 0){2205 mol = World::get ()->createMolecule();2206 World::get ()->getMolecules()->insert(mol);2208 if(World::getInstance().numMolecules() == 0){ 2209 mol = World::getInstance().createMolecule(); 2210 World::getInstance().getMolecules()->insert(mol); 2207 2211 cout << "Molecule created" << endl; 2208 2212 if(mol->cell_size[0] == 0.){ … … 2225 2229 2226 2230 UIFactory::makeUserInterface(UIFactory::Text); 2227 MainWindow *mainWindow = UIFactory::get ()->makeMainWindow(populaters,World::get()->getMolecules(), configuration, World::get()->getPeriode(), ConfigFileName);2231 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName); 2228 2232 mainWindow->display(); 2229 2233 delete mainWindow; 2230 2234 } 2231 2235 2232 if(World::get ()->getPeriode()->StorePeriodentafel(configuration->databasepath))2236 if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath)) 2233 2237 Log() << Verbose(0) << "Saving of elements.db successful." << endl; 2234 2238 -
src/config.cpp
r9131f3 r4415da 675 675 { 676 676 int MaxTypes = 0; 677 element *elementhash[MAX_ELEMENTS];677 const element *elementhash[MAX_ELEMENTS]; 678 678 char name[MAX_ELEMENTS]; 679 679 char keyword[MAX_ELEMENTS]; … … 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) { … … 1107 1107 string zeile; 1108 1108 string dummy; 1109 element *elementhash[128];1109 const element *elementhash[128]; 1110 1110 int Z = -1; 1111 1111 int No = -1; … … 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/defs.hpp
r9131f3 r4415da 33 33 enum Shading { white, lightgray, darkgray, black }; //!< color in Breadth-First-Search analysis 34 34 35 // some types that can stay abstract 36 typedef unsigned int moleculeId_t; 37 typedef unsigned int atomId_t; 35 38 36 39 37 //enum CutCyclicBond { KeepBond, SaturateBond }; //!< Saturation scheme either atom- or bondwise -
src/element.cpp
r9131f3 r4415da 9 9 10 10 #include "element.hpp" 11 12 using namespace std; 11 13 12 14 /************************************* Functions for class element **********************************/ … … 35 37 * \param *out outstream 36 38 */ 37 bool element::Output(o fstream * const out) const39 bool element::Output(ostream * const out) const 38 40 { 39 41 if (out != NULL) { … … 50 52 * \param NoOfAtoms total number of atom of this element type 51 53 */ 52 bool element::Checkout(o fstream * const out, const int Number, const int NoOfAtoms) const54 bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const 53 55 { 54 56 if (out != NULL) { … … 58 60 return false; 59 61 }; 62 63 atomicNumber_t element::getNumber() const{ 64 return Z; 65 } 66 67 string element::getSymbol() const{ 68 return string(symbol); 69 } -
src/element.hpp
r9131f3 r4415da 9 9 #define ELEMENT_HPP_ 10 10 11 using namespace std;12 13 11 /*********************************************** includes ***********************************/ 14 12 … … 19 17 20 18 #include <iostream> 19 #include <string> 21 20 22 21 #include "defs.hpp" 22 #include "types.hpp" 23 23 24 24 /********************************************** declarations *******************************/ … … 50 50 ~element(); 51 51 52 // accessor functions 53 atomicNumber_t getNumber() const; 54 std::string getSymbol() const; 55 52 56 //> print element entries to screen 53 bool Output( ofstream * const out) const;54 bool Checkout( ofstream * const out, const int No, const int NoOfAtoms) const;57 bool Output(std::ostream * const out) const; 58 bool Checkout(std::ostream * const out, const int No, const int NoOfAtoms) const; 55 59 56 60 private: -
src/errorlogger.cpp
r9131f3 r4415da 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
r9131f3 r4415da 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/helpers.hpp
r9131f3 r4415da 189 189 #define PLURAL_S(v) (((v)==1)?"":"s") 190 190 191 // this is to allow different modes of access for 192 // maps and sets 193 template<typename Res,typename T> 194 struct _take{ 195 Res get(T value) const; 196 }; 197 198 // if we have a set,vector etc we can directly access the result 199 template<typename Res> 200 struct _take<Res,Res>{ 201 static inline Res get(Res value){ 202 return value; 203 } 204 }; 205 206 // if we have a map we have to access the second part of 207 // the pair 208 template<typename Res,typename T1> 209 struct _take<Res,std::pair<T1,Res> >{ 210 static inline Res get(std::pair<T1,Res> value){ 211 return value.second; 212 } 213 }; 214 191 215 #endif /*HELPERS_HPP_*/ -
src/leastsquaremin.hpp
r9131f3 r4415da 42 42 gsl_vector *x; 43 43 const molecule *mol; 44 element *type;44 const element *type; 45 45 }; 46 46 -
src/log.cpp
r9131f3 r4415da 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
r9131f3 r4415da 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
r9131f3 r4415da 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
r9131f3 r4415da 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 … … 99 99 100 100 std::string molecule::calcFormula(){ 101 int Counts[MAX_ELEMENTS];101 std::map<atomicNumber_t,unsigned int> counts; 102 102 stringstream sstr; 103 for (int j = 0; j<MAX_ELEMENTS;j++) 104 Counts[j] = 0; 103 periodentafel *periode = World::getInstance().getPeriode(); 105 104 for(atom *Walker = start; Walker != end; Walker = Walker->next) { 106 Counts[Walker->type->Z]++; 107 } 108 for(element* Elemental = elemente->end; Elemental != elemente->start; Elemental = Elemental->previous) { 109 if (Counts[Elemental->Z] != 0) 110 sstr << Elemental->symbol << Counts[Elemental->Z]; 105 counts[Walker->type->getNumber()]++; 106 } 107 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; 108 for(iter = counts.rbegin(); iter != counts.rend(); ++iter) { 109 atomicNumber_t Z = (*iter).first; 110 sstr << periode->FindElement(Z)->symbol << (*iter).second; 111 111 } 112 112 return sstr.str(); … … 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
r9131f3 r4415da 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
r9131f3 r4415da 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
r9131f3 r4415da 141 141 void MoleculeListClass::Enumerate(ostream *out) 142 142 { 143 element* Elemental = NULL;144 143 atom *Walker = NULL; 145 int Counts[MAX_ELEMENTS]; 144 periodentafel *periode = World::getInstance().getPeriode(); 145 std::map<atomicNumber_t,unsigned int> counts; 146 146 double size=0; 147 147 Vector Origin; … … 155 155 Origin.Zero(); 156 156 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 157 // reset element counts158 for (int j = 0; j<MAX_ELEMENTS;j++)159 Counts[j] = 0;160 157 // count atoms per element and determine size of bounding sphere 161 158 size=0.; … … 163 160 while (Walker->next != (*ListRunner)->end) { 164 161 Walker = Walker->next; 165 Counts[Walker->type->Z]++;162 counts[Walker->type->getNumber()]++; 166 163 if (Walker->x.DistanceSquared(&Origin) > size) 167 164 size = Walker->x.DistanceSquared(&Origin); … … 169 166 // output Index, Name, number of atoms, chemical formula 170 167 (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t"; 171 Elemental = (*ListRunner)->elemente->end; 172 while(Elemental->previous != (*ListRunner)->elemente->start) {173 Elemental = Elemental->previous;174 if (Counts[Elemental->Z] != 0)175 (*out) << Elemental->symbol << Counts[Elemental->Z];168 169 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; 170 for(iter=counts.rbegin(); iter!=counts.rend();++iter){ 171 atomicNumber_t Z =(*iter).first; 172 (*out) << periode->FindElement(Z)->getSymbol() << (*iter).second; 176 173 } 177 174 // Center and size … … 215 212 // remove src 216 213 ListOfMolecules.remove(srcmol); 217 World::get ()->destroyMolecule(srcmol);214 World::getInstance().destroyMolecule(srcmol); 218 215 return true; 219 216 }; … … 580 577 stringstream line; 581 578 atom *Walker = NULL; 582 element *runner = NULL;579 periodentafel *periode=World::getInstance().getPeriode(); 583 580 584 581 // open file for the force factors … … 590 587 //output << prefix << "Forces" << endl; 591 588 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 592 runner = (*ListRunner)->elemente->start; 593 while (runner->next != (*ListRunner)->elemente->end) { // go through every element 594 runner = runner->next; 595 if ((*ListRunner)->ElementsInMolecule[runner->Z]) { // if this element got atoms 589 periodentafel::const_iterator elemIter; 590 for(elemIter=periode->begin();elemIter!=periode->end();++elemIter){ 591 if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms 596 592 Walker = (*ListRunner)->start; 597 593 while (Walker->next != (*ListRunner)->end) { // go through every atom of this element 598 594 Walker = Walker->next; 599 if (Walker->type-> Z == runner->Z) {595 if (Walker->type->getNumber() == (*elemIter).first) { 600 596 if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea 601 597 //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it … … 750 746 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration) 751 747 { 752 molecule *mol = World::get ()->createMolecule();748 molecule *mol = World::getInstance().createMolecule(); 753 749 atom *Walker = NULL; 754 750 atom *Advancer = NULL; … … 775 771 } 776 772 // remove the molecule 777 World::get ()->destroyMolecule(*MolRunner);773 World::getInstance().destroyMolecule(*MolRunner); 778 774 ListOfMolecules.erase(MolRunner); 779 775 } … … 797 793 molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules"); 798 794 for (int i=0;i<MolCount;i++) { 799 molecules[i] = World::get ()->createMolecule();795 molecules[i] = World::getInstance().createMolecule(); 800 796 molecules[i]->ActiveFlag = true; 801 797 strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE); … … 895 891 OBSERVE; 896 892 molecule *mol = NULL; 897 mol = World::get ()->createMolecule();893 mol = World::getInstance().createMolecule(); 898 894 insert(mol); 899 895 }; … … 904 900 char filename[MAXSTRINGSIZE]; 905 901 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl; 906 mol = World::get ()->createMolecule();902 mol = World::getInstance().createMolecule(); 907 903 do { 908 904 Log() << Verbose(0) << "Enter file name: "; … … 962 958 mol = *ListRunner; 963 959 ListOfMolecules.erase(ListRunner); 964 World::get ()->destroyMolecule(mol);960 World::getInstance().destroyMolecule(mol); 965 961 break; 966 962 } … … 1009 1005 // remove the leaf itself 1010 1006 if (Leaf != NULL) { 1011 World::get ()->destroyMolecule(Leaf);1007 World::getInstance().destroyMolecule(Leaf); 1012 1008 Leaf = NULL; 1013 1009 } -
src/periodentafel.cpp
r9131f3 r4415da 10 10 #include <fstream> 11 11 #include <cstring> 12 #include <cassert> 12 13 13 14 #include "element.hpp" … … 18 19 #include "verbose.hpp" 19 20 21 using namespace std; 22 20 23 /************************************* Functions for class periodentafel ***************************/ 21 24 … … 23 26 * Initialises start and end of list and resets periodentafel::checkliste to false. 24 27 */ 25 periodentafel::periodentafel() : start(new element), end(new element) 26 { 27 start->previous = NULL; 28 start->next = end; 29 end->previous = start; 30 end->next = NULL; 31 }; 28 periodentafel::periodentafel() 29 {}; 32 30 33 31 /** destructor for class periodentafel … … 37 35 { 38 36 CleanupPeriodtable(); 39 delete(end);40 delete(start);41 37 }; 42 38 … … 45 41 * \return true - succeeded, false - does not occur 46 42 */ 47 bool periodentafel::AddElement(element * const pointer) 48 { 43 periodentafel::iterator periodentafel::AddElement(element * const pointer) 44 { 45 atomicNumber_t Z = pointer->getNumber(); 46 assert(!elements.count(Z)); 49 47 pointer->sort = &pointer->Z; 50 if (pointer-> Z < 1 && pointer->Z>= MAX_ELEMENTS)48 if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS) 51 49 Log() << Verbose(0) << "Invalid Z number!\n"; 52 return add(pointer, end); 50 pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer)); 51 return res.first; 53 52 }; 54 53 … … 57 56 * \return true - succeeded, false - element not found 58 57 */ 59 bool periodentafel::RemoveElement(element * const pointer) 60 { 61 return remove(pointer, start, end); 58 void periodentafel::RemoveElement(element * const pointer) 59 { 60 atomicNumber_t Z = pointer->getNumber(); 61 elements.erase(Z); 62 62 }; 63 63 … … 65 65 * \return true - succeeded, false - does not occur 66 66 */ 67 bool periodentafel::CleanupPeriodtable() 68 { 69 return cleanup(start,end); 67 void periodentafel::CleanupPeriodtable() 68 { 69 for(iterator iter=elements.begin();iter!=elements.end();++iter){ 70 delete(*iter).second; 71 } 72 elements.clear(); 70 73 }; 71 74 … … 75 78 * \return pointer to element or NULL if not found 76 79 */ 77 element * const periodentafel::FindElement(const int Z) const78 { 79 element *walker = find(&Z, start,end);80 return (walker);80 const element * periodentafel::FindElement(atomicNumber_t Z) const 81 { 82 const_iterator res = elements.find(Z); 83 return res!=elements.end()?((*res).second):0; 81 84 }; 82 85 … … 86 89 * \return pointer to element 87 90 */ 88 element * const periodentafel::FindElement(const char * const shorthand) const 89 { 90 element *walker = periodentafel::start; 91 while (walker->next != periodentafel::end) { 92 walker = walker->next; 93 if (strncmp(walker->symbol, shorthand, 3) == 0) 94 return(walker); 95 } 96 return (NULL); 91 const element * periodentafel::FindElement(const char * const shorthand) const 92 { 93 element *res = 0; 94 for(const_iterator iter=elements.begin();iter!=elements.end();++iter) { 95 if((*iter).second->getSymbol() == shorthand){ 96 res = (*iter).second; 97 break; 98 } 99 } 100 return res; 97 101 }; 98 102 99 103 /** Asks for element number and returns pointer to element 100 104 */ 101 element * constperiodentafel::AskElement() const102 { 103 element *walker = NULL;105 const element * periodentafel::AskElement() const 106 { 107 const element *walker = NULL; 104 108 int Z; 105 109 do { … … 114 118 * \return pointer to either present or newly created element 115 119 */ 116 element * constperiodentafel::EnterElement()117 { 118 element *walker= NULL;119 int Z = -1;120 const element * periodentafel::EnterElement() 121 { 122 const element *res = NULL; 123 atomicNumber_t Z = 0; 120 124 Log() << Verbose(0) << "Atomic number: " << Z << endl; 121 125 cin >> Z; 122 walker = FindElement(Z); 123 if (walker == NULL) { 126 res = FindElement(Z); 127 if (!res) { 128 // TODO: make this using the constructor 129 element *tmp; 124 130 Log() << Verbose(0) << "Element not found in database, please enter." << endl; 125 walker= new element;126 walker->Z = Z;131 tmp = new element; 132 tmp->Z = Z; 127 133 Log() << Verbose(0) << "Mass: " << endl; 128 cin >> walker->mass;134 cin >> tmp->mass; 129 135 Log() << Verbose(0) << "Name [max 64 chars]: " << endl; 130 cin >> walker->name;136 cin >> tmp->name; 131 137 Log() << Verbose(0) << "Short form [max 3 chars]: " << endl; 132 cin >> walker->symbol; 133 periodentafel::AddElement(walker); 134 } 135 return(walker); 136 }; 138 cin >> tmp->symbol; 139 AddElement(tmp); 140 res = tmp; 141 } 142 return res; 143 }; 144 145 146 /******************** Access to iterators ****************************/ 147 periodentafel::const_iterator periodentafel::begin(){ 148 return elements.begin(); 149 } 150 151 periodentafel::const_iterator periodentafel::end(){ 152 return elements.end(); 153 } 154 155 periodentafel::reverse_iterator periodentafel::rbegin(){ 156 return reverse_iterator(elements.end()); 157 } 158 159 periodentafel::reverse_iterator periodentafel::rend(){ 160 return reverse_iterator(elements.begin()); 161 } 137 162 138 163 /** Prints period table to given stream. 139 164 * \param output stream 140 165 */ 141 bool periodentafel::Output(o fstream * const output) const166 bool periodentafel::Output(ostream * const output) const 142 167 { 143 168 bool result = true; 144 element *walker = start;145 169 if (output != NULL) { 146 while (walker->next != end) { 147 walker = walker->next; 148 result = result && walker->Output(output); 170 for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){ 171 result = result && (*iter).second->Output(output); 149 172 } 150 173 return result; … … 157 180 * \param *checkliste elements table for this molecule 158 181 */ 159 bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const 160 { 161 element *walker = start; 182 bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const 183 { 162 184 bool result = true; 163 185 int No = 1; … … 166 188 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl; 167 189 *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl; 168 while (walker->next != end) { 169 walker = walker->next; 170 if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) { 171 walker->No = No; 172 result = result && walker->Checkout(output, No++, checkliste[walker->Z]); 190 for(const_iterator iter=elements.begin(); iter!=elements.end();++iter){ 191 if (((*iter).first < MAX_ELEMENTS) && (checkliste[(*iter).first])) { 192 (*iter).second->No = No; 193 result = result && (*iter).second->Checkout(output, No++, checkliste[(*iter).first]); 173 194 } 174 195 } … … 184 205 { 185 206 ifstream infile; 186 double tmp;187 207 element *ptr; 208 map<atomicNumber_t,element*> parsedElems; 188 209 bool status = true; 189 210 bool otherstatus = true; … … 223 244 //neues->Output((ofstream *)&cout); 224 245 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS)) 225 p eriodentafel::AddElement(neues);246 parsedElems[neues->getNumber()] = neues; 226 247 else { 227 248 Log() << Verbose(0) << "Could not parse element: "; … … 243 264 if (infile != NULL) { 244 265 while (!infile.eof()) { 245 infile >> tmp; 246 infile >> ws; 247 infile >> FindElement((int)tmp)->Valence; 266 atomicNumber_t Z; 267 infile >> Z; 268 infile >> ws; 269 infile >> parsedElems[Z]->Valence; 248 270 infile >> ws; 249 271 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl; … … 261 283 if (infile != NULL) { 262 284 while (!infile.eof()) { 263 infile >> tmp; 264 infile >> ws; 265 infile >> FindElement((int)tmp)->NoValenceOrbitals; 285 atomicNumber_t Z; 286 infile >> Z; 287 infile >> ws; 288 infile >> parsedElems[Z]->NoValenceOrbitals; 266 289 infile >> ws; 267 290 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; … … 279 302 if (infile != NULL) { 280 303 while (!infile.eof()) { 281 infile >> tmp; 282 ptr = FindElement((int)tmp); 304 atomicNumber_t Z; 305 infile >> Z; 306 ptr = parsedElems[Z]; 283 307 infile >> ws; 284 308 infile >> ptr->HBondDistance[0]; … … 300 324 if (infile != NULL) { 301 325 while (!infile.eof()) { 302 infile >> tmp; 303 ptr = FindElement((int)tmp); 326 atomicNumber_t Z; 327 infile >> Z; 328 ptr = parsedElems[Z]; 304 329 infile >> ws; 305 330 infile >> ptr->HBondAngle[0]; … … 313 338 otherstatus = false; 314 339 315 if (!otherstatus) 340 if (otherstatus){ 341 map<atomicNumber_t,element*>::iterator iter; 342 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){ 343 AddElement((*iter).second); 344 } 345 } 346 else{ 316 347 eLog() << Verbose(2) << "Something went wrong while parsing the other databases!" << endl; 348 map<atomicNumber_t,element*>::iterator iter; 349 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){ 350 AddElement((*iter).second); 351 } 352 } 317 353 318 354 return status; … … 334 370 f << header1 << endl; 335 371 f << header2 << endl; 336 element *walker = periodentafel::start; 337 while (walker->next != periodentafel::end) { 338 walker = walker->next; 339 result = result && walker->Output(&f); 372 for(const_iterator iter=elements.begin();iter!=elements.end();++iter){ 373 result = result && (*iter).second->Output(&f); 340 374 } 341 375 f.close(); -
src/periodentafel.hpp
r9131f3 r4415da 1 1 #ifndef PERIODENTAFEL_HPP_ 2 2 #define PERIODENTAFEL_HPP_ 3 4 using namespace std;5 3 6 4 /*********************************************** includes ***********************************/ … … 12 10 13 11 #include <iostream> 12 #include <map> 13 #include <iterator> 14 14 15 15 #include "defs.hpp" 16 #include "types.hpp" 16 17 17 18 /****************************************** forward declarations *****************************/ … … 25 26 */ 26 27 class periodentafel { 28 /******* Types *********/ 29 private: 30 typedef std::map<atomicNumber_t,element*> elementSet; 27 31 public: 28 element *start; //!< start of element list 29 element *end; //!< end of element list 32 typedef elementSet::iterator iterator; 33 typedef elementSet::const_iterator const_iterator; 34 typedef std::reverse_iterator<const_iterator> reverse_iterator; 35 public: 36 30 37 char header1[MAXSTRINGSIZE]; //!< store first header line 31 38 char header2[MAXSTRINGSIZE]; //!< store second header line … … 34 41 ~periodentafel(); 35 42 36 bool AddElement(element * const pointer); 37 bool RemoveElement(element * const pointer); 38 bool CleanupPeriodtable(); 39 element * const FindElement(const int Z) const; 40 element * const FindElement(const char * const shorthand) const; 41 element * const AskElement() const; 42 element * const EnterElement(); 43 bool Output(ofstream * const output) const; 44 bool Checkout(ofstream * const output, const int * const checkliste) const; 43 iterator AddElement(element * const pointer); 44 void RemoveElement(element * const pointer); 45 void CleanupPeriodtable(); 46 const element *FindElement(atomicNumber_t) const; 47 const element *FindElement(const char * const shorthand) const; 48 const element *AskElement() const; 49 const element *EnterElement(); 50 51 const_iterator begin(); 52 const_iterator end(); 53 reverse_iterator rbegin(); 54 reverse_iterator rend(); 55 bool Output(std::ostream * const output) const; 56 bool Checkout(std::ostream * const output, const int * const checkliste) const; 45 57 bool LoadPeriodentafel(const char * const path); 46 58 bool StorePeriodentafel(const char * const path) const; 47 59 48 60 private: 61 elementSet elements; 49 62 }; 50 63 -
src/unittests/ActionSequenceTest.cpp
r9131f3 r4415da 35 35 virtual ~canUndoActionStub(){} 36 36 37 virtual void call(){} 38 virtual void undo(){} 37 virtual Action::state_ptr performCall(){ 38 return Action::success; 39 } 40 virtual Action::state_ptr performUndo(Action::state_ptr){ 41 return Action::success; 42 } 43 virtual Action::state_ptr performRedo(Action::state_ptr){ 44 return Action::success; 45 } 39 46 virtual bool canUndo(){ 47 return true; 48 } 49 virtual bool shouldUndo(){ 40 50 return true; 41 51 } … … 48 58 virtual ~cannotUndoActionStub(){} 49 59 50 virtual void call(){} 51 virtual void undo(){} 60 virtual Action::state_ptr performCall(){ 61 return Action::success; 62 } 63 virtual Action::state_ptr performUndo(Action::state_ptr){ 64 return Action::success; 65 } 66 virtual Action::state_ptr performRedo(Action::state_ptr){ 67 return Action::success; 68 } 52 69 virtual bool canUndo(){ 53 70 return false; 71 } 72 virtual bool shouldUndo(){ 73 return true; 54 74 } 55 75 }; … … 64 84 virtual ~wasCalledActionStub(){} 65 85 66 virtual void call(){86 virtual Action::state_ptr performCall(){ 67 87 called = true; 68 } 69 virtual void undo(){ 88 return Action::success; 89 } 90 virtual Action::state_ptr performUndo(Action::state_ptr){ 70 91 called = false; 92 return Action::success; 93 } 94 virtual Action::state_ptr performRedo(Action::state_ptr){ 95 called = true; 96 return Action::success; 71 97 } 72 98 virtual bool canUndo(){ 99 return true; 100 } 101 virtual bool shouldUndo(){ 73 102 return true; 74 103 } … … 185 214 sequence->addAction(shouldCall2); 186 215 187 sequence->callAll();188 189 sequence->removeLastAction(); 190 sequence->removeLastAction(); 191 192 sequence->undoAll( );216 ActionSequence::stateSet states = sequence->callAll(); 217 218 sequence->removeLastAction(); 219 sequence->removeLastAction(); 220 221 sequence->undoAll(states); 193 222 194 223 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled()); -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
r9131f3 r4415da 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
r9131f3 r4415da 27 27 #include "World.hpp" 28 28 29 #include "Helpers/Assert.hpp" 30 29 31 #ifdef HAVE_TESTRUNNER 30 32 #include "UnitTestMain.hpp" … … 38 40 void AnalysisCorrelationToSurfaceUnitTest::setUp() 39 41 { 42 ASSERT_DO(Assert::Throw); 43 40 44 atom *Walker = NULL; 41 45 … … 61 65 62 66 // construct periodentafel 63 tafel = World::get ()->getPeriode();67 tafel = World::getInstance().getPeriode(); 64 68 tafel->AddElement(hydrogen); 65 69 tafel->AddElement(carbon); 66 70 67 71 // construct molecule (tetraeder of hydrogens) base 68 TestMolecule = World::get ()->createMolecule();69 Walker = World::get ()->createAtom();72 TestMolecule = World::getInstance().createMolecule(); 73 Walker = World::getInstance().createAtom(); 70 74 Walker->type = hydrogen; 71 75 Walker->node->Init(1., 0., 1. ); 72 76 TestMolecule->AddAtom(Walker); 73 Walker = World::get ()->createAtom();77 Walker = World::getInstance().createAtom(); 74 78 Walker->type = hydrogen; 75 79 Walker->node->Init(0., 1., 1. ); 76 80 TestMolecule->AddAtom(Walker); 77 Walker = World::get ()->createAtom();81 Walker = World::getInstance().createAtom(); 78 82 Walker->type = hydrogen; 79 83 Walker->node->Init(1., 1., 0. ); 80 84 TestMolecule->AddAtom(Walker); 81 Walker = World::get ()->createAtom();85 Walker = World::getInstance().createAtom(); 82 86 Walker->type = hydrogen; 83 87 Walker->node->Init(0., 0., 0. ); … … 87 91 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 88 92 89 TestList = World::get ()->getMolecules();93 TestList = World::getInstance().getMolecules(); 90 94 TestMolecule->ActiveFlag = true; 91 95 TestList->insert(TestMolecule); … … 100 104 101 105 // add outer atoms 102 Walker = World::get ()->createAtom();106 Walker = World::getInstance().createAtom(); 103 107 Walker->type = carbon; 104 108 Walker->node->Init(4., 0., 4. ); 105 109 TestMolecule->AddAtom(Walker); 106 Walker = World::get ()->createAtom();110 Walker = World::getInstance().createAtom(); 107 111 Walker->type = carbon; 108 112 Walker->node->Init(0., 4., 4. ); 109 113 TestMolecule->AddAtom(Walker); 110 Walker = World::get ()->createAtom();114 Walker = World::getInstance().createAtom(); 111 115 Walker->type = carbon; 112 116 Walker->node->Init(4., 4., 0. ); 113 117 TestMolecule->AddAtom(Walker); 114 118 // add inner atoms 115 Walker = World::get ()->createAtom();119 Walker = World::getInstance().createAtom(); 116 120 Walker->type = carbon; 117 121 Walker->node->Init(0.5, 0.5, 0.5 ); … … 135 139 // note that all the atoms are cleaned by TestMolecule 136 140 delete(LC); 137 World:: destroy();141 World::purgeInstance(); 138 142 MemoryUsageObserver::purgeInstance(); 139 143 logger::purgeInstance(); -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
r9131f3 r4415da 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
r9131f3 r4415da 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)); 141 141 } 142 143 142 // exclude and include some atoms 144 143 { 145 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));144 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2]))); 146 145 std::set<atomId_t> excluded; 147 146 excluded.insert(atomIds[ATOM_COUNT/2]); … … 152 151 153 152 { 154 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));153 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2]))); 155 154 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 156 155 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId()); -
src/unittests/AtomDescriptorTest.hpp
r9131f3 r4415da 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include " defs.hpp"13 #include "types.hpp" 14 14 15 15 #define ATOM_COUNT (10) -
src/unittests/CacheableTest.cpp
r9131f3 r4415da 27 27 class threeNumbers : public Observable { 28 28 public: 29 bool hasRecalced;30 29 int x; 31 30 int y; 32 31 int z; 32 Cacheable<int> sum; 33 bool hasRecalced; 33 34 34 35 void setX(int _x){ … … 54 55 55 56 threeNumbers(int _x,int _y, int _z) : 57 x(_x),y(_y),z(_z), 56 58 sum(this,boost::bind(&threeNumbers::calcSum,this)), 57 x(_x),y(_y),z(_z),58 59 hasRecalced(false) 59 60 {} 60 61 Cacheable<int> sum;62 61 }; 63 62 -
src/unittests/Makefile.am
r9131f3 r4415da 29 29 ObserverTest \ 30 30 ParserUnitTest \ 31 SingletonTest \ 31 32 StackClassUnitTest \ 32 33 TesselationUnitTest \ … … 68 69 ObserverTest.cpp \ 69 70 ParserUnitTest.cpp \ 71 SingletonTest.cpp \ 70 72 stackclassunittest.cpp \ 71 73 tesselationunittest.cpp \ … … 91 93 AnalysisPairCorrelationUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp 92 94 AnalysisPairCorrelationUnitTest_LDADD = ${ALLLIBS} 95 96 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp 97 atomsCalculationTest_LDADD = ${ALLLIBS} 93 98 94 99 BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp … … 125 130 MoleculeDescriptorTest_LDADD = ${ALLLIBS} 126 131 132 SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp 133 SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB} 134 127 135 StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp 128 136 StackClassUnitTest_LDADD = ${ALLLIBS} … … 158 166 manipulateAtomsTest_LDADD = ${ALLLIBS} 159 167 160 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp161 atomsCalculationTest_LDADD = ${ALLLIBS}162 163 168 TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS) 164 169 TestRunner_LDADD = ${ALLLIBS} -
src/unittests/MoleculeDescriptorTest.cpp
r9131f3 r4415da 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/MoleculeDescriptorTest.hpp
r9131f3 r4415da 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include " defs.hpp"13 #include "types.hpp" 14 14 15 15 #define MOLECULE_COUNT (10) -
src/unittests/ObserverTest.cpp
r9131f3 r4415da 13 13 14 14 #include "Patterns/Observer.hpp" 15 #include "Helpers/Assert.hpp" 15 16 16 17 #include <iostream> … … 65 66 }; 66 67 68 class BlockObservable : public Observable { 69 public: 70 void changeMethod1(){ 71 OBSERVE; 72 // test if we report correctly as blocked 73 CPPUNIT_ASSERT(isBlocked()); 74 } 75 76 void changeMethod2(){ 77 OBSERVE; 78 internalMethod1(); 79 internalMethod2(); 80 } 81 82 void internalMethod1(){ 83 // we did not block, but our caller did... 84 // see if this is found 85 CPPUNIT_ASSERT(isBlocked()); 86 } 87 88 void internalMethod2(){ 89 OBSERVE; 90 // Both this method and the caller do block 91 // Does the reporting still work as expected? 92 CPPUNIT_ASSERT(isBlocked()); 93 } 94 95 void noChangeMethod(){ 96 // No Block introduced here 97 // reported correctely? 98 CPPUNIT_ASSERT(!isBlocked()); 99 } 100 }; 101 67 102 class SuperObservable : public Observable { 68 103 public: … … 86 121 87 122 void ObserverTest::setUp() { 123 ASSERT_DO(Assert::Throw); 88 124 simpleObservable1 = new SimpleObservable(); 89 125 simpleObservable2 = new SimpleObservable(); 90 126 callObservable = new CallObservable(); 91 127 superObservable = new SuperObservable(); 128 blockObservable = new BlockObservable(); 92 129 93 130 observer1 = new UpdateCountObserver(); … … 163 200 } 164 201 202 void ObserverTest::doesReportTest(){ 203 // Actual checks are in the Stub-methods for this 204 blockObservable->changeMethod1(); 205 blockObservable->changeMethod2(); 206 blockObservable->noChangeMethod(); 207 } 165 208 166 209 void ObserverTest::CircleDetectionTest() { … … 174 217 // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE 175 218 simpleObservable1->signOn(simpleObservable1); 176 simpleObservable1->changeMethod();219 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 177 220 178 221 // more complex test … … 180 223 simpleObservable1->signOn(simpleObservable2); 181 224 simpleObservable2->signOn(simpleObservable1); 182 simpleObservable1->changeMethod();225 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 183 226 simpleObservable1->signOff(simpleObservable2); 184 227 simpleObservable2->signOff(simpleObservable1); -
src/unittests/ObserverTest.hpp
r9131f3 r4415da 16 16 class CallObservable; 17 17 class SuperObservable; 18 class BlockObservable; 18 19 19 20 … … 24 25 CPPUNIT_TEST ( doesBlockUpdateTest ); 25 26 CPPUNIT_TEST ( doesSubObservableTest ); 27 CPPUNIT_TEST ( doesReportTest ); 26 28 CPPUNIT_TEST ( CircleDetectionTest ); 27 29 CPPUNIT_TEST_SUITE_END(); … … 34 36 void doesBlockUpdateTest(); 35 37 void doesSubObservableTest(); 38 void doesReportTest(); 36 39 void CircleDetectionTest(); 37 40 … … 45 48 SimpleObservable *simpleObservable2; 46 49 CallObservable *callObservable; 50 BlockObservable *blockObservable; 47 51 SuperObservable *superObservable; 48 52 }; -
src/unittests/ParserUnitTest.cpp
r9131f3 r4415da 32 32 oxygen->symbol[0] = 'O'; 33 33 oxygen->Z = 8; 34 World::get ()->getPeriode()->AddElement(oxygen);34 World::getInstance().getPeriode()->AddElement(oxygen); 35 35 36 36 element* hydrogen = new element(); 37 37 hydrogen->symbol[0] = 'H'; 38 38 hydrogen->Z = 1; 39 World::get ()->getPeriode()->AddElement(hydrogen);39 World::getInstance().getPeriode()->AddElement(hydrogen); 40 40 } 41 41 … … 53 53 testParser->load(&input); 54 54 55 CPPUNIT_ASSERT_EQUAL(3, World::get ()->numAtoms());55 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 56 56 57 57 string newWaterXyz = ""; … … 66 66 cout << "Testing the tremolo parser." << endl; 67 67 TremoloParser* testParser = new TremoloParser(); 68 stringstream input; 69 70 // Atomdata beginning with "# ATOMDATA" 68 71 string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n"; 69 stringstream input;70 72 input << waterTremolo; 71 73 testParser->load(&input); 74 input.clear(); 75 76 // Atomdata beginning with "#ATOMDATA" 72 77 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n"; 73 input.clear();74 78 input << waterTremolo; 75 79 testParser->load(&input); 80 input.clear(); 81 82 // One simple data line 83 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n"; 84 input << waterTremolo; 85 testParser->load(&input); 86 input.clear(); 87 88 // Invalid key in Atomdata line 89 waterTremolo = "#\n#ATOMDATA Id name foo Type x=3\n\n\n"; 90 input << waterTremolo; 91 testParser->load(&input); 92 input.clear(); 93 76 94 cout << "testing the tremolo parser is done" << endl; 77 95 } -
src/unittests/analysisbondsunittest.cpp
r9131f3 r4415da 53 53 strcpy(hydrogen->symbol, "H"); 54 54 carbon = new element; 55 carbon->Z = 1;55 carbon->Z = 2; 56 56 carbon->Valence = 4; 57 57 carbon->NoValenceOrbitals = 4; … … 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
r9131f3 r4415da 24 24 #include "atom.hpp" 25 25 26 #ifdef HAVE_TESTRUNNER 27 #include "UnitTestMain.hpp" 28 #endif /*HAVE_TESTRUNNER*/ 29 26 30 // Registers the fixture into the 'registry' 27 31 CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest ); 28 32 29 // some stubs30 class AtomStub : public atom {31 public:32 AtomStub(atomId_t _id) :33 atom(),34 id(_id),35 manipulated(false)36 {}37 38 virtual atomId_t getId(){39 return id;40 }41 42 virtual void doSomething(){43 manipulated = true;44 }45 46 bool manipulated;47 private:48 atomId_t id;49 };50 51 33 // set up and tear down 52 34 void atomsCalculationTest::setUp(){ 53 World::get ();35 World::getInstance(); 54 36 for(int i=0;i<ATOM_COUNT;++i){ 55 atoms[i]= new AtomStub(i);56 World::get()->registerAtom(atoms[i]);37 atoms[i]= World::getInstance().createAtom(); 38 atomIds[i]= atoms[i]->getId(); 57 39 } 58 40 } 59 41 void atomsCalculationTest::tearDown(){ 60 World:: destroy();61 ActionRegistry::purge Registry();42 World::purgeInstance(); 43 ActionRegistry::purgeInstance(); 62 44 } 63 45 64 46 // some helper functions 65 static bool hasAll(std::vector<int> ids,int min, int max, std::set<int> excluded = std::set<int>()){ 66 for(int i=min;i<max;++i){ 67 if(!excluded.count(i)){ 68 std::vector<int>::iterator iter; 47 static bool hasAllIds(std::vector<atomId_t> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){ 48 for(int i=0;i<ATOM_COUNT;++i){ 49 atomId_t id = ids[i]; 50 if(!excluded.count(id)){ 51 std::vector<atomId_t>::iterator iter; 69 52 bool res=false; 70 for(iter= ids.begin();iter!=ids.end();++iter){71 res |= (*iter) == i ;53 for(iter=atoms.begin();iter!=atoms.end();++iter){ 54 res |= (*iter) == id; 72 55 } 73 56 if(!res) { 74 cout << "Atom " << i << " missing in returned list" << endl;57 cout << "Atom " << id << " missing in returned list" << endl; 75 58 return false; 76 59 } … … 80 63 } 81 64 82 static bool hasNoDuplicates(std::vector< int> ids){83 std::set< int> found;84 std::vector< int>::iterator iter;65 static bool hasNoDuplicates(std::vector<atomId_t> ids){ 66 std::set<atomId_t> found; 67 std::vector<atomId_t>::iterator iter; 85 68 for(iter=ids.begin();iter!=ids.end();++iter){ 86 69 int id = (*iter); … … 92 75 } 93 76 94 static void operation(atom* _atom){95 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);96 assert(atom);97 atom->doSomething();98 }99 100 101 77 void atomsCalculationTest::testCalculateSimple(){ 102 AtomsCalculation< int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());103 std::vector< int> allIds = (*calc)();104 CPPUNIT_ASSERT(hasAll (allIds,0,ATOM_COUNT));78 AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms()); 79 std::vector<atomId_t> allIds = (*calc)(); 80 CPPUNIT_ASSERT(hasAllIds(allIds,atomIds)); 105 81 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 106 82 } 107 83 108 84 void atomsCalculationTest::testCalculateExcluded(){ 109 int excluded = ATOM_COUNT/2;110 AtomsCalculation< int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));111 std::vector< int> allIds = (*calc)();112 std::set< int> excluded_set;85 atomId_t excluded = atomIds[ATOM_COUNT/2]; 86 AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded)); 87 std::vector<atomId_t> allIds = (*calc)(); 88 std::set<atomId_t> excluded_set; 113 89 excluded_set.insert(excluded); 114 CPPUNIT_ASSERT(hasAll (allIds,0,ATOM_COUNT,excluded_set));90 CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set)); 115 91 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 116 92 CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size()); -
src/unittests/atomsCalculationTest.hpp
r9131f3 r4415da 12 12 13 13 #define ATOM_COUNT (10) 14 15 #include "types.hpp" 14 16 15 17 class atom; … … 31 33 private: 32 34 atom *atoms [ATOM_COUNT]; 33 int atomIds [ATOM_COUNT];35 atomId_t atomIds [ATOM_COUNT]; 34 36 }; 35 37 -
src/unittests/bondgraphunittest.cpp
r9131f3 r4415da 51 51 strcpy(hydrogen->symbol, "H"); 52 52 carbon = new element; 53 carbon->Z = 1;53 carbon->Z = 2; 54 54 strcpy(carbon->name, "carbon"); 55 55 strcpy(carbon->symbol, "C"); … … 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
r9131f3 r4415da 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
r9131f3 r4415da 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
r9131f3 r4415da 18 18 #include "Actions/ManipulateAtomsProcess.hpp" 19 19 #include "Actions/ActionRegistry.hpp" 20 #include "Actions/ActionHistory.hpp" 20 21 21 22 #include "World.hpp" 22 23 #include "atom.hpp" 24 25 #ifdef HAVE_TESTRUNNER 26 #include "UnitTestMain.hpp" 27 #endif /*HAVE_TESTRUNNER*/ 23 28 24 29 // Registers the fixture into the 'registry' … … 30 35 AtomStub(int _id) : 31 36 atom(), 32 id(_id),33 manipulated(false)37 manipulated(false), 38 id(_id) 34 39 {} 35 40 … … 66 71 // set up and tear down 67 72 void manipulateAtomsTest::setUp(){ 68 World::get(); 73 ActionHistory::init(); 74 World::getInstance(); 69 75 for(int i=0;i<ATOM_COUNT;++i){ 70 76 atoms[i]= new AtomStub(i); 71 World::get ()->registerAtom(atoms[i]);77 World::getInstance().registerAtom(atoms[i]); 72 78 } 73 79 } 74 80 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; 81 World::purgeInstance(); 82 ActionRegistry::purgeInstance(); 83 ActionHistory::purgeInstance(); 107 84 } 108 85 … … 115 92 116 93 void manipulateAtomsTest::testManipulateSimple(){ 117 ManipulateAtomsProcess *proc = World::get ()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());94 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms()); 118 95 proc->call(); 119 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());96 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 120 97 std::vector<atom*>::iterator iter; 121 98 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){ … … 128 105 129 106 void manipulateAtomsTest::testManipulateExcluded(){ 130 ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2)); 107 108 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2)); 131 109 proc->call(); 132 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());110 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 133 111 std::vector<atom*>::iterator iter; 134 112 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){ … … 145 123 void manipulateAtomsTest::testObserver(){ 146 124 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));125 World::getInstance().signOn(obs); 126 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms()); 149 127 proc->call(); 150 128 151 129 CPPUNIT_ASSERT_EQUAL(1,obs->count); 152 World::get ()->signOff(obs);130 World::getInstance().signOff(obs); 153 131 delete obs; 154 132 }
Note:
See TracChangeset
for help on using the changeset viewer.