Changes in / [9131f3:4415da]


Ignore:
Files:
13 added
1 deleted
95 edited

Legend:

Unmodified
Added
Removed
  • doc/Doxyfile

    r9131f3 r4415da  
    127127#---------------------------------------------------------------------------
    128128SOURCE_BROWSER         = YES
    129 INLINE_SOURCES         = NO
    130 STRIP_CODE_COMMENTS    = YES
     129INLINE_SOURCES         = YES
     130STRIP_CODE_COMMENTS    = NO
    131131REFERENCED_BY_RELATION = NO
    132132REFERENCES_RELATION    = NO
  • src/Actions/Action.cpp

    r9131f3 r4415da  
    1010#include "Actions/Action.hpp"
    1111#include "Actions/ActionRegistry.hpp"
     12#include "Actions/ActionHistory.hpp"
    1213
    1314using namespace std;
     15
     16// An empty state to indicate success
     17Action::state_ptr Action::success = Action::state_ptr(new ActionState());
     18Action::state_ptr Action::failure = Action::state_ptr(new ActionState());
    1419
    1520Action::Action(std::string _name,bool _doRegister) :
     
    1722{
    1823  if(_doRegister){
    19     ActionRegistry::getRegistry()->registerAction(this);
     24    ActionRegistry::getInstance().registerAction(this);
    2025  }
    2126}
     
    2732  return name;
    2833}
     34
     35void 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}
     47Action::state_ptr Action::undo(state_ptr _state) {
     48  // forward to private virtual
     49  return performUndo(_state);
     50}
     51Action::state_ptr Action::redo(state_ptr _state) {
     52  // forward to private virtual
     53  return performRedo(_state);
     54}
     55
     56
     57bool Action::isActive(){
     58  return true;
     59}
  • src/Actions/Action.hpp

    r9131f3 r4415da  
    1010
    1111#include <string>
     12#include <boost/shared_ptr.hpp>
     13
     14// forward declaration
     15
     16class ActionState;
     17class ActionSequence;
    1218
    1319/**
     
    2127class Action
    2228{
    23 protected:
     29friend class ActionSequence;
    2430public:
     31
     32  typedef boost::shared_ptr<ActionState> state_ptr;
     33
    2534  Action(std::string _name,bool _doRegister=true);
    2635  virtual ~Action();
    2736
    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
    3043  virtual bool canUndo()=0;
    31   //virtual bool shouldUndo()=0;
     44  virtual bool shouldUndo()=0;
     45
     46  virtual bool isActive();
    3247
    3348  virtual const std::string getName();
    3449
     50protected:
     51  static state_ptr success;
     52  static state_ptr failure;
     53
    3554private:
     55  virtual state_ptr performCall()=0;
     56  virtual state_ptr performUndo(state_ptr)=0;
     57  virtual state_ptr performRedo(state_ptr)=0;
     58
    3659  std::string name;
    3760};
    3861
     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 */
     69class ActionState{
     70public:
     71  ActionState(){}
     72  virtual ~ActionState(){}
     73};
     74
    3975#endif /* ACTION_H_ */
  • src/Actions/ActionRegistry.cpp

    r9131f3 r4415da  
    99#include "Actions/Action.hpp"
    1010
     11#include "Patterns/Singleton_impl.hpp"
     12
    1113#include <string>
    12 #include <cassert>
     14#include "Helpers/Assert.hpp"
    1315#include <iostream>
    1416
    1517using namespace std;
    16 
    17 ActionRegistry *ActionRegistry::theInstance=0;
    1818
    1919ActionRegistry::ActionRegistry()
     
    3333  map<const string,Action*>::iterator iter;
    3434  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");
    3636  return iter->second;
    3737}
     
    4040  pair<map<const string,Action*>::iterator,bool> ret;
    4141  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");
    4343}
    4444
    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 }
     45CONSTRUCT_SINGLETON(ActionRegistry)
  • src/Actions/ActionRegistry.hpp

    r9131f3 r4415da  
    1212#include <map>
    1313
     14#include "Patterns/Singleton.hpp"
     15
    1416class Action;
    1517
    16 class ActionRegistry
     18class ActionRegistry : public Singleton<ActionRegistry>
    1719{
     20  friend class Singleton<ActionRegistry>;
    1821public:
    1922  Action* getActionByName(const std::string);
     
    2326  std::map<const std::string,Action*> actionMap;
    2427
    25 // singleton stuff
    26 public:
    27   static ActionRegistry* getRegistry();
    28   static void purgeRegistry();
    2928private:
    3029  ActionRegistry();
    3130  virtual ~ActionRegistry();
    32   static ActionRegistry *theInstance;
    3331};
    3432
  • src/Actions/ActionSequence.cpp

    r9131f3 r4415da  
    88#include "Actions/ActionSequence.hpp"
    99#include "Actions/Action.hpp"
     10
     11#include "Helpers/Assert.hpp"
    1012
    1113using namespace std;
     
    3436}
    3537
    36 void ActionSequence::callAll(){
    37   deque<Action*>::iterator it;
    38   for(it=actions.begin(); it!=actions.end(); it++)
    39     (*it)->call();
     38ActionSequence::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;
    4047}
    4148
    42 void ActionSequence::undoAll(){
    43   deque<Action*>::reverse_iterator rit;
    44   for(rit=actions.rbegin(); rit!=actions.rend(); rit++)
    45     (*rit)->undo();
     49ActionSequence::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
     69ActionSequence::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;
    4684}
    4785
    4886bool ActionSequence::canUndo(){
    4987  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  }
    5393  return canUndo;
    5494}
     95
     96bool 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  
    99#define ACTIONSEQUENZE_HPP_
    1010
     11#include "Actions/Action.hpp"
     12
    1113#include <deque>
    12 
    13 class Action;
    1414
    1515/**
     
    1919{
    2020public:
     21  typedef std::deque<Action*> actionSet;
     22  typedef std::deque<Action::state_ptr> stateSet;
     23
    2124  ActionSequence();
    2225  virtual ~ActionSequence();
     
    2528  Action* removeLastAction();
    2629
    27   void callAll();
    28   void undoAll();
     30  stateSet callAll();
     31  stateSet undoAll(stateSet);
     32  stateSet redoAll(stateSet);
    2933
    3034  bool canUndo();
     35  bool shouldUndo();
    3136
    3237private:
    33   std::deque<Action*> actions;
     38  actionSet actions;
    3439};
    3540
  • src/Actions/AtomsCalculation_impl.hpp

    r9131f3 r4415da  
    1919AtomsCalculation<T>::AtomsCalculation(boost::function<T(atom*)> _op,std::string name,AtomDescriptor _descr) :
    2020  Calculation<std::vector<T> >(0,name,false),
    21   op(_op),
    22   descr(_descr)
     21  descr(_descr),
     22  op(_op)
    2323{}
    2424
     
    2929template<typename T>
    3030std::vector<T>* AtomsCalculation<T>::doCalc(){
    31   World* world = World::get();
     31  World* world = World::getPointer();
    3232  int steps = world->numAtoms();
    33   int count = 0;
    3433  std::vector<T> *res = new std::vector<T>();
    3534  res->reserve(steps);
    3635  Process::setMaxSteps(steps);
    3736  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){
    4038    Process::setCurrStep(iter.getCount());
    4139    res->push_back(op(*iter));
  • src/Actions/Calculation.hpp

    r9131f3 r4415da  
    2929   * from menu Items or other places.
    3030   */
    31   virtual void call();
    32   virtual void undo();
    3331  virtual bool canUndo();
     32
     33  virtual bool shouldUndo();
    3434
    3535  /**
     
    6464  virtual T* doCalc()=0;
    6565private:
     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
    6670  bool done;
    6771};
  • src/Actions/Calculation_impl.hpp

    r9131f3 r4415da  
    1616Calculation<T>::Calculation(int _maxSteps, std::string _name, bool _doRegister) :
    1717  Process(_maxSteps,_name,_doRegister),
    18   done(false),
    19   result(0)
     18  result(0),
     19  done(false)
    2020{}
    2121
     
    2929
    3030template<typename T>
    31 void Calculation<T>::call(){
     31Action::state_ptr Calculation<T>::performCall(){
    3232  reset();
    3333  (*this)();
     34  return Action::success;
    3435}
    3536
    3637template<typename T>
    37 void Calculation<T>::undo(){}
     38Action::state_ptr Calculation<T>::performUndo(Action::state_ptr){
     39  ASSERT(0,"Cannot undo a calculation");
     40  return Action::success;
     41}
     42template<typename T>
     43Action::state_ptr Calculation<T>::performRedo(Action::state_ptr){
     44  ASSERT(0,"Cannot redo a calculation");
     45  return Action::success;
     46}
    3847
    3948template<typename T>
    4049bool Calculation<T>::canUndo()
     50{
     51  return false;
     52}
     53
     54template<typename T>
     55bool Calculation<T>::shouldUndo()
    4156{
    4257  return false;
  • src/Actions/ErrorAction.cpp

    r9131f3 r4415da  
    1111#include "log.hpp"
    1212#include "verbose.hpp"
     13#include "Helpers/Assert.hpp"
    1314
    1415using namespace std;
     
    2425}
    2526
    26 void ErrorAction::call() {
     27Action::state_ptr ErrorAction::performCall() {
    2728  Log() << Verbose(0) << errorMsg << endl;
     29  return Action::success;
    2830}
    29 void ErrorAction::undo() {
     31Action::state_ptr ErrorAction::performUndo(Action::state_ptr) {
     32  ASSERT(0,"Undo called for an ErrorAction");
     33  return Action::success;
     34}
     35
     36Action::state_ptr ErrorAction::performRedo(Action::state_ptr) {
     37  ASSERT(0,"Redo called for an ErrorAction");
     38  return Action::success;
    3039}
    3140
     
    3342  return false;
    3443}
     44
     45bool ErrorAction::shouldUndo(){
     46  return false;
     47}
  • src/Actions/ErrorAction.hpp

    r9131f3 r4415da  
    1818  virtual ~ErrorAction();
    1919
    20   virtual void call();
    21   virtual void undo();
    2220  virtual bool canUndo();
     21  virtual bool shouldUndo();
    2322
    2423private:
     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
    2529  std::string errorMsg;
    2630};
  • src/Actions/MakroAction.cpp

    r9131f3 r4415da  
    1111#include "Actions/Action.hpp"
    1212#include "Actions/ActionSequence.hpp"
     13#include "Helpers/Assert.hpp"
    1314
    1415using namespace std;
     16
     17class MakroActionState : public ActionState{
     18public:
     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};
    1528
    1629MakroAction::MakroAction(string _name,ActionSequence* _actions,bool _doRegister) :
     
    3043
    3144
    32 void MakroAction::call(){
    33   actions->callAll();
     45Action::state_ptr MakroAction::performCall(){
     46  ActionSequence::stateSet states = actions->callAll();
     47  return Action::state_ptr(new MakroActionState(states));
    3448}
    3549
    36 void MakroAction::undo() {
    37   actions->undoAll();
     50Action::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
     57Action::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));
    3862}
    3963
     
    4165  return actions->canUndo();
    4266}
     67
     68bool MakroAction::shouldUndo() {
     69  return actions->shouldUndo();
     70}
  • src/Actions/MakroAction.hpp

    r9131f3 r4415da  
    2626  virtual ~MakroAction();
    2727
    28   virtual void call();
    29   virtual void undo();
    30   virtual bool canUndo();
     28  bool canUndo();
     29  bool shouldUndo();
    3130
    3231private:
     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
    3336  ActionSequence *actions;
    3437};
  • src/Actions/ManipulateAtomsProcess.cpp

    r9131f3 r4415da  
    99
    1010#include <iostream>
     11
     12#include "World.hpp"
     13#include "Helpers/Assert.hpp"
    1114
    1215using namespace std;
     
    2225{}
    2326
    24 void ManipulateAtomsProcess::call(){
    25   World::get()->doManipulate(this);
     27Action::state_ptr ManipulateAtomsProcess::performCall(){
     28  World::getInstance().doManipulate(this);
     29  return Action::success;
    2630}
    2731
    28 void ManipulateAtomsProcess::undo(){
     32Action::state_ptr ManipulateAtomsProcess::performUndo(Action::state_ptr){
     33  ASSERT(0,"Undo called for a ManipulateAtomsProcess");
     34  return Action::success;
     35}
    2936
     37Action::state_ptr ManipulateAtomsProcess::performRedo(Action::state_ptr){
     38  ASSERT(0,"Redo called for a ManipulateAtomsProcess");
     39  return Action::success;
    3040}
    3141
     
    3444}
    3545
     46bool ManipulateAtomsProcess::shouldUndo(){
     47  return true;
     48}
     49
    3650void ManipulateAtomsProcess::doManipulate(World *world){
    3751  setMaxSteps(world->numAtoms());
    3852  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){
    4154    setCurrStep(iter.getCount());
    4255    operation(*iter);
  • src/Actions/ManipulateAtomsProcess.hpp

    r9131f3 r4415da  
    1010
    1111#include "Actions/Process.hpp"
     12
     13#include<boost/function.hpp>
     14
    1215#include "Descriptors/AtomDescriptor.hpp"
     16
     17class World;
    1318
    1419class ManipulateAtomsProcess : public Process
     
    1823  virtual ~ManipulateAtomsProcess();
    1924
    20   virtual void call();
    21   virtual void undo();
    2225  virtual bool canUndo();
     26  virtual bool shouldUndo();
    2327
    2428  virtual void doManipulate(World *);
    2529private:
     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
    2635  AtomDescriptor descr;
    2736  boost::function<void(atom*)> operation;
  • src/Actions/MethodAction.cpp

    r9131f3 r4415da  
    1010#include <string>
    1111
    12 #include "MethodAction.hpp"
     12#include "Actions/MethodAction.hpp"
     13#include "Helpers/Assert.hpp"
    1314
    1415using namespace std;
     
    2122
    2223MethodAction::~MethodAction()
    23 {
    24   // TODO Auto-generated destructor stub
     24{}
     25
     26
     27Action::state_ptr MethodAction::performCall() {
     28  executeMethod();
     29  // we don't have a state to save so we return Action::success
     30  return Action::success;
    2531}
    2632
     33Action::state_ptr MethodAction::performUndo(Action::state_ptr) {
     34  ASSERT(0,"Cannot undo a MethodAction");
     35  return Action::success;
     36}
    2737
    28 void MethodAction::call() {
    29   executeMethod();
    30 }
    31 void MethodAction::undo() {
    32 
     38Action::state_ptr MethodAction::performRedo(Action::state_ptr){
     39  ASSERT(0,"Cannot redo a MethodAction");
     40  return Action::success;
    3341}
    3442
     
    3644  return false;
    3745}
     46
     47bool MethodAction::shouldUndo(){
     48  return true;
     49}
  • src/Actions/MethodAction.hpp

    r9131f3 r4415da  
    2222  MethodAction(std::string _name,boost::function<void()> _executeMethod,bool _doRegister=true);
    2323  virtual ~MethodAction();
     24  virtual bool canUndo();
     25  virtual bool shouldUndo();
    2426
    25   virtual void call();
    26   virtual void undo();
    27   virtual bool canUndo();
     27private:
     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
    2832
    2933  boost::function<void()> executeMethod; //!< this stores the method to be called
    30 
    31 
    3234};
    3335
  • src/Actions/small_actions.cpp

    r9131f3 r4415da  
    1414/****** ChangeMoleculeNameAction *****/
    1515
    16 char ChangeMoleculeNameAction::NAME[] = "Change filename of Molecule";
     16// memento to remember the state when undoing
     17
     18class ChangeMoleculeNameState : public ActionState {
     19public:
     20  ChangeMoleculeNameState(molecule* _mol,std::string _lastName) :
     21    mol(_mol),
     22    lastName(_lastName)
     23  {}
     24  molecule* mol;
     25  std::string lastName;
     26};
     27
     28const char ChangeMoleculeNameAction::NAME[] = "Change filename of Molecule";
    1729
    1830ChangeMoleculeNameAction::ChangeMoleculeNameAction(MoleculeListClass *_molecules) :
     
    2436{}
    2537
    26 void ChangeMoleculeNameAction::call() {
     38Action::state_ptr ChangeMoleculeNameAction::performCall() {
    2739  string filename;
    2840  molecule *mol = NULL;
    29   Dialog *dialog = UIFactory::get()->makeDialog();
     41  Dialog *dialog = UIFactory::getInstance().makeDialog();
    3042
    3143  dialog->queryMolecule("Enter index of molecule: ",&mol,molecules);
    3244  dialog->queryString("Enter name: ",&filename);
     45
    3346  if(dialog->display()) {
     47    string oldName = mol->getName();
    3448    mol->setName(filename);
     49    delete dialog;
     50    return Action::state_ptr(new ChangeMoleculeNameState(mol,oldName));
    3551  }
    36 
    3752  delete dialog;
     53  return Action::failure;
    3854}
    3955
    40 void ChangeMoleculeNameAction::undo() {
     56Action::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");
    4159
     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
     66Action::state_ptr ChangeMoleculeNameAction::performRedo(Action::state_ptr _state){
     67  // Undo and redo have to do the same for this action
     68  return performUndo(_state);
    4269}
    4370
    4471bool ChangeMoleculeNameAction::canUndo() {
    45   return false;
     72  return true;
    4673}
    4774
  • src/Actions/small_actions.hpp

    r9131f3 r4415da  
    1414  virtual ~ChangeMoleculeNameAction();
    1515
    16   void call();
    17   void undo();
    1816  bool canUndo();
    1917  bool shouldUndo();
     
    2119  virtual const std::string getName();
    2220private:
     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
    2325  MoleculeListClass *molecules;
    24   static char NAME[];
     26  static const char NAME[];
    2527};
    2628
  • src/Descriptors/AtomDescriptor.cpp

    r9131f3 r4415da  
    6868
    6969World::AtomSet& AtomDescriptor_impl::getAtoms(){
    70   return World::get()->atoms;
     70  return World::getInstance().atoms;
    7171}
    7272
  • src/Descriptors/AtomDescriptor.hpp

    r9131f3 r4415da  
    3636  friend atom* World::getAtom(AtomDescriptor descriptor);
    3737  friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor);
    38   friend class World::AtomIterator;
     38  template <class,class,class> friend class SelectiveIterator;
    3939
    4040  friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
  • src/Descriptors/AtomTypeDescriptor.cpp

    r9131f3 r4415da  
    1313#include "periodentafel.hpp"
    1414
    15 AtomTypeDescriptor_impl::AtomTypeDescriptor_impl(element* _type) :
     15AtomTypeDescriptor_impl::AtomTypeDescriptor_impl(const element* _type) :
    1616  type(_type)
    1717{}
     
    2424}
    2525
    26 AtomDescriptor AtomByType(element *elem){
     26AtomDescriptor AtomByType(const element *elem){
    2727  return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomTypeDescriptor_impl(elem)));
    2828}
    2929
    3030AtomDescriptor AtomByType(int Z){
    31   element * elem = World::get()->getPeriode()->FindElement(Z);
     31  const element * elem = World::getInstance().getPeriode()->FindElement(Z);
    3232  return AtomByType(elem);
    3333}
  • src/Descriptors/AtomTypeDescriptor.hpp

    r9131f3 r4415da  
    1313class element;
    1414
    15 AtomDescriptor AtomByType(element *);
     15AtomDescriptor AtomByType(const element *);
    1616AtomDescriptor AtomByType(int);
    1717
  • src/Descriptors/AtomTypeDescriptor_impl.hpp

    r9131f3 r4415da  
    1414{
    1515public:
    16   AtomTypeDescriptor_impl(element* _type);
     16  AtomTypeDescriptor_impl(const element* _type);
    1717  virtual ~AtomTypeDescriptor_impl();
    1818
    1919  bool predicate(std::pair<atomId_t,atom*> atom);
    2020private:
    21   element *type;
     21  const element * const type;
    2222};
    2323
  • src/Descriptors/MoleculeDescriptor.cpp

    r9131f3 r4415da  
    6868
    6969World::MoleculeSet& MoleculeDescriptor_impl::getMolecules(){
    70   return World::get()->molecules;
     70  return World::getInstance().molecules;
    7171}
    7272
  • src/Descriptors/MoleculeDescriptor.hpp

    r9131f3 r4415da  
    3636  friend molecule* World::getMolecule(MoleculeDescriptor descriptor);
    3737  friend std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor);
    38   friend class World::MoleculeIterator;
     38  template <class,class,class> friend class SelectiveIterator;
    3939
    4040  friend MoleculeDescriptor operator&&(const MoleculeDescriptor &lhs, const MoleculeDescriptor &rhs);
     
    4343
    4444public:
    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
    4647
    4748  MoleculeDescriptor(impl_ptr);
  • src/Legacy/oldmenu.cpp

    r9131f3 r4415da  
    7878      case 'a': // absolute coordinates of atom
    7979        Log() << Verbose(0) << "Enter absolute coordinates." << endl;
    80         first = World::get()->createAtom();
     80        first = World::getInstance().createAtom();
    8181        first->x.AskPosition(mol->cell_size, false);
    8282        first->type = periode->AskElement();  // give type
     
    8585
    8686      case 'b': // relative coordinates of atom wrt to reference point
    87         first = World::get()->createAtom();
     87        first = World::getInstance().createAtom();
    8888        valid = true;
    8989        do {
     
    101101
    102102      case 'c': // relative coordinates of atom wrt to already placed atom
    103         first = World::get()->createAtom();
     103        first = World::getInstance().createAtom();
    104104        valid = true;
    105105        do {
     
    117117
    118118    case 'd': // two atoms, two angles and a distance
    119         first = World::get()->createAtom();
     119        first = World::getInstance().createAtom();
    120120        valid = true;
    121121        do {
     
    217217
    218218      case 'e': // least square distance position to a set of atoms
    219         first = World::get()->createAtom();
     219        first = World::getInstance().createAtom();
    220220        atoms = new (Vector*[128]);
    221221        valid = true;
     
    239239          mol->AddAtom(first);  // add to molecule
    240240        } else {
    241           World::get()->destroyAtom(first);
     241          World::getInstance().destroyAtom(first);
    242242          Log() << Verbose(0) << "Please enter at least two vectors!\n";
    243243        }
     
    748748  int axis,faktor,count,j;
    749749  atom *first = NULL;
    750   element **Elements;
     750  const element **Elements;
    751751  Vector x,y;
    752752  Vector **vectors;
     
    764764    if (mol->AtomCount != 0) {  // if there is more than none
    765765      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];
    767767      vectors = new Vector *[count];
    768768      j = 0;
     
    782782        x.AddVector(&y); // per factor one cell width further
    783783        for (int k=count;k--;) { // go through every atom of the original cell
    784           first = World::get()->createAtom(); // create a new body
     784          first = World::getInstance().createAtom(); // create a new body
    785785          first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    786786          first->x.AddVector(&x);     // translate the coordinates
     
    912912void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) {
    913913  molecule *srcmol = NULL, *destmol = NULL;
    914   Dialog *dialog = UIFactory::get()->makeDialog();
     914  Dialog *dialog = UIFactory::getInstance().makeDialog();
    915915  dialog->queryMolecule("Enter index of destination molecule: ",&destmol, molecules);
    916916  dialog->queryMolecule("Enter index of source molecule to add from: ",&srcmol, molecules);
     
    926926void oldmenu::embeddMolecules(MoleculeListClass *molecules) {
    927927  molecule *srcmol = NULL, *destmol = NULL;
    928   Dialog *dialog = UIFactory::get()->makeDialog();
     928  Dialog *dialog = UIFactory::getInstance().makeDialog();
    929929  dialog->queryMolecule("Enter index of matrix molecule (the variable one): ",&srcmol,molecules);
    930930  dialog->queryMolecule("Enter index of molecule to merge into (the fixed one): ",&destmol,molecules);
     
    10891089    A++;
    10901090  }
    1091   World::get()->destroyMolecule(mol);
     1091  World::getInstance().destroyMolecule(mol);
    10921092};
    10931093
  • src/Makefile.am

    r9131f3 r4415da  
    88ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    99
    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
     10ACTIONSSOURCE = 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                 
     22ACTIONSHEADER = 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                           
    1236
    1337PARSERSOURCE = Parser/ChangeTracker.cpp Parser/FormatParser.cpp Parser/TremoloParser.cpp Parser/XyzParser.cpp
     
    1539
    1640PATTERNSOURCE = Patterns/Observer.cpp
    17 PATTERNHEADER = Patterns/Observer.hpp Patterns/Cacheable.hpp
     41PATTERNHEADER = Patterns/Cacheable.hpp \
     42                                Patterns/Observer.hpp \
     43                Patterns/Singleton.hpp
    1844
    1945VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp
     
    3662                                   Descriptors/AtomTypeDescriptor.cpp \
    3763                                   Descriptors/MoleculeDescriptor.cpp \
    38                                    Descriptors/MoleculeIdDescriptor.cpp
     64                                   Descriptors/MoleculeIdDescriptor.cpp
     65                                   
    3966                                   
    4067DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \
     
    4370                                   Descriptors/MoleculeDescriptor.hpp \
    4471                                   Descriptors/MoleculeIdDescriptor.hpp
     72                                   
    4573
    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
     75SOURCE = ${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
     113HEADER = ${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
    48114
    49115BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB)
  • src/Menu/ActionMenuItem.cpp

    r9131f3 r4415da  
    2020
    2121ActionMenuItem::~ActionMenuItem()
    22 {
    23   // TODO Auto-generated destructor stub
    24 }
     22{}
    2523
    2624void ActionMenuItem::doTrigger() {
    2725  action->call();
    2826}
     27
     28bool ActionMenuItem::isActive() {
     29  return action->isActive();
     30}
  • src/Menu/ActionMenuItem.hpp

    r9131f3 r4415da  
    2626  virtual void doTrigger();
    2727
     28  virtual bool isActive();
     29
    2830private:
    2931  Action* action; //!< this action will be called when the trigger matches
  • src/Menu/MenuItem.cpp

    r9131f3 r4415da  
    7878  return added;
    7979}
     80
     81bool MenuItem::isActive(){
     82  return true;
     83}
  • src/Menu/MenuItem.hpp

    r9131f3 r4415da  
    2121 */
    2222class MenuItem {
    23 private:
    24   char trigger;
    25   string *description;
    26   bool added;
    27 
    2823public:
    2924  MenuItem(char,const char*,Menu*);
     
    4136  bool wasAdded();
    4237
     38  virtual bool isActive();
     39
    4340protected:
    4441  void setDescription(string);
     42
     43private:
     44  char trigger;
     45  string *description;
     46  bool added;
    4547};
    4648
  • src/Menu/TextMenu.cpp

    r9131f3 r4415da  
    1111#include "Menu/TextMenu.hpp"
    1212#include "Menu/MenuItem.hpp"
     13#include "Helpers/Assert.hpp"
    1314
    1415
     
    5152
    5253void 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";
    5462}
    5563
     
    7482    list<MenuItem*>::iterator iter;
    7583    for(iter = items.begin(); iter!=items.end();iter++){
    76       somethingChosen |= (*iter)->checkTrigger(choice);
     84      if((*iter)->isActive()){
     85        somethingChosen |= (*iter)->checkTrigger(choice);
     86      }
    7787    }
    7888    // see if something was chosen and call default Item if not
     
    8898}
    8999
     100string TextMenu::getTitle(){
     101  return title;
     102}
     103
    90104void TextMenu::addDefault(MenuItem* _defaultItem) {
    91105  defaultItem = _defaultItem;
    92106}
     107
     108/****************************** Contained Actions ****************/
     109
     110const string TextMenu::LeaveAction::nameBase = "Leave menu: ";
     111
     112TextMenu::LeaveAction::LeaveAction(TextMenu* _menu) :
     113Action(nameBase+_menu->getTitle()),
     114menu(_menu)
     115{}
     116
     117TextMenu::LeaveAction::~LeaveAction(){}
     118
     119bool TextMenu::LeaveAction::canUndo(){
     120  return false;
     121}
     122
     123bool TextMenu::LeaveAction::shouldUndo(){
     124  return false;
     125}
     126
     127Action::state_ptr TextMenu::LeaveAction::performCall(){
     128  menu->doQuit();
     129  return Action::success;
     130}
     131
     132
     133Action::state_ptr TextMenu::LeaveAction::performUndo(Action::state_ptr){
     134  ASSERT(0,"Cannot undo leaving a menu");
     135  return Action::success;
     136}
     137
     138Action::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  
    1414
    1515#include "Menu/Menu.hpp"
     16#include "Actions/Action.hpp"
    1617#include "defs.hpp"
    1718
     
    2627{
    2728public:
     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
    2847  TextMenu(ostream& _outputter, string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH);
    2948  virtual ~TextMenu();
     
    3251  virtual void removeItem(MenuItem*);
    3352  virtual void display();
     53  virtual string getTitle();
    3454
    3555  /**
  • src/Parser/ChangeTracker.cpp

    r9131f3 r4415da  
    1515ChangeTracker::ChangeTracker() {
    1616  isConsistent = true;
    17   World::get()->signOn(this);
     17  World::getInstance().signOn(this);
    1818}
    1919
     
    2222 */
    2323ChangeTracker::~ChangeTracker() {
    24   World::get()->signOff(this);
     24  World::getInstance().signOff(this);
    2525}
    2626
  • src/Parser/TremoloParser.cpp

    r9131f3 r4415da  
    2020 */
    2121TremoloParser::TremoloParser() {
     22  knownKeys[" "] = noKey; // so we can detect invalid keys
    2223  knownKeys["x"] = x;
    2324  knownKeys["u"] = u;
     
    6162  while (lineStream.good()) {
    6263    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    }
    6369    usedFields.push_back(keyword);
    6470  }
     
    7480  vector<string>::iterator it;
    7581  stringstream lineStream;
     82  atom* newAtom = World::getInstance().createAtom();
     83  TremoloAtomInfoContainer atomInfo = *(new TremoloAtomInfoContainer());
     84  atomDataKey currentField;
    7685  string word;
    7786
     
    7988  for (it=usedFields.begin(); it < usedFields.end(); it++) {
    8089    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) {
    8292      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;
    85175        break;
    86176      default :
     
    90180    }
    91181  }
     182  moreData[newAtom->getId()] = atomInfo;
    92183}
    93184
     
    117208}
    118209
    119 /*
    120 #ATOMDATA  <record_entry_1> ... <record_entry_n>
    121 # <record_entry>: <dataname>[=<n>]
    122 # <dataname>    : x | u | F | stress | Id | neighbors | imprData
    123 #               | GroupMeasureTypeNo | Type | extType
    124 #               | name | resName | chainID | resSeq
    125 #               | occupancy | tempFactor | segID | Charge
    126 #               | charge
    127 ATOMDATA name Id x=3 mass charge epsilon sigma eps14 sig14 name type protein protno neighbors=4
    128 */
    129 
    130 //MatrixContainer* data = readData(fileName, getHeaderSize('#'), 0);
    131 
    132 
    133210/**
    134211 * Saves the World's current state into as a tremolo file.
     
    144221*/
    145222}
     223
     224TremoloAtomInfoContainer::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  
    1212#include "FormatParser.hpp"
    1313
     14/**
     15 * Holds tremolo-specific information which is not store in the atom class.
     16 */
     17class TremoloAtomInfoContainer {
     18public:
     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 */
    1440class TremoloParser:public FormatParser
    1541{
     
    2753   * Known keys for the ATOMDATA line.
    2854   */
    29   enum StringValue {
     55  enum atomDataKey {
     56    noKey,
    3057    x,
    3158    u,
     
    5380   * Map to associate the known keys with numbers.
    5481   */
    55   std::map<std::string, StringValue> knownKeys;
     82  std::map<std::string, atomDataKey> knownKeys;
    5683
    5784  /**
     
    6491   * file.
    6592   */
    66   std::map<std::string, std::string> moreData;
     93  std::map<int, TremoloAtomInfoContainer> moreData;
    6794};
    6895
  • src/Parser/XyzParser.cpp

    r9131f3 r4415da  
    4444
    4545  for (int i = 0; i < numberOfAtoms; i++) {
    46     newAtom = World::get()->createAtom();
     46    newAtom = World::getInstance().createAtom();
    4747    *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));
    4949  }
    5050}
     
    5656 */
    5757void XyzParser::save(ostream* file) {
    58   *file << World::get()->numAtoms() << endl << comment << endl;
     58  *file << World::getInstance().numAtoms() << endl << comment << endl;
    5959
    60   vector<atom*> atoms = World::get()->getAllAtoms();
     60  vector<atom*> atoms = World::getInstance().getAllAtoms();
    6161  for(vector<atom*>::iterator it = atoms.begin(); it < atoms.end(); it++) {
    6262    *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  
    1111#include "Patterns/Observer.hpp"
    1212#include <boost/function.hpp>
     13#include <boost/shared_ptr.hpp>
     14#include <iostream>
     15
     16#include "Helpers/Assert.hpp"
    1317
    1418#ifndef NO_CACHING
     
    1721  class Cacheable : public Observer
    1822  {
     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
    19125  public:
    20126    Cacheable(Observable *_owner, boost::function<T()> _recalcMethod);
    21127    virtual ~Cacheable();
    22128
    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;
    27131
    28132    // methods implemented for base-class Observer
     
    30134    void subjectKilled(Observable *subject);
    31135  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
    35145    Observable *owner;
    36     bool valid;
    37     bool canBeUsed;
     146
    38147    boost::function<T()> recalcMethod;
     148
     149    // de-activated copy constructor
     150    Cacheable(const Cacheable&);
    39151  };
    40152
     
    43155  Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) :
    44156    owner(_owner),
    45     valid(false),
    46     canBeUsed(true),
    47157    recalcMethod(_recalcMethod)
    48158  {
     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;
    49163    // we sign on with the best(=lowest) priority, so cached values are recalculated before
    50164    // anybody else might ask for updated values
     
    52166  }
    53167
    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    }
    70183  }
    71184
     
    77190
    78191  template<typename T>
    79   const bool Cacheable<T>::isValid(){
    80     return valid;
     192  const bool Cacheable<T>::isValid() const{
     193    return state->isValid();
    81194  }
    82195
    83196  template<typename T>
    84197  void Cacheable<T>::update(Observable *subject) {
    85     valid = false;
     198    state->invalidate();
    86199  }
    87200
    88201  template<typename T>
    89202  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
    101214#else
    102215  template<typename T>
     
    107220    virtual ~Cacheable();
    108221
    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;
    113224
    114225    // methods implemented for base-class Observer
     
    126237
    127238  template<typename T>
    128   const T& Cacheable<T>::operator*(){
     239  const T Cacheable<T>::operator*() const{
    129240    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);
    140241  }
    141242
     
    145246
    146247  template<typename T>
    147   const bool Cacheable<T>::isValid(){
     248  const bool Cacheable<T>::isValid() const{
    148249    return true;
    149250  }
     
    151252  template<typename T>
    152253  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");
    159260  }
    160261#endif
  • src/Patterns/Observer.cpp

    r9131f3 r4415da  
    1010
    1111#include <iostream>
    12 #include <cassert>
     12
     13#include "Helpers/Assert.hpp"
    1314
    1415using namespace std;
     
    127128    // observers, but still we are called by one of our sub-Observables
    128129    // 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");
    132133    return;
    133134  }
     
    148149 */
    149150void 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");
    151152  bool res = false;
    152153  callees_t *callees = 0;
     
    172173 */
    173174void 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.");
    175176  callees_t *callees = callTable[this];
    176177  callees_t::iterator iter;
     
    188189    delete callees;
    189190  }
     191}
     192
     193bool Observable::isBlocked(){
     194  return depth.count(this) > 0;
    190195}
    191196
  • src/Patterns/Observer.hpp

    r9131f3 r4415da  
    9595  virtual void signOff(Observer *target);
    9696
     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
    97103protected:
    98104  virtual void update(Observable *publisher);
     
    119125  static std::set<Observable*> busyObservables;
    120126
     127  //! @cond
    121128  // Structure for RAII-Style notification
    122129protected:
     
    133140    Observable *protege;
    134141  };
     142  //! @endcond
    135143};
    136144
  • src/UIElements/Dialog.cpp

    r9131f3 r4415da  
    133133  *target = *tmp;
    134134}
     135
     136// Element Queries
     137Dialog::ElementQuery::ElementQuery(std::string title, const element **_target) :
     138  Query(title),
     139  tmp(0),
     140  target(_target)
     141  {}
     142
     143Dialog::ElementQuery::~ElementQuery(){}
     144
     145void Dialog::ElementQuery::setResult(){
     146  *target=tmp;
     147}
  • src/UIElements/Dialog.hpp

    r9131f3 r4415da  
    1515class molecule;
    1616class Vector;
     17class element;
    1718
    1819class Dialog
     
    2728  virtual void queryMolecule(const char*,molecule**,MoleculeListClass*)=0;
    2829  virtual void queryVector(const char*,Vector *,const double *const,bool)=0;
     30  virtual void queryElement(const char*,const element **)=0;
    2931
    3032  virtual bool display();
     
    4547  public:
    4648    Query(std::string _title);
    47     ~Query();
     49    virtual ~Query();
    4850    virtual bool handle()=0;
    4951    virtual void setResult()=0;
     
    5860  public:
    5961    IntQuery(std::string title,int *_target);
    60     ~IntQuery();
     62    virtual ~IntQuery();
    6163    virtual bool handle()=0;
    6264    virtual void setResult();
     
    7072  public:
    7173    DoubleQuery(std::string title,double *_target);
    72     ~DoubleQuery();
     74    virtual ~DoubleQuery();
    7375    virtual bool handle()=0;
    7476    virtual void setResult();
     
    8284  public:
    8385    StringQuery(std::string title,std::string *_target);
    84     ~StringQuery();
     86    virtual ~StringQuery();
    8587    virtual bool handle()=0;
    8688    virtual void setResult();
     
    9597  public:
    9698    MoleculeQuery(std::string title, molecule **_target, MoleculeListClass *_molecules);
    97     ~MoleculeQuery();
     99    virtual ~MoleculeQuery();
    98100    virtual bool handle()=0;
    99101    virtual void setResult();
     
    108110  public:
    109111      VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check);
    110       ~VectorQuery();
     112      virtual ~VectorQuery();
    111113      virtual bool handle()=0;
    112114      virtual void setResult();
     
    119121  };
    120122
     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
    121135void registerQuery(Query* query);
    122136
  • src/UIElements/TextDialog.cpp

    r9131f3 r4415da  
    1010#include "UIElements/TextDialog.hpp"
    1111
     12#include "World.hpp"
     13#include "periodentafel.hpp"
    1214#include "atom.hpp"
    1315#include "molecule.hpp"
     
    4547void TextDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check) {
    4648  registerQuery(new VectorTextQuery(title,target,cellSize,check));
     49}
     50
     51void TextDialog::queryElement(const char* title, const element **target){
     52  registerQuery(new ElementTextQuery(title,target));
    4753}
    4854
     
    113119
    114120bool TextDialog::VectorTextQuery::handle() {
     121 Log() << Verbose(0) << getTitle();
    115122 tmp->AskPosition(cellSize,check);
    116123 return true;
    117124}
     125
     126
     127TextDialog::ElementTextQuery::ElementTextQuery(std::string title, const element **target) :
     128    Dialog::ElementQuery(title,target)
     129{}
     130
     131TextDialog::ElementTextQuery::~ElementTextQuery()
     132{}
     133
     134bool 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  
    2424  virtual void queryMolecule(const char*,molecule**,MoleculeListClass*);
    2525  virtual void queryVector(const char*,Vector *,const double * const,bool);
     26  virtual void queryElement(const char*,const element **);
    2627
    2728protected:
     
    3031  public:
    3132    IntTextQuery(std::string title, int *_target);
    32     ~IntTextQuery();
     33    virtual ~IntTextQuery();
    3334    virtual bool handle();
    3435  };
     
    3738  public:
    3839    DoubleTextQuery(std::string title, double *_target);
    39     ~DoubleTextQuery();
     40    virtual ~DoubleTextQuery();
    4041    virtual bool handle();
    4142  };
     
    4445  public:
    4546    StringTextQuery(std::string title, std::string *_target);
    46     ~StringTextQuery();
     47    virtual ~StringTextQuery();
    4748    virtual bool handle();
    4849  };
     
    5152  public:
    5253    MoleculeTextQuery(std::string title, molecule **_target, MoleculeListClass *_molecules);
    53     ~MoleculeTextQuery();
     54    virtual ~MoleculeTextQuery();
    5455    virtual bool handle();
    5556  };
     
    5859  public:
    5960    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();
    6169    virtual bool handle();
    6270  };
  • src/UIElements/TextWindow.cpp

    r9131f3 r4415da  
    3939#include "Actions/MethodAction.hpp"
    4040#include "Actions/ErrorAction.hpp"
     41#include "Actions/ActionRegistry.hpp"
    4142#include "Views/StreamStringView.hpp"
    4243#include "Views/MethodStringView.hpp"
     
    5657  moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1));
    5758  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);
    5867
    5968  new SeperatorItem(main_menu);
     
    94103  populaters.MakeEditMoleculesMenu(editMoleculesMenu,molecules,configuration,periode);
    95104
    96   returnFromEditMoleculeAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,editMoleculesMenu),false);
     105  Action *returnFromEditMoleculeAction = new TextMenu::LeaveAction(editMoleculesMenu);
    97106  MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnFromEditMoleculeAction);
    98107
     
    108117  delete old_menu;
    109118  delete quitAction;
    110   delete returnFromEditMoleculeAction;
    111119  delete moleculeView;
    112120  delete statusIndicator;
  • src/UIElements/TextWindow.hpp

    r9131f3 r4415da  
    2929  // some actions only needed in textMenus
    3030  Action *quitAction;
    31   Action *returnFromEditMoleculeAction;
    3231  // all views that are contained in the main Menu
    3332  StringView *moleculeView;
  • src/UIElements/UIFactory.cpp

    r9131f3 r4415da  
    88
    99#include <cassert>
     10#include "Patterns/Singleton_impl.hpp"
    1011#include "UIElements/UIFactory.hpp"
    1112
    1213// all factories that can be used:
    1314#include "UIElements/TextUIFactory.hpp"
    14 
    15 UIFactory *UIFactory::theFactory = 0;
    1615
    1716UIFactory::UIFactory()
     
    2726
    2827void UIFactory::makeUserInterface(InterfaceTypes type) {
    29   assert(theFactory == 0 && "makeUserInterface should only be called once");
    3028  switch(type) {
    3129    case Text :
    32       theFactory = new TextUIFactory();
     30      setInstance(new TextUIFactory());
    3331      break;
    3432
     
    3937}
    4038
    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 }
     39CONSTRUCT_SINGLETON(UIFactory)
  • src/UIElements/UIFactory.hpp

    r9131f3 r4415da  
    1717
    1818struct menuPopulaters;
     19
     20#include "Patterns/Singleton.hpp"
     21
    1922/**
    2023 * Abstract Factory to create any kind of User interface object needed by the programm.
     
    2427 * UIs can be handled in a concise abstract way.
    2528 */
    26 class UIFactory
     29class UIFactory : public Singleton<UIFactory,false>
    2730{
    2831
     
    4548  UIFactory();
    4649
    47 // singleton stuff
    48 private:
    49   static UIFactory *theFactory;
    50 
    5150public:
    5251  /**
     
    5554  static void makeUserInterface(InterfaceTypes type);
    5655
    57   /**
    58    * get the previously created factory
    59    */
    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();
    6856};
    6957
  • src/World.cpp

    r9131f3 r4415da  
    1515#include "Descriptors/MoleculeDescriptor.hpp"
    1616#include "Descriptors/MoleculeDescriptor_impl.hpp"
     17#include "Descriptors/SelectiveIterator_impl.hpp"
    1718#include "Actions/ManipulateAtomsProcess.hpp"
     19
     20#include "Patterns/Singleton_impl.hpp"
    1821
    1922using namespace std;
     
    170173    atomId_t id = *(atomIdPool.begin());
    171174    atomIdPool.erase(id);
     175    return id;
    172176  }
    173177}
     
    206210/******************************* Iterators ********************************/
    207211
    208 /*
    209  * Actual Implementation of the iterators can be found in WorldIterators.cpp
    210  */
     212// Build the AtomIterator from template
     213CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
     214
    211215
    212216World::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
     220World::AtomIterator World::atomEnd(){
     221  return AtomIterator(AllAtoms(),atoms,atoms.end());
     222}
     223
     224// build the MoleculeIterator from template
     225CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
    219226
    220227World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
    221   return MoleculeIterator(descr,this);
    222 }
    223 
    224 World::MoleculeSet::iterator World::moleculeEnd(){
    225   return molecules.end();
     228  return MoleculeIterator(descr,molecules);
     229}
     230
     231World::MoleculeIterator World::moleculeEnd(){
     232  return MoleculeIterator(AllMolecules(),molecules,molecules.end());
    226233}
    227234
    228235/******************************* Singleton Stuff **************************/
    229 
    230 // TODO: Hide boost-thread using Autotools stuff when no threads are used
    231 World* World::theWorld = 0;
    232 boost::mutex World::worldLock;
    233236
    234237World::World() :
     
    260263}
    261264
    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
     267CONSTRUCT_SINGLETON(World)
    300268
    301269/******************************* deprecated Legacy Stuff ***********************/
  • src/World.hpp

    r9131f3 r4415da  
    1616#include <boost/shared_ptr.hpp>
    1717
    18 #include "defs.hpp"
     18#include "types.hpp"
     19#include "Descriptors/SelectiveIterator.hpp"
    1920#include "Patterns/Observer.hpp"
    2021#include "Patterns/Cacheable.hpp"
     22#include "Patterns/Singleton.hpp"
     23
    2124
    2225// forward declarations
     
    3336class AtomsCalculation;
    3437
    35 class World : public Observable
     38
     39
     40class World : public Singleton<World>, public Observable
    3641{
     42
     43// Make access to constructor and destructor possible from inside the singleton
     44friend class Singleton<World>;
     45
    3746// necessary for coupling with descriptors
    3847friend class AtomDescriptor_impl;
     
    4554template<typename> friend class AtomsCalculation;
    4655public:
     56
     57  // Types for Atom and Molecule structures
    4758  typedef std::map<atomId_t,atom*> AtomSet;
    4859  typedef std::map<moleculeId_t,molecule*> MoleculeSet;
     
    150161
    151162  // 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;
    190164
    191165  /**
     
    201175   * used for internal purposes, like AtomProcesses and AtomCalculations.
    202176   */
    203   AtomSet::iterator atomEnd();
     177  AtomIterator atomEnd();
    204178
    205179  // Molecules
    206180
    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;
    243182
    244183  /**
     
    254193   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    255194   */
    256   MoleculeSet::iterator moleculeEnd();
     195  MoleculeIterator moleculeEnd();
    257196
    258197
     
    267206
    268207  periodentafel *periode;
     208public:
    269209  AtomSet atoms;
     210private:
    270211  std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
    271212  atomId_t currAtomId; //!< stores the next available Id for atoms
    272213  MoleculeSet molecules;
    273214  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 immidiately
    291    * create a new one. Use this to reset while somebody is still Observing
    292    * the world and should reset the observed instance. All observers will be
    293    * sent the subjectKille() message from the old world.
    294    */
    295   static World* reset();
    296 
    297215private:
    298216  /**
     
    307225   */
    308226  virtual ~World();
    309 
    310   static World *theWorld;
    311   // this mutex only saves the singleton pattern...
    312   // use other mutexes to protect internal data as well
    313   // this mutex handles access to the pointer, not to the object!!!
    314   static boost::mutex worldLock;
    315227
    316228  /*****
  • src/atom.cpp

    r9131f3 r4415da  
    5050  res->FixedIon = FixedIon;
    5151  res->node = &x;
    52   World::get()->registerAtom(res);
     52  World::getInstance().registerAtom(res);
    5353  return res;
    5454}
  • src/atom.hpp

    r9131f3 r4415da  
    2828#include "atom_trajectoryparticle.hpp"
    2929#include "tesselation.hpp"
     30#include "types.hpp"
    3031
    3132/****************************************** forward declarations *****************************/
  • src/atom_atominfo.cpp

    r9131f3 r4415da  
    2020};
    2121
    22 element *AtomInfo::getType(){
     22const element *AtomInfo::getType(){
    2323  return type;
    2424}
    2525
    26 void AtomInfo::setType(element* _type) {
     26void AtomInfo::setType(const element* _type) {
    2727  type = _type;
    2828}
    2929
    3030void AtomInfo::setType(int Z) {
    31   element *elem = World::get()->getPeriode()->FindElement(Z);
     31  const element *elem = World::getInstance().getPeriode()->FindElement(Z);
    3232  setType(elem);
    3333}
  • src/atom_atominfo.hpp

    r9131f3 r4415da  
    3232  Vector v;       //!< velocity vector of atom, giving last velocity within cell
    3333  Vector F;       //!< Force vector of atom, giving last force within cell
    34   element *type;  //!< pointing to element
     34  const element *type;  //!< pointing to element
    3535
    3636  AtomInfo();
    3737  ~AtomInfo();
    3838
    39   element *getType();
    40   void setType(element *);
     39  const element *getType();
     40  void setType(const element *);
    4141  void setType(int);
    4242
  • src/boundary.cpp

    r9131f3 r4415da  
    801801{
    802802        Info FunctionInfo(__func__);
    803   molecule *Filling = World::get()->createMolecule();
     803  molecule *Filling = World::getInstance().createMolecule();
    804804  Vector CurrentPosition;
    805805  int N[NDIM];
  • src/builder.cpp

    r9131f3 r4415da  
    7474#include "Menu/ActionMenuItem.hpp"
    7575#include "Actions/ActionRegistry.hpp"
     76#include "Actions/ActionHistory.hpp"
    7677#include "Actions/MethodAction.hpp"
    7778#include "Actions/small_actions.hpp"
     
    14321433     }
    14331434     if (mol == NULL) {
    1434        mol = World::get()->createMolecule();
     1435       mol = World::getInstance().createMolecule();
    14351436       mol->ActiveFlag = true;
    14361437       if (ConfigFileName != NULL)
     
    14811482                SaveFlag = true;
    14821483                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();
    14841485                first->type = periode->FindElement(atoi(argv[argptr]));
    14851486                if (first->type != NULL)
     
    15931594                }
    15941595                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]));
    15961597                FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
    15971598                int ranges[NDIM] = {1,1,1};
     
    16341635                Log() << Verbose(1) << "Filling Box with water molecules." << endl;
    16351636                // construct water molecule
    1636                 molecule *filler = World::get()->createMolecule();
     1637                molecule *filler = World::getInstance().createMolecule();
    16371638                molecule *Filling = NULL;
    16381639                atom *second = NULL, *third = NULL;
     
    16411642//                first->x.Zero();
    16421643//                filler->AddAtom(first);
    1643                 first = World::get()->createAtom();
     1644                first = World::getInstance().createAtom();
    16441645                first->type = periode->FindElement(1);
    16451646                first->x.Init(0.441, -0.143, 0.);
    16461647                filler->AddAtom(first);
    1647                 second = World::get()->createAtom();
     1648                second = World::getInstance().createAtom();
    16481649                second->type = periode->FindElement(1);
    16491650                second->x.Init(-0.464, 1.137, 0.0);
    16501651                filler->AddAtom(second);
    1651                 third = World::get()->createAtom();
     1652                third = World::getInstance().createAtom();
    16521653                third->type = periode->FindElement(8);
    16531654                third->x.Init(-0.464, 0.177, 0.);
     
    16641665                  molecules->insert(Filling);
    16651666                }
    1666                 World::get()->destroyMolecule(filler);
     1667                World::getInstance().destroyMolecule(filler);
    16671668                argptr+=6;
    16681669              }
     
    20702071                  int faktor = atoi(argv[argptr++]);
    20712072                  int count;
    2072                   element ** Elements;
     2073                  const element ** Elements;
    20732074                  Vector ** vectors;
    20742075                  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;
    20762077                    faktor = 1;
    20772078                  }
     
    20792080                  if (mol->AtomCount != 0) {  // if there is more than none
    20802081                    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];
    20822083                    vectors = new Vector *[count];
    20832084                    j = 0;
     
    20972098                      x.AddVector(&y); // per factor one cell width further
    20982099                      for (int k=count;k--;) { // go through every atom of the original cell
    2099                         first = World::get()->createAtom(); // create a new body
     2100                        first = World::getInstance().createAtom(); // create a new body
    21002101                        first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    21012102                        first->x.AddVector(&x);      // translate the coordinates
     
    21682169void cleanUp(config *configuration){
    21692170  UIFactory::purgeInstance();
    2170   World::destroy();
     2171  World::purgeInstance();
    21712172  delete(configuration);
    21722173  Log() << Verbose(0) <<  "Maximum of allocated memory: "
     
    21772178  logger::purgeInstance();
    21782179  errorLogger::purgeInstance();
    2179   ActionRegistry::purgeRegistry();
     2180  ActionRegistry::purgeInstance();
    21802181}
    21812182
     
    21902191    char *ConfigFileName = NULL;
    21912192    int j;
     2193
    21922194    setVerbosity(0);
     2195    // need to init the history before any action is created
     2196    ActionHistory::init();
    21932197    /* 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);
    21952199    switch (j){
    21962200        case 255:
     
    22022206            break;
    22032207    }
    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);
    22072211        cout << "Molecule created" << endl;
    22082212        if(mol->cell_size[0] == 0.){
     
    22252229
    22262230      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);
    22282232      mainWindow->display();
    22292233      delete mainWindow;
    22302234    }
    22312235
    2232     if(World::get()->getPeriode()->StorePeriodentafel(configuration->databasepath))
     2236    if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath))
    22332237        Log() << Verbose(0) << "Saving of elements.db successful." << endl;
    22342238
  • src/config.cpp

    r9131f3 r4415da  
    675675{
    676676  int MaxTypes = 0;
    677   element *elementhash[MAX_ELEMENTS];
     677  const element *elementhash[MAX_ELEMENTS];
    678678  char name[MAX_ELEMENTS];
    679679  char keyword[MAX_ELEMENTS];
     
    733733            sprintf(keyword,"%s_%i",name, j+1);
    734734            if (repetition == 0) {
    735               neues = World::get()->createAtom();
     735              neues = World::getInstance().createAtom();
    736736              AtomList[i][j] = neues;
    737737              LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    812812          sprintf(keyword,"%s_%i",name, j+1);
    813813          if (repetition == 0) {
    814             neues = World::get()->createAtom();
     814            neues = World::getInstance().createAtom();
    815815            AtomList[i][j] = neues;
    816816            LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    851851void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    852852{
    853   molecule *mol = World::get()->createMolecule();
     853  molecule *mol = World::getInstance().createMolecule();
    854854  ifstream *file = new ifstream(filename);
    855855  if (file == NULL) {
     
    10891089void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    10901090{
    1091   molecule *mol = World::get()->createMolecule();
     1091  molecule *mol = World::getInstance().createMolecule();
    10921092  ifstream *file = new ifstream(filename);
    10931093  if (file == NULL) {
     
    11071107  string zeile;
    11081108  string dummy;
    1109   element *elementhash[128];
     1109  const element *elementhash[128];
    11101110  int Z = -1;
    11111111  int No = -1;
     
    12881288        }
    12891289        istringstream input2(zeile);
    1290         atom *neues = World::get()->createAtom();
     1290        atom *neues = World::getInstance().createAtom();
    12911291        input2 >> neues->x.x[0]; // x
    12921292        input2 >> neues->x.x[1]; // y
     
    17881788  char filename[MAXSTRINGSIZE];
    17891789  ofstream output;
    1790   molecule *mol = World::get()->createMolecule();
     1790  molecule *mol = World::getInstance().createMolecule();
    17911791  mol->SetNameFromFilename(ConfigFileName);
    17921792
     
    18991899  }
    19001900
    1901   World::get()->destroyMolecule(mol);
     1901  World::getInstance().destroyMolecule(mol);
    19021902};
    19031903
  • src/defs.hpp

    r9131f3 r4415da  
    3333enum Shading { white, lightgray, darkgray, black };  //!< color in Breadth-First-Search analysis
    3434
    35 // some types that can stay abstract
    36 typedef unsigned int moleculeId_t;
    37 typedef unsigned int atomId_t;
     35
    3836
    3937//enum CutCyclicBond { KeepBond,  SaturateBond }; //!< Saturation scheme either atom- or bondwise
  • src/element.cpp

    r9131f3 r4415da  
    99
    1010#include "element.hpp"
     11
     12using namespace std;
    1113
    1214/************************************* Functions for class element **********************************/
     
    3537 * \param *out outstream
    3638 */
    37 bool element::Output(ofstream * const out) const
     39bool element::Output(ostream * const out) const
    3840{
    3941  if (out != NULL) {
     
    5052 * \param NoOfAtoms total number of atom of this element type
    5153 */
    52 bool element::Checkout(ofstream * const out, const int Number, const int NoOfAtoms) const
     54bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const
    5355{
    5456  if (out != NULL) {
     
    5860    return false;
    5961};
     62
     63atomicNumber_t element::getNumber() const{
     64  return Z;
     65}
     66
     67string element::getSymbol() const{
     68  return string(symbol);
     69}
  • src/element.hpp

    r9131f3 r4415da  
    99#define ELEMENT_HPP_
    1010
    11 using namespace std;
    12 
    1311/*********************************************** includes ***********************************/
    1412
     
    1917
    2018#include <iostream>
     19#include <string>
    2120
    2221#include "defs.hpp"
     22#include "types.hpp"
    2323
    2424/********************************************** declarations *******************************/
     
    5050  ~element();
    5151
     52  // accessor functions
     53  atomicNumber_t getNumber() const;
     54  std::string getSymbol() const;
     55
    5256  //> 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;
    5559
    5660  private:
  • src/errorlogger.cpp

    r9131f3 r4415da  
    99#include "errorlogger.hpp"
    1010#include "verbose.hpp"
     11#include "Patterns/Singleton_impl.hpp"
    1112
    1213ofstream null("/dev/null");
    13 
    14 errorLogger* errorLogger::instance = NULL;
    1514int errorLogger::verbosity = 2;
    1615ostream* errorLogger::nix = &null;
     
    2322errorLogger::errorLogger()
    2423{
    25   instance = NULL;
    2624  verbosity = 2;
    2725};
     
    3432}
    3533
    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 }
     34CONSTRUCT_SINGLETON(errorLogger)
    6035
    6136/**
  • src/errorlogger.hpp

    r9131f3 r4415da  
    1111#include <iostream>
    1212
     13#include "Patterns/Singleton.hpp"
     14
    1315using namespace std;
    1416
    1517class Verbose;
    1618
    17 class errorLogger {
     19class errorLogger : public Singleton<errorLogger>{
     20  friend class Singleton<errorLogger>;
    1821public :
    1922  static ostream *nix;
    2023  static int verbosity;
    2124
    22   static errorLogger* getInstance();
    23   static void purgeInstance();
    2425  static bool DoOutput();
    2526  static void setVerbosity(int verbosityLevel);
     
    3132  ~errorLogger();
    3233
    33 private:
    34   static errorLogger* instance;
    3534};
    3635
  • src/helpers.hpp

    r9131f3 r4415da  
    189189#define PLURAL_S(v) (((v)==1)?"":"s")
    190190
     191// this is to allow different modes of access for
     192// maps and sets
     193template<typename Res,typename T>
     194struct _take{
     195  Res get(T value) const;
     196};
     197
     198// if we have a set,vector etc we can directly access the result
     199template<typename Res>
     200struct _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
     208template<typename Res,typename T1>
     209struct _take<Res,std::pair<T1,Res> >{
     210  static inline Res get(std::pair<T1,Res> value){
     211    return value.second;
     212  }
     213};
     214
    191215#endif /*HELPERS_HPP_*/
  • src/leastsquaremin.hpp

    r9131f3 r4415da  
    4242  gsl_vector *x;
    4343  const molecule *mol;
    44   element *type;
     44  const element *type;
    4545};
    4646
  • src/log.cpp

    r9131f3 r4415da  
    1515 */
    1616void setVerbosity(int verbosityLevel) {
    17   logger::getInstance()->setVerbosity(verbosityLevel);
    18   errorLogger::getInstance()->setVerbosity(verbosityLevel);
     17  logger::getInstance().setVerbosity(verbosityLevel);
     18  errorLogger::getInstance().setVerbosity(verbosityLevel);
    1919}
    2020
     
    2424 * \param indentation level of the message to log
    2525 */
    26 class logger * Log() {
     26class logger& Log() {
    2727  return logger::getInstance();
    2828}
     
    3333 * \param indentation level of the message to log
    3434 */
    35 class errorLogger * eLog() {
     35class errorLogger & eLog() {
    3636  return errorLogger::getInstance();
    3737}
  • src/logger.cpp

    r9131f3 r4415da  
    99#include "logger.hpp"
    1010#include "verbose.hpp"
     11#include "Patterns/Singleton_impl.hpp"
    1112
    1213ofstream nullStream("/dev/null");
    1314
    14 logger* logger::instance = NULL;
    1515int logger::verbosity = 2;
    1616ostream* logger::nix = &nullStream;
     
    2323logger::logger()
    2424{
    25   instance = NULL;
    2625  verbosity = 2;
    2726};
     
    3433}
    3534
    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 }
     35CONSTRUCT_SINGLETON(logger)
    6036
    6137/**
  • src/logger.hpp

    r9131f3 r4415da  
    1111#include <iostream>
    1212
     13#include "Patterns/Singleton.hpp"
     14
    1315using namespace std;
    1416
    1517class Verbose;
    1618
    17 class logger {
     19class logger : public Singleton<logger> {
     20  friend class Singleton<logger>;
    1821public :
    1922  static ostream *nix;
    2023  static int verbosity;
    2124
    22   static logger* getInstance();
    23   static void purgeInstance();
    2425  static bool DoOutput();
    2526  static void setVerbosity(int verbosityLevel);
     
    3031  /** Do not call this destructor directly, use purgeInstance() instead. */
    3132  ~logger();
    32 
    33 private:
    34   static logger* instance;
    3533};
    3634
  • src/molecule.cpp

    r9131f3 r4415da  
    3131 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3232 */
    33 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get()->createAtom()), end(World::get()->createAtom()),
     33molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::getInstance().createAtom()), end(World::getInstance().createAtom()),
    3434  first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
    3535  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
     
    5656
    5757molecule *NewMolecule(){
    58   return new molecule(World::get()->getPeriode());
     58  return new molecule(World::getInstance().getPeriode());
    5959}
    6060
     
    9999
    100100std::string molecule::calcFormula(){
    101   int Counts[MAX_ELEMENTS];
     101  std::map<atomicNumber_t,unsigned int> counts;
    102102  stringstream sstr;
    103   for (int j = 0; j<MAX_ELEMENTS;j++)
    104     Counts[j] = 0;
     103  periodentafel *periode = World::getInstance().getPeriode();
    105104  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;
    111111  }
    112112  return sstr.str();
     
    261261  switch(TopBond->BondDegree) {
    262262    case 1:
    263       FirstOtherAtom = World::get()->createAtom();    // new atom
     263      FirstOtherAtom = World::getInstance().createAtom();    // new atom
    264264      FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
    265265      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     
    318318
    319319      // create the two Hydrogens ...
    320       FirstOtherAtom = World::get()->createAtom();
    321       SecondOtherAtom = World::get()->createAtom();
     320      FirstOtherAtom = World::getInstance().createAtom();
     321      SecondOtherAtom = World::getInstance().createAtom();
    322322      FirstOtherAtom->type = elemente->FindElement(1);
    323323      SecondOtherAtom->type = elemente->FindElement(1);
     
    373373    case 3:
    374374      // 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();
    378378      FirstOtherAtom->type = elemente->FindElement(1);
    379379      SecondOtherAtom->type = elemente->FindElement(1);
     
    494494    MDSteps++;
    495495  for(i=0;i<NumberOfAtoms;i++){
    496     Walker = World::get()->createAtom();
     496    Walker = World::getInstance().createAtom();
    497497    getline(xyzfile,line,'\n');
    498498    istringstream *item = new istringstream(line);
  • src/molecule_dynamics.cpp

    r9131f3 r4415da  
    486486  bool status = true;
    487487  int MaxSteps = configuration.MaxOuterStep;
    488   MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::get());
     488  MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::getPointer());
    489489  // Get the Permutation Map by MinimiseConstrainedPotential
    490490  atom **PermutationMap = NULL;
     
    506506  Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl;
    507507  for (int step = 0; step <= MaxSteps; step++) {
    508     mol = World::get()->createMolecule();
     508    mol = World::getInstance().createMolecule();
    509509    MoleculePerStep->insert(mol);
    510510    Walker = start;
  • src/molecule_fragmentation.cpp

    r9131f3 r4415da  
    676676  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    677677  // 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());
    679679  int k=0;
    680680  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     
    927927{
    928928  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    929   molecule *Leaf = World::get()->createMolecule();
     929  molecule *Leaf = World::getInstance().createMolecule();
    930930
    931931//  Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
  • src/moleculelist.cpp

    r9131f3 r4415da  
    141141void MoleculeListClass::Enumerate(ostream *out)
    142142{
    143   element* Elemental = NULL;
    144143  atom *Walker = NULL;
    145   int Counts[MAX_ELEMENTS];
     144  periodentafel *periode = World::getInstance().getPeriode();
     145  std::map<atomicNumber_t,unsigned int> counts;
    146146  double size=0;
    147147  Vector Origin;
     
    155155    Origin.Zero();
    156156    for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    157       // reset element counts
    158       for (int j = 0; j<MAX_ELEMENTS;j++)
    159         Counts[j] = 0;
    160157      // count atoms per element and determine size of bounding sphere
    161158      size=0.;
     
    163160      while (Walker->next != (*ListRunner)->end) {
    164161        Walker = Walker->next;
    165         Counts[Walker->type->Z]++;
     162        counts[Walker->type->getNumber()]++;
    166163        if (Walker->x.DistanceSquared(&Origin) > size)
    167164          size = Walker->x.DistanceSquared(&Origin);
     
    169166      // output Index, Name, number of atoms, chemical formula
    170167      (*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;
    176173      }
    177174      // Center and size
     
    215212  // remove src
    216213  ListOfMolecules.remove(srcmol);
    217   World::get()->destroyMolecule(srcmol);
     214  World::getInstance().destroyMolecule(srcmol);
    218215  return true;
    219216};
     
    580577  stringstream line;
    581578  atom *Walker = NULL;
    582   element *runner = NULL;
     579  periodentafel *periode=World::getInstance().getPeriode();
    583580
    584581  // open file for the force factors
     
    590587    //output << prefix << "Forces" << endl;
    591588    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
    596592          Walker = (*ListRunner)->start;
    597593          while (Walker->next != (*ListRunner)->end) { // go through every atom of this element
    598594            Walker = Walker->next;
    599             if (Walker->type->Z == runner->Z) {
     595            if (Walker->type->getNumber() == (*elemIter).first) {
    600596              if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea
    601597                //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it
     
    750746void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
    751747{
    752   molecule *mol = World::get()->createMolecule();
     748  molecule *mol = World::getInstance().createMolecule();
    753749  atom *Walker = NULL;
    754750  atom *Advancer = NULL;
     
    775771    }
    776772    // remove the molecule
    777     World::get()->destroyMolecule(*MolRunner);
     773    World::getInstance().destroyMolecule(*MolRunner);
    778774    ListOfMolecules.erase(MolRunner);
    779775  }
     
    797793  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    798794  for (int i=0;i<MolCount;i++) {
    799     molecules[i] = World::get()->createMolecule();
     795    molecules[i] = World::getInstance().createMolecule();
    800796    molecules[i]->ActiveFlag = true;
    801797    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     
    895891  OBSERVE;
    896892  molecule *mol = NULL;
    897   mol = World::get()->createMolecule();
     893  mol = World::getInstance().createMolecule();
    898894  insert(mol);
    899895};
     
    904900  char filename[MAXSTRINGSIZE];
    905901  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
    906   mol = World::get()->createMolecule();
     902  mol = World::getInstance().createMolecule();
    907903  do {
    908904    Log() << Verbose(0) << "Enter file name: ";
     
    962958      mol = *ListRunner;
    963959      ListOfMolecules.erase(ListRunner);
    964       World::get()->destroyMolecule(mol);
     960      World::getInstance().destroyMolecule(mol);
    965961      break;
    966962    }
     
    10091005  // remove the leaf itself
    10101006  if (Leaf != NULL) {
    1011     World::get()->destroyMolecule(Leaf);
     1007    World::getInstance().destroyMolecule(Leaf);
    10121008    Leaf = NULL;
    10131009  }
  • src/periodentafel.cpp

    r9131f3 r4415da  
    1010#include <fstream>
    1111#include <cstring>
     12#include <cassert>
    1213
    1314#include "element.hpp"
     
    1819#include "verbose.hpp"
    1920
     21using namespace std;
     22
    2023/************************************* Functions for class periodentafel ***************************/
    2124
     
    2326 * Initialises start and end of list and resets periodentafel::checkliste to false.
    2427 */
    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 };
     28periodentafel::periodentafel()
     29{};
    3230
    3331/** destructor for class periodentafel
     
    3735{
    3836  CleanupPeriodtable();
    39   delete(end);
    40   delete(start);
    4137};
    4238
     
    4541 * \return true - succeeded, false - does not occur
    4642 */
    47 bool periodentafel::AddElement(element * const pointer)
    48 {
     43periodentafel::iterator periodentafel::AddElement(element * const pointer)
     44{
     45  atomicNumber_t Z = pointer->getNumber();
     46  assert(!elements.count(Z));
    4947  pointer->sort = &pointer->Z;
    50   if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS)
     48  if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS)
    5149    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;
    5352};
    5453
     
    5756 * \return true - succeeded, false - element not found
    5857 */
    59 bool periodentafel::RemoveElement(element * const pointer)
    60 {
    61   return remove(pointer, start, end);
     58void periodentafel::RemoveElement(element * const pointer)
     59{
     60  atomicNumber_t Z = pointer->getNumber();
     61  elements.erase(Z);
    6262};
    6363
     
    6565 * \return true - succeeded, false - does not occur
    6666 */
    67 bool periodentafel::CleanupPeriodtable()
    68 {
    69   return cleanup(start,end);
     67void periodentafel::CleanupPeriodtable()
     68{
     69  for(iterator iter=elements.begin();iter!=elements.end();++iter){
     70    delete(*iter).second;
     71  }
     72  elements.clear();
    7073};
    7174
     
    7578 * \return pointer to element or NULL if not found
    7679 */
    77 element * const periodentafel::FindElement(const int Z) const
    78 {
    79   element *walker = find(&Z, start,end);
    80   return(walker);
     80const element * periodentafel::FindElement(atomicNumber_t Z) const
     81{
     82  const_iterator res = elements.find(Z);
     83  return res!=elements.end()?((*res).second):0;
    8184};
    8285
     
    8689 * \return pointer to element
    8790 */
    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);
     91const 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;
    97101};
    98102
    99103/** Asks for element number and returns pointer to element
    100104 */
    101 element * const periodentafel::AskElement() const
    102 {
    103   element *walker = NULL;
     105const element * periodentafel::AskElement() const
     106{
     107  const element *walker = NULL;
    104108  int Z;
    105109  do {
     
    114118 * \return pointer to either present or newly created element
    115119 */
    116 element * const periodentafel::EnterElement()
    117 {
    118   element *walker = NULL;
    119   int Z = -1;
     120const element * periodentafel::EnterElement()
     121{
     122  const element *res = NULL;
     123  atomicNumber_t Z = 0;
    120124  Log() << Verbose(0) << "Atomic number: " << Z << endl;
    121125  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;
    124130    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;
    127133    Log() << Verbose(0) << "Mass: " << endl;
    128     cin >> walker->mass;
     134    cin >> tmp->mass;
    129135    Log() << Verbose(0) << "Name [max 64 chars]: " << endl;
    130     cin >> walker->name;
     136    cin >> tmp->name;
    131137    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 ****************************/
     147periodentafel::const_iterator periodentafel::begin(){
     148  return elements.begin();
     149}
     150
     151periodentafel::const_iterator periodentafel::end(){
     152  return elements.end();
     153}
     154
     155periodentafel::reverse_iterator periodentafel::rbegin(){
     156  return reverse_iterator(elements.end());
     157}
     158
     159periodentafel::reverse_iterator periodentafel::rend(){
     160  return reverse_iterator(elements.begin());
     161}
    137162
    138163/** Prints period table to given stream.
    139164 * \param output stream
    140165 */
    141 bool periodentafel::Output(ofstream * const output) const
     166bool periodentafel::Output(ostream * const output) const
    142167{
    143168  bool result = true;
    144   element *walker = start;
    145169  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);
    149172    }
    150173    return result;
     
    157180 * \param *checkliste elements table for this molecule
    158181 */
    159 bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const
    160 {
    161   element *walker = start;
     182bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const
     183{
    162184  bool result = true;
    163185  int No = 1;
     
    166188    *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl;
    167189    *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]);
    173194      }
    174195    }
     
    184205{
    185206  ifstream infile;
    186   double tmp;
    187207  element *ptr;
     208  map<atomicNumber_t,element*> parsedElems;
    188209  bool status = true;
    189210  bool otherstatus = true;
     
    223244      //neues->Output((ofstream *)&cout);
    224245      if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))
    225         periodentafel::AddElement(neues);
     246        parsedElems[neues->getNumber()] = neues;
    226247      else {
    227248        Log() << Verbose(0) << "Could not parse element: ";
     
    243264  if (infile != NULL) {
    244265    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;
    248270      infile >> ws;
    249271      //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
     
    261283  if (infile != NULL) {
    262284    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;
    266289      infile >> ws;
    267290      //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
     
    279302  if (infile != NULL) {
    280303    while (!infile.eof()) {
    281       infile >> tmp;
    282       ptr = FindElement((int)tmp);
     304      atomicNumber_t Z;
     305      infile >> Z;
     306      ptr = parsedElems[Z];
    283307      infile >> ws;
    284308      infile >> ptr->HBondDistance[0];
     
    300324  if (infile != NULL) {
    301325    while (!infile.eof()) {
    302       infile >> tmp;
    303       ptr = FindElement((int)tmp);
     326      atomicNumber_t Z;
     327      infile >> Z;
     328      ptr = parsedElems[Z];
    304329      infile >> ws;
    305330      infile >> ptr->HBondAngle[0];
     
    313338    otherstatus = false;
    314339
    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{
    316347    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  }
    317353
    318354  return status;
     
    334370    f << header1 << endl;
    335371    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);
    340374    }
    341375    f.close();
  • src/periodentafel.hpp

    r9131f3 r4415da  
    11#ifndef PERIODENTAFEL_HPP_
    22#define PERIODENTAFEL_HPP_
    3 
    4 using namespace std;
    53
    64/*********************************************** includes ***********************************/
     
    1210
    1311#include <iostream>
     12#include <map>
     13#include <iterator>
    1414
    1515#include "defs.hpp"
     16#include "types.hpp"
    1617
    1718/****************************************** forward declarations *****************************/
     
    2526 */
    2627class periodentafel {
     28  /******* Types *********/
     29  private:
     30    typedef std::map<atomicNumber_t,element*> elementSet;
    2731  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
    3037    char header1[MAXSTRINGSIZE]; //!< store first header line
    3138    char header2[MAXSTRINGSIZE]; //!< store second header line
     
    3441  ~periodentafel();
    3542
    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;
    4557  bool LoadPeriodentafel(const char * const path);
    4658  bool StorePeriodentafel(const char * const path) const;
    4759
    4860  private:
     61    elementSet elements;
    4962};
    5063
  • src/unittests/ActionSequenceTest.cpp

    r9131f3 r4415da  
    3535  virtual ~canUndoActionStub(){}
    3636
    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  }
    3946  virtual bool canUndo(){
     47    return true;
     48  }
     49  virtual bool shouldUndo(){
    4050    return true;
    4151  }
     
    4858  virtual ~cannotUndoActionStub(){}
    4959
    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  }
    5269  virtual bool canUndo(){
    5370    return false;
     71  }
     72  virtual bool shouldUndo(){
     73   return true;
    5474  }
    5575};
     
    6484  virtual ~wasCalledActionStub(){}
    6585
    66   virtual void call(){
     86  virtual Action::state_ptr performCall(){
    6787    called = true;
    68   }
    69   virtual void undo(){
     88    return Action::success;
     89  }
     90  virtual Action::state_ptr performUndo(Action::state_ptr){
    7091    called = false;
     92    return Action::success;
     93  }
     94  virtual Action::state_ptr performRedo(Action::state_ptr){
     95    called = true;
     96    return Action::success;
    7197  }
    7298  virtual bool canUndo(){
     99    return true;
     100  }
     101  virtual bool shouldUndo(){
    73102    return true;
    74103  }
     
    185214  sequence->addAction(shouldCall2);
    186215
    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);
    193222
    194223  CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r9131f3 r4415da  
    5757
    5858  // construct periodentafel
    59   tafel = World::get()->getPeriode();
     59  tafel = World::getInstance().getPeriode();
    6060  tafel->AddElement(hydrogen);
    6161
    6262  // 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();
    6565  Walker->type = hydrogen;
    6666  Walker->node->Init(1., 0., 1. );
    6767  TestMolecule->AddAtom(Walker);
    68   Walker = World::get()->createAtom();
     68  Walker = World::getInstance().createAtom();
    6969  Walker->type = hydrogen;
    7070  Walker->node->Init(0., 1., 1. );
    7171  TestMolecule->AddAtom(Walker);
    72   Walker = World::get()->createAtom();
     72  Walker = World::getInstance().createAtom();
    7373  Walker->type = hydrogen;
    7474  Walker->node->Init(1., 1., 0. );
    7575  TestMolecule->AddAtom(Walker);
    76   Walker = World::get()->createAtom();
     76  Walker = World::getInstance().createAtom();
    7777  Walker->type = hydrogen;
    7878  Walker->node->Init(0., 0., 0. );
     
    8282  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8383
    84   TestList = World::get()->getMolecules();
     84  TestList = World::getInstance().getMolecules();
    8585  TestMolecule->ActiveFlag = true;
    8686  TestList->insert(TestMolecule);
     
    104104
    105105  delete(point);
    106   World::destroy();
     106  World::purgeInstance();
    107107  MemoryUsageObserver::purgeInstance();
    108108  logger::purgeInstance();
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r9131f3 r4415da  
    2727#include "World.hpp"
    2828
     29#include "Helpers/Assert.hpp"
     30
    2931#ifdef HAVE_TESTRUNNER
    3032#include "UnitTestMain.hpp"
     
    3840void AnalysisCorrelationToSurfaceUnitTest::setUp()
    3941{
     42  ASSERT_DO(Assert::Throw);
     43
    4044  atom *Walker = NULL;
    4145
     
    6165
    6266  // construct periodentafel
    63   tafel = World::get()->getPeriode();
     67  tafel = World::getInstance().getPeriode();
    6468  tafel->AddElement(hydrogen);
    6569  tafel->AddElement(carbon);
    6670
    6771  // 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();
    7074  Walker->type = hydrogen;
    7175  Walker->node->Init(1., 0., 1. );
    7276  TestMolecule->AddAtom(Walker);
    73   Walker = World::get()->createAtom();
     77  Walker = World::getInstance().createAtom();
    7478  Walker->type = hydrogen;
    7579  Walker->node->Init(0., 1., 1. );
    7680  TestMolecule->AddAtom(Walker);
    77   Walker = World::get()->createAtom();
     81  Walker = World::getInstance().createAtom();
    7882  Walker->type = hydrogen;
    7983  Walker->node->Init(1., 1., 0. );
    8084  TestMolecule->AddAtom(Walker);
    81   Walker = World::get()->createAtom();
     85  Walker = World::getInstance().createAtom();
    8286  Walker->type = hydrogen;
    8387  Walker->node->Init(0., 0., 0. );
     
    8791  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8892
    89   TestList = World::get()->getMolecules();
     93  TestList = World::getInstance().getMolecules();
    9094  TestMolecule->ActiveFlag = true;
    9195  TestList->insert(TestMolecule);
     
    100104
    101105  // add outer atoms
    102   Walker = World::get()->createAtom();
     106  Walker = World::getInstance().createAtom();
    103107  Walker->type = carbon;
    104108  Walker->node->Init(4., 0., 4. );
    105109  TestMolecule->AddAtom(Walker);
    106   Walker = World::get()->createAtom();
     110  Walker = World::getInstance().createAtom();
    107111  Walker->type = carbon;
    108112  Walker->node->Init(0., 4., 4. );
    109113  TestMolecule->AddAtom(Walker);
    110   Walker = World::get()->createAtom();
     114  Walker = World::getInstance().createAtom();
    111115  Walker->type = carbon;
    112116  Walker->node->Init(4., 4., 0. );
    113117  TestMolecule->AddAtom(Walker);
    114118  // add inner atoms
    115   Walker = World::get()->createAtom();
     119  Walker = World::getInstance().createAtom();
    116120  Walker->type = carbon;
    117121  Walker->node->Init(0.5, 0.5, 0.5 );
     
    135139  // note that all the atoms are cleaned by TestMolecule
    136140  delete(LC);
    137   World::destroy();
     141  World::purgeInstance();
    138142  MemoryUsageObserver::purgeInstance();
    139143  logger::purgeInstance();
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r9131f3 r4415da  
    5656
    5757  // construct periodentafel
    58   tafel = World::get()->getPeriode();
     58  tafel = World::getInstance().getPeriode();
    5959  tafel->AddElement(hydrogen);
    6060
    6161  // 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();
    6464  Walker->type = hydrogen;
    6565  Walker->node->Init(1., 0., 1. );
    6666  TestMolecule->AddAtom(Walker);
    67   Walker = World::get()->createAtom();
     67  Walker = World::getInstance().createAtom();
    6868  Walker->type = hydrogen;
    6969  Walker->node->Init(0., 1., 1. );
    7070  TestMolecule->AddAtom(Walker);
    71   Walker = World::get()->createAtom();
     71  Walker = World::getInstance().createAtom();
    7272  Walker->type = hydrogen;
    7373  Walker->node->Init(1., 1., 0. );
    7474  TestMolecule->AddAtom(Walker);
    75   Walker = World::get()->createAtom();
     75  Walker = World::getInstance().createAtom();
    7676  Walker->type = hydrogen;
    7777  Walker->node->Init(0., 0., 0. );
     
    8181  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8282
    83   TestList = World::get()->getMolecules();
     83  TestList = World::getInstance().getMolecules();
    8484  TestMolecule->ActiveFlag = true;
    8585  TestList->insert(TestMolecule);
     
    100100
    101101  // note that all the atoms are cleaned by TestMolecule
    102   World::destroy();
     102  World::purgeInstance();
    103103  MemoryUsageObserver::purgeInstance();
    104104  logger::purgeInstance();
  • src/unittests/AtomDescriptorTest.cpp

    r9131f3 r4415da  
    2929// set up and tear down
    3030void AtomDescriptorTest::setUp(){
    31   World::get();
     31  World::getInstance();
    3232  for(int i=0;i<ATOM_COUNT;++i){
    33     atoms[i]= World::get()->createAtom();
     33    atoms[i]= World::getInstance().createAtom();
    3434    atomIds[i]= atoms[i]->getId();
    3535  }
     
    3737
    3838void AtomDescriptorTest::tearDown(){
    39   World::destroy();
     39  World::purgeInstance();
    4040}
    4141
     
    7373
    7474void AtomDescriptorTest::AtomBaseSetsTest(){
    75   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     75  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    7676  CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
    7777  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
    7878
    79   std::vector<atom*> noAtoms = World::get()->getAllAtoms(NoAtoms());
     79  std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms());
    8080  CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
    8181}
     
    8383  // test Atoms from boundaries and middle of the set
    8484  atom* testAtom;
    85   testAtom = World::get()->getAtom(AtomById(atomIds[0]));
     85  testAtom = World::getInstance().getAtom(AtomById(atomIds[0]));
    8686  CPPUNIT_ASSERT(testAtom);
    8787  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]));
    8989  CPPUNIT_ASSERT(testAtom);
    9090  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]));
    9292  CPPUNIT_ASSERT(testAtom);
    9393  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
     
    103103  }
    104104  // test from outside of set
    105   testAtom = World::get()->getAtom(AtomById(outsideId));
     105  testAtom = World::getInstance().getAtom(AtomById(outsideId));
    106106  CPPUNIT_ASSERT(!testAtom);
    107107}
     
    109109  // test some elementary set operations
    110110  {
    111     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
     111    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms());
    112112    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    113113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    115115
    116116  {
    117     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
     117    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms());
    118118    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    119119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    121121
    122122  {
    123     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()&&AllAtoms());
     123    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms());
    124124    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    125125  }
    126126
    127127  {
    128     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&NoAtoms());
     128    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms());
    129129    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    130130  }
    131131
    132132  {
    133     std::vector<atom*> testAtoms = World::get()->getAllAtoms(!AllAtoms());
     133    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms());
    134134    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    135135  }
    136136
    137137  {
    138     std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
     138    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms());
    139139    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    140140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
    141141  }
    142 
    143142  // exclude and include some atoms
    144143  {
    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])));
    146145    std::set<atomId_t> excluded;
    147146    excluded.insert(atomIds[ATOM_COUNT/2]);
     
    152151
    153152  {
    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])));
    155154    CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
    156155    CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
  • src/unittests/AtomDescriptorTest.hpp

    r9131f3 r4415da  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "defs.hpp"
     13#include "types.hpp"
    1414
    1515#define ATOM_COUNT (10)
  • src/unittests/CacheableTest.cpp

    r9131f3 r4415da  
    2727class threeNumbers : public Observable {
    2828public:
    29   bool hasRecalced;
    3029  int x;
    3130  int y;
    3231  int z;
     32  Cacheable<int> sum;
     33  bool hasRecalced;
    3334
    3435  void setX(int _x){
     
    5455
    5556  threeNumbers(int _x,int _y, int _z) :
     57    x(_x),y(_y),z(_z),
    5658    sum(this,boost::bind(&threeNumbers::calcSum,this)),
    57     x(_x),y(_y),z(_z),
    5859    hasRecalced(false)
    5960  {}
    60 
    61   Cacheable<int> sum;
    6261};
    6362
  • src/unittests/Makefile.am

    r9131f3 r4415da  
    2929  ObserverTest \
    3030  ParserUnitTest \
     31  SingletonTest \
    3132  StackClassUnitTest \
    3233  TesselationUnitTest \
     
    6869  ObserverTest.cpp \
    6970  ParserUnitTest.cpp \
     71  SingletonTest.cpp \
    7072  stackclassunittest.cpp \
    7173  tesselationunittest.cpp \
     
    9193AnalysisPairCorrelationUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp
    9294AnalysisPairCorrelationUnitTest_LDADD = ${ALLLIBS}
     95
     96atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
     97atomsCalculationTest_LDADD = ${ALLLIBS}
    9398
    9499BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp
     
    125130MoleculeDescriptorTest_LDADD = ${ALLLIBS}
    126131
     132SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp
     133SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB}
     134
    127135StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp
    128136StackClassUnitTest_LDADD = ${ALLLIBS}
     
    158166manipulateAtomsTest_LDADD = ${ALLLIBS}
    159167
    160 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
    161 atomsCalculationTest_LDADD = ${ALLLIBS}
    162 
    163168TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
    164169TestRunner_LDADD = ${ALLLIBS}
  • src/unittests/MoleculeDescriptorTest.cpp

    r9131f3 r4415da  
    2929// set up and tear down
    3030void MoleculeDescriptorTest::setUp(){
    31   World::get();
     31  World::getInstance();
    3232  for(int i=0;i<MOLECULE_COUNT;++i){
    33     molecules[i]= World::get()->createMolecule();
     33    molecules[i]= World::getInstance().createMolecule();
    3434    moleculeIds[i]= molecules[i]->getId();
    3535  }
     
    3737
    3838void MoleculeDescriptorTest::tearDown(){
    39   World::destroy();
     39  World::purgeInstance();
    4040}
    4141
     
    7373
    7474void MoleculeDescriptorTest::MoleculeBaseSetsTest(){
    75   std::vector<molecule*> allMolecules = World::get()->getAllMolecules(AllMolecules());
     75  std::vector<molecule*> allMolecules = World::getInstance().getAllMolecules(AllMolecules());
    7676  CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(allMolecules,moleculeIds));
    7777  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(allMolecules));
    7878
    79   std::vector<molecule*> noMolecules = World::get()->getAllMolecules(NoMolecules());
     79  std::vector<molecule*> noMolecules = World::getInstance().getAllMolecules(NoMolecules());
    8080  CPPUNIT_ASSERT_EQUAL( true , noMolecules.empty());
    8181}
     
    8383  // test Molecules from boundaries and middle of the set
    8484  molecule* testMolecule;
    85   testMolecule = World::get()->getMolecule(MoleculeById(moleculeIds[0]));
     85  testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[0]));
    8686  CPPUNIT_ASSERT(testMolecule);
    8787  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]));
    8989  CPPUNIT_ASSERT(testMolecule);
    9090  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]));
    9292  CPPUNIT_ASSERT(testMolecule);
    9393  CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT-1], testMolecule->getId());
     
    103103  }
    104104  // test from outside of set
    105   testMolecule = World::get()->getMolecule(MoleculeById(outsideId));
     105  testMolecule = World::getInstance().getMolecule(MoleculeById(outsideId));
    106106  CPPUNIT_ASSERT(!testMolecule);
    107107}
     
    109109  // test some elementary set operations
    110110  {
    111     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()||NoMolecules());
     111    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()||NoMolecules());
    112112    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    113113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    115115
    116116  {
    117     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()||AllMolecules());
     117    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||AllMolecules());
    118118    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    119119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    121121
    122122  {
    123     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()&&AllMolecules());
     123    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()&&AllMolecules());
    124124    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    125125  }
    126126
    127127  {
    128     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()&&NoMolecules());
     128    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&NoMolecules());
    129129    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    130130  }
    131131
    132132  {
    133     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(!AllMolecules());
     133    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!AllMolecules());
    134134    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    135135  }
    136136
    137137  {
    138     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(!NoMolecules());
     138    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!NoMolecules());
    139139    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    140140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    143143  // exclude and include some molecules
    144144  {
    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])));
    146146    std::set<moleculeId_t> excluded;
    147147    excluded.insert(moleculeIds[MOLECULE_COUNT/2]);
     
    152152
    153153  {
    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])));
    155155    CPPUNIT_ASSERT_EQUAL( (size_t)1, testMolecules.size());
    156156    CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecules[0]->getId());
  • src/unittests/MoleculeDescriptorTest.hpp

    r9131f3 r4415da  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "defs.hpp"
     13#include "types.hpp"
    1414
    1515#define MOLECULE_COUNT (10)
  • src/unittests/ObserverTest.cpp

    r9131f3 r4415da  
    1313
    1414#include "Patterns/Observer.hpp"
     15#include "Helpers/Assert.hpp"
    1516
    1617#include <iostream>
     
    6566};
    6667
     68class BlockObservable : public Observable {
     69public:
     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
    67102class SuperObservable : public Observable {
    68103public:
     
    86121
    87122void ObserverTest::setUp() {
     123  ASSERT_DO(Assert::Throw);
    88124  simpleObservable1 = new SimpleObservable();
    89125  simpleObservable2 = new SimpleObservable();
    90126  callObservable = new CallObservable();
    91127  superObservable = new SuperObservable();
     128  blockObservable = new BlockObservable();
    92129
    93130  observer1 = new UpdateCountObserver();
     
    163200}
    164201
     202void ObserverTest::doesReportTest(){
     203  // Actual checks are in the Stub-methods for this
     204  blockObservable->changeMethod1();
     205  blockObservable->changeMethod2();
     206  blockObservable->noChangeMethod();
     207}
    165208
    166209void ObserverTest::CircleDetectionTest() {
     
    174217  // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE
    175218  simpleObservable1->signOn(simpleObservable1);
    176   simpleObservable1->changeMethod();
     219  CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
    177220
    178221  // more complex test
     
    180223  simpleObservable1->signOn(simpleObservable2);
    181224  simpleObservable2->signOn(simpleObservable1);
    182   simpleObservable1->changeMethod();
     225  CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
    183226  simpleObservable1->signOff(simpleObservable2);
    184227  simpleObservable2->signOff(simpleObservable1);
  • src/unittests/ObserverTest.hpp

    r9131f3 r4415da  
    1616class CallObservable;
    1717class SuperObservable;
     18class BlockObservable;
    1819
    1920
     
    2425  CPPUNIT_TEST ( doesBlockUpdateTest );
    2526  CPPUNIT_TEST ( doesSubObservableTest );
     27  CPPUNIT_TEST ( doesReportTest );
    2628  CPPUNIT_TEST ( CircleDetectionTest );
    2729  CPPUNIT_TEST_SUITE_END();
     
    3436  void doesBlockUpdateTest();
    3537  void doesSubObservableTest();
     38  void doesReportTest();
    3639  void CircleDetectionTest();
    3740
     
    4548  SimpleObservable *simpleObservable2;
    4649  CallObservable *callObservable;
     50  BlockObservable *blockObservable;
    4751  SuperObservable *superObservable;
    4852};
  • src/unittests/ParserUnitTest.cpp

    r9131f3 r4415da  
    3232  oxygen->symbol[0] = 'O';
    3333  oxygen->Z = 8;
    34   World::get()->getPeriode()->AddElement(oxygen);
     34  World::getInstance().getPeriode()->AddElement(oxygen);
    3535
    3636  element* hydrogen = new element();
    3737  hydrogen->symbol[0] = 'H';
    3838  hydrogen->Z = 1;
    39   World::get()->getPeriode()->AddElement(hydrogen);
     39  World::getInstance().getPeriode()->AddElement(hydrogen);
    4040}
    4141
     
    5353  testParser->load(&input);
    5454
    55   CPPUNIT_ASSERT_EQUAL(3, World::get()->numAtoms());
     55  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    5656
    5757  string newWaterXyz = "";
     
    6666  cout << "Testing the tremolo parser." << endl;
    6767  TremoloParser* testParser = new TremoloParser();
     68  stringstream input;
     69
     70  // Atomdata beginning with "# ATOMDATA"
    6871  string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n";
    69   stringstream input;
    7072  input << waterTremolo;
    7173  testParser->load(&input);
     74  input.clear();
     75
     76  // Atomdata beginning with "#ATOMDATA"
    7277  waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n";
    73   input.clear();
    7478  input << waterTremolo;
    7579  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
    7694  cout << "testing the tremolo parser is done" << endl;
    7795}
  • src/unittests/analysisbondsunittest.cpp

    r9131f3 r4415da  
    5353  strcpy(hydrogen->symbol, "H");
    5454  carbon = new element;
    55   carbon->Z = 1;
     55  carbon->Z = 2;
    5656  carbon->Valence = 4;
    5757  carbon->NoValenceOrbitals = 4;
     
    6161
    6262  // construct periodentafel
    63   tafel = World::get()->getPeriode();
     63  tafel = World::getInstance().getPeriode();
    6464  tafel->AddElement(hydrogen);
    6565  tafel->AddElement(carbon);
    6666
    6767  // 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();
    7070  Walker->type = hydrogen;
    7171  Walker->node->Init(1.5, 0., 1.5 );
    7272  TestMolecule->AddAtom(Walker);
    73   Walker = World::get()->createAtom();
     73  Walker = World::getInstance().createAtom();
    7474  Walker->type = hydrogen;
    7575  Walker->node->Init(0., 1.5, 1.5 );
    7676  TestMolecule->AddAtom(Walker);
    77   Walker = World::get()->createAtom();
     77  Walker = World::getInstance().createAtom();
    7878  Walker->type = hydrogen;
    7979  Walker->node->Init(1.5, 1.5, 0. );
    8080  TestMolecule->AddAtom(Walker);
    81   Walker = World::get()->createAtom();
     81  Walker = World::getInstance().createAtom();
    8282  Walker->type = hydrogen;
    8383  Walker->node->Init(0., 0., 0. );
    8484  TestMolecule->AddAtom(Walker);
    85   Walker = World::get()->createAtom();
     85  Walker = World::getInstance().createAtom();
    8686  Walker->type = carbon;
    8787  Walker->node->Init(0.5, 0.5, 0.5 );
     
    117117
    118118  // remove molecule
    119   World::get()->destroyMolecule(TestMolecule);
     119  World::getInstance().destroyMolecule(TestMolecule);
    120120  // note that all the atoms are cleaned by TestMolecule
    121   World::destroy();
     121  World::purgeInstance();
    122122};
    123123
  • src/unittests/atomsCalculationTest.cpp

    r9131f3 r4415da  
    2424#include "atom.hpp"
    2525
     26#ifdef HAVE_TESTRUNNER
     27#include "UnitTestMain.hpp"
     28#endif /*HAVE_TESTRUNNER*/
     29
    2630// Registers the fixture into the 'registry'
    2731CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest );
    2832
    29 // some stubs
    30 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 
    5133// set up and tear down
    5234void atomsCalculationTest::setUp(){
    53   World::get();
     35  World::getInstance();
    5436  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();
    5739  }
    5840}
    5941void atomsCalculationTest::tearDown(){
    60   World::destroy();
    61   ActionRegistry::purgeRegistry();
     42  World::purgeInstance();
     43  ActionRegistry::purgeInstance();
    6244}
    6345
    6446// 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;
     47static 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;
    6952      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;
    7255      }
    7356      if(!res) {
    74         cout << "Atom " << i << " missing in returned list" << endl;
     57        cout << "Atom " << id << " missing in returned list" << endl;
    7558        return false;
    7659      }
     
    8063}
    8164
    82 static bool hasNoDuplicates(std::vector<int> ids){
    83   std::set<int> found;
    84   std::vector<int>::iterator iter;
     65static bool hasNoDuplicates(std::vector<atomId_t> ids){
     66  std::set<atomId_t> found;
     67  std::vector<atomId_t>::iterator iter;
    8568  for(iter=ids.begin();iter!=ids.end();++iter){
    8669    int id = (*iter);
     
    9275}
    9376
    94 static void operation(atom* _atom){
    95   AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
    96   assert(atom);
    97   atom->doSomething();
    98 }
    99 
    100 
    10177void 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));
    10581  CPPUNIT_ASSERT(hasNoDuplicates(allIds));
    10682}
    10783
    10884void 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;
    11389  excluded_set.insert(excluded);
    114   CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT,excluded_set));
     90  CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set));
    11591  CPPUNIT_ASSERT(hasNoDuplicates(allIds));
    11692  CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size());
  • src/unittests/atomsCalculationTest.hpp

    r9131f3 r4415da  
    1212
    1313#define ATOM_COUNT (10)
     14
     15#include "types.hpp"
    1416
    1517class atom;
     
    3133private:
    3234  atom *atoms [ATOM_COUNT];
    33   int atomIds [ATOM_COUNT];
     35  atomId_t atomIds [ATOM_COUNT];
    3436};
    3537
  • src/unittests/bondgraphunittest.cpp

    r9131f3 r4415da  
    5151  strcpy(hydrogen->symbol, "H");
    5252  carbon = new element;
    53   carbon->Z = 1;
     53  carbon->Z = 2;
    5454  strcpy(carbon->name, "carbon");
    5555  strcpy(carbon->symbol, "C");
     
    5757
    5858  // construct periodentafel
    59   tafel = World::get()->getPeriode();
     59  tafel = World::getInstance().getPeriode();
    6060  tafel->AddElement(hydrogen);
    6161  tafel->AddElement(carbon);
    6262
    6363  // 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();
    6666  Walker->type = hydrogen;
    6767  Walker->node->Init(1., 0., 1. );
    6868  TestMolecule->AddAtom(Walker);
    69   Walker = World::get()->createAtom();
     69  Walker = World::getInstance().createAtom();
    7070  Walker->type = hydrogen;
    7171  Walker->node->Init(0., 1., 1. );
    7272  TestMolecule->AddAtom(Walker);
    73   Walker = World::get()->createAtom();
     73  Walker = World::getInstance().createAtom();
    7474  Walker->type = hydrogen;
    7575  Walker->node->Init(1., 1., 0. );
    7676  TestMolecule->AddAtom(Walker);
    77   Walker = World::get()->createAtom();
     77  Walker = World::getInstance().createAtom();
    7878  Walker->type = hydrogen;
    7979  Walker->node->Init(0., 0., 0. );
     
    102102
    103103  // remove molecule
    104   World::get()->destroyMolecule(TestMolecule);
     104  World::getInstance().destroyMolecule(TestMolecule);
    105105  // note that all the atoms, molecules, the tafel and the elements
    106106  // are all cleaned when the world is destroyed
    107   World::destroy();
     107  World::purgeInstance();
    108108  MemoryUsageObserver::purgeInstance();
    109109  logger::purgeInstance();
  • src/unittests/listofbondsunittest.cpp

    r9131f3 r4415da  
    5151
    5252  // construct periodentafel
    53   tafel = World::get()->getPeriode();
     53  tafel = World::getInstance().getPeriode();
    5454  tafel->AddElement(hydrogen);
    5555
    5656  // 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();
    5959  Walker->type = hydrogen;
    6060  Walker->node->Init(1., 0., 1. );
    6161  TestMolecule->AddAtom(Walker);
    62   Walker = World::get()->createAtom();
     62  Walker = World::getInstance().createAtom();
    6363  Walker->type = hydrogen;
    6464  Walker->node->Init(0., 1., 1. );
    6565  TestMolecule->AddAtom(Walker);
    66   Walker = World::get()->createAtom();
     66  Walker = World::getInstance().createAtom();
    6767  Walker->type = hydrogen;
    6868  Walker->node->Init(1., 1., 0. );
    6969  TestMolecule->AddAtom(Walker);
    70   Walker = World::get()->createAtom();
     70  Walker = World::getInstance().createAtom();
    7171  Walker->type = hydrogen;
    7272  Walker->node->Init(0., 0., 0. );
     
    8282{
    8383  // remove
    84   World::get()->destroyMolecule(TestMolecule);
     84  World::getInstance().destroyMolecule(TestMolecule);
    8585  // note that all the atoms, molecules, the tafel and the elements
    8686  // are all cleaned when the world is destroyed
    87   World::destroy();
     87  World::purgeInstance();
    8888  MemoryUsageObserver::purgeInstance();
    8989  logger::purgeInstance();
     
    250250
    251251  // remove atom2
    252   World::get()->destroyAtom(atom2);
     252  World::getInstance().destroyAtom(atom2);
    253253
    254254  // check bond if removed from other atom
  • src/unittests/logunittest.cpp

    r9131f3 r4415da  
    4040void LogTest::logTest()
    4141{
    42   logger::getInstance()->setVerbosity(2);
     42  logger::getInstance().setVerbosity(2);
    4343  Log() << Verbose(0) << "Verbosity level is set to 2." << endl;
    4444  Log() << Verbose(0) << "Test level 0" << endl;
  • src/unittests/manipulateAtomsTest.cpp

    r9131f3 r4415da  
    1818#include "Actions/ManipulateAtomsProcess.hpp"
    1919#include "Actions/ActionRegistry.hpp"
     20#include "Actions/ActionHistory.hpp"
    2021
    2122#include "World.hpp"
    2223#include "atom.hpp"
     24
     25#ifdef HAVE_TESTRUNNER
     26#include "UnitTestMain.hpp"
     27#endif /*HAVE_TESTRUNNER*/
    2328
    2429// Registers the fixture into the 'registry'
     
    3035  AtomStub(int _id) :
    3136  atom(),
    32   id(_id),
    33   manipulated(false)
     37  manipulated(false),
     38  id(_id)
    3439  {}
    3540
     
    6671// set up and tear down
    6772void manipulateAtomsTest::setUp(){
    68   World::get();
     73  ActionHistory::init();
     74  World::getInstance();
    6975  for(int i=0;i<ATOM_COUNT;++i){
    7076    atoms[i]= new AtomStub(i);
    71     World::get()->registerAtom(atoms[i]);
     77    World::getInstance().registerAtom(atoms[i]);
    7278  }
    7379}
    7480void 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();
    10784}
    10885
     
    11592
    11693void 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());
    11895  proc->call();
    119   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     96  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    12097  std::vector<atom*>::iterator iter;
    12198  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    128105
    129106void 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));
    131109  proc->call();
    132   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     110  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    133111  std::vector<atom*>::iterator iter;
    134112  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    145123void manipulateAtomsTest::testObserver(){
    146124  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());
    149127  proc->call();
    150128
    151129  CPPUNIT_ASSERT_EQUAL(1,obs->count);
    152   World::get()->signOff(obs);
     130  World::getInstance().signOff(obs);
    153131  delete obs;
    154132}
Note: See TracChangeset for help on using the changeset viewer.