Changes in / [66e95e:b31bc4]


Ignore:
Location:
src
Files:
13 added
1 deleted
81 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    r66e95e rb31bc4  
    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}
  • src/Actions/Action.hpp

    r66e95e rb31bc4  
    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;
    3245
    3346  virtual const std::string getName();
    3447
     48protected:
     49  static state_ptr success;
     50  static state_ptr failure;
     51
    3552private:
     53  virtual state_ptr performCall()=0;
     54  virtual state_ptr performUndo(state_ptr)=0;
     55  virtual state_ptr performRedo(state_ptr)=0;
     56
    3657  std::string name;
    3758};
    3859
     60/**
     61 * This class can be used by actions to save the state.
     62 *
     63 * It is implementing a memento pattern. The base class is completely empty,
     64 * since no general state internals can be given. The Action performing
     65 * the Undo should downcast to the apropriate type.
     66 */
     67class ActionState{
     68public:
     69  ActionState(){}
     70  virtual ~ActionState(){}
     71};
     72
    3973#endif /* ACTION_H_ */
  • src/Actions/ActionRegistry.cpp

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

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

    r66e95e rb31bc4  
    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

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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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
    1337PATTERNSOURCE = Patterns/Observer.cpp
    14 PATTERNHEADER = Patterns/Observer.hpp Patterns/Cacheable.hpp
     38PATTERNHEADER = Patterns/Cacheable.hpp \
     39                                Patterns/Observer.hpp \
     40                Patterns/Singleton.hpp
    1541
    1642VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp
     
    3359                                   Descriptors/AtomTypeDescriptor.cpp \
    3460                                   Descriptors/MoleculeDescriptor.cpp \
    35                                    Descriptors/MoleculeIdDescriptor.cpp
     61                                   Descriptors/MoleculeIdDescriptor.cpp
     62                                   
    3663                                   
    3764DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \
     
    4067                                   Descriptors/MoleculeDescriptor.hpp \
    4168                                   Descriptors/MoleculeIdDescriptor.hpp
     69                                   
    4270
    43 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${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
     71
     72SOURCE = ${ANALYSISSOURCE} \
     73                 ${ATOMSOURCE} \
     74                 ${PATTERNSOURCE} \
     75                 ${UISOURCE} \
     76                 ${DESCRIPTORSOURCE} \
     77                 ${LEGACYSOURCE} \
     78                 bond.cpp \
     79                 bondgraph.cpp \
     80                 boundary.cpp \
     81                 config.cpp \
     82                 element.cpp \
     83                 ellipsoid.cpp \
     84                 errorlogger.cpp \
     85                 graph.cpp \
     86                 helpers.cpp \
     87                 Helpers/Assert.cpp \
     88                 info.cpp \
     89                 leastsquaremin.cpp \
     90                 linkedcell.cpp \
     91                 lists.cpp \
     92                 log.cpp \
     93                 logger.cpp \
     94                 memoryusageobserver.cpp \
     95                 moleculelist.cpp \
     96                 molecule.cpp \
     97                 molecule_dynamics.cpp \
     98                 molecule_fragmentation.cpp \
     99                 molecule_geometry.cpp \
     100                 molecule_graph.cpp \
     101                 molecule_pointcloud.cpp \
     102                 parser.cpp \
     103                 periodentafel.cpp \
     104                 tesselation.cpp \
     105                 tesselationhelpers.cpp \
     106                 vector.cpp \
     107                 verbose.cpp \
     108                 World.cpp
    44109HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${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
    45110
  • src/Menu/TextMenu.cpp

    r66e95e rb31bc4  
    1111#include "Menu/TextMenu.hpp"
    1212#include "Menu/MenuItem.hpp"
     13#include "Helpers/Assert.hpp"
    1314
    1415
     
    8889}
    8990
     91string TextMenu::getTitle(){
     92  return title;
     93}
     94
    9095void TextMenu::addDefault(MenuItem* _defaultItem) {
    9196  defaultItem = _defaultItem;
    9297}
     98
     99/****************************** Contained Actions ****************/
     100
     101const string TextMenu::LeaveAction::nameBase = "Leave menu: ";
     102
     103TextMenu::LeaveAction::LeaveAction(TextMenu* _menu) :
     104Action(nameBase+_menu->getTitle()),
     105menu(_menu)
     106{}
     107
     108TextMenu::LeaveAction::~LeaveAction(){}
     109
     110bool TextMenu::LeaveAction::canUndo(){
     111  return false;
     112}
     113
     114bool TextMenu::LeaveAction::shouldUndo(){
     115  return false;
     116}
     117
     118Action::state_ptr TextMenu::LeaveAction::performCall(){
     119  menu->doQuit();
     120  return Action::success;
     121}
     122
     123
     124Action::state_ptr TextMenu::LeaveAction::performUndo(Action::state_ptr){
     125  ASSERT(0,"Cannot undo leaving a menu");
     126  return Action::success;
     127}
     128
     129Action::state_ptr TextMenu::LeaveAction::performRedo(Action::state_ptr){
     130  ASSERT(0,"Cannot redo leaving a menu");
     131  return Action::success;
     132}
  • src/Menu/TextMenu.hpp

    r66e95e rb31bc4  
    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/Patterns/Cacheable.hpp

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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/TextWindow.cpp

    r66e95e rb31bc4  
    9494  populaters.MakeEditMoleculesMenu(editMoleculesMenu,molecules,configuration,periode);
    9595
    96   returnFromEditMoleculeAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,editMoleculesMenu),false);
     96  Action *returnFromEditMoleculeAction = new TextMenu::LeaveAction(editMoleculesMenu);
    9797  MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnFromEditMoleculeAction);
    9898
     
    108108  delete old_menu;
    109109  delete quitAction;
    110   delete returnFromEditMoleculeAction;
    111110  delete moleculeView;
    112111  delete statusIndicator;
  • src/UIElements/TextWindow.hpp

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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:
    155     AtomIterator();
    156     AtomIterator(AtomDescriptor, World*);
    157     AtomIterator(const AtomIterator&);
    158     AtomIterator& operator=(const AtomIterator&);
    159     AtomIterator& operator++();     // prefix
    160     AtomIterator  operator++(int);  // postfix with dummy parameter
    161     bool operator==(const AtomIterator&);
    162     bool operator==(const AtomSet::iterator&);
    163     bool operator!=(const AtomIterator&);
    164     bool operator!=(const AtomSet::iterator&);
    165     atom* operator*();
    166 
    167     int getCount();
    168   protected:
    169     void advanceState();
    170     AtomSet::iterator state;
    171     boost::shared_ptr<AtomDescriptor_impl>  descr;
    172     int index;
    173 
    174     World* world;
    175   };
     163  typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
    176164
    177165  /**
     
    187175   * used for internal purposes, like AtomProcesses and AtomCalculations.
    188176   */
    189   AtomSet::iterator atomEnd();
     177  AtomIterator atomEnd();
    190178
    191179  // Molecules
    192180
    193   class MoleculeIterator {
    194   public:
    195     MoleculeIterator();
    196     MoleculeIterator(MoleculeDescriptor, World*);
    197     MoleculeIterator(const MoleculeIterator&);
    198     MoleculeIterator& operator=(const MoleculeIterator&);
    199     MoleculeIterator& operator++();     // prefix
    200     MoleculeIterator  operator++(int);  // postfix with dummy parameter
    201     bool operator==(const MoleculeIterator&);
    202     bool operator==(const MoleculeSet::iterator&);
    203     bool operator!=(const MoleculeIterator&);
    204     bool operator!=(const MoleculeSet::iterator&);
    205     molecule* operator*();
    206 
    207     int getCount();
    208   protected:
    209     void advanceState();
    210     MoleculeSet::iterator state;
    211     boost::shared_ptr<MoleculeDescriptor_impl>  descr;
    212     int index;
    213 
    214     World* world;
    215   };
     181  typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
    216182
    217183  /**
     
    227193   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    228194   */
    229   MoleculeSet::iterator moleculeEnd();
     195  MoleculeIterator moleculeEnd();
    230196
    231197
     
    240206
    241207  periodentafel *periode;
     208public:
    242209  AtomSet atoms;
     210private:
    243211  std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
    244212  atomId_t currAtomId; //!< stores the next available Id for atoms
    245213  MoleculeSet molecules;
    246214  moleculeId_t currMoleculeId;
    247 
    248 
    249   /***** singleton Stuff *****/
    250 public:
    251 
    252   /**
    253    * get the currently active instance of the World.
    254    */
    255   static World* get();
    256 
    257   /**
    258    * destroy the currently active instance of the World.
    259    */
    260   static void destroy();
    261 
    262   /**
    263    * destroy the currently active instance of the World and immidiately
    264    * create a new one. Use this to reset while somebody is still Observing
    265    * the world and should reset the observed instance. All observers will be
    266    * sent the subjectKille() message from the old world.
    267    */
    268   static World* reset();
    269 
    270215private:
    271216  /**
     
    280225   */
    281226  virtual ~World();
    282 
    283   static World *theWorld;
    284   // this mutex only saves the singleton pattern...
    285   // use other mutexes to protect internal data as well
    286   // this mutex handles access to the pointer, not to the object!!!
    287   static boost::mutex worldLock;
    288227
    289228  /*****
  • src/atom.cpp

    r66e95e rb31bc4  
    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

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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    2828  MoleculeDescriptorTest \
    2929  ObserverTest \
     30  SingletonTest \
    3031  StackClassUnitTest \
    3132  TesselationUnitTest \
     
    6768  MoleculeDescriptorTest.cpp \
    6869  ObserverTest.cpp \
     70  SingletonTest.cpp \
    6971  stackclassunittest.cpp \
    7072  tesselationunittest.cpp \
     
    9092AnalysisPairCorrelationUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp
    9193AnalysisPairCorrelationUnitTest_LDADD = ${ALLLIBS}
     94
     95atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
     96atomsCalculationTest_LDADD = ${ALLLIBS}
    9297
    9398BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp
     
    124129MoleculeDescriptorTest_LDADD = ${ALLLIBS}
    125130
     131SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp
     132SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB}
     133
    126134StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp
    127135StackClassUnitTest_LDADD = ${ALLLIBS}
     
    154162manipulateAtomsTest_LDADD = ${ALLLIBS}
    155163
    156 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
    157 atomsCalculationTest_LDADD = ${ALLLIBS}
    158 
    159164TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
    160165TestRunner_LDADD = ${ALLLIBS}
  • src/unittests/MoleculeDescriptorTest.cpp

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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/analysisbondsunittest.cpp

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    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

    r66e95e rb31bc4  
    2222#include "atom.hpp"
    2323
     24#ifdef HAVE_TESTRUNNER
     25#include "UnitTestMain.hpp"
     26#endif /*HAVE_TESTRUNNER*/
     27
    2428// Registers the fixture into the 'registry'
    2529CPPUNIT_TEST_SUITE_REGISTRATION( manipulateAtomsTest );
     
    3034  AtomStub(int _id) :
    3135  atom(),
    32   id(_id),
    33   manipulated(false)
     36  manipulated(false),
     37  id(_id)
    3438  {}
    3539
     
    6670// set up and tear down
    6771void manipulateAtomsTest::setUp(){
    68   World::get();
     72  World::getInstance();
    6973  for(int i=0;i<ATOM_COUNT;++i){
    7074    atoms[i]= new AtomStub(i);
    71     World::get()->registerAtom(atoms[i]);
     75    World::getInstance().registerAtom(atoms[i]);
    7276  }
    7377}
    7478void manipulateAtomsTest::tearDown(){
    75   World::destroy();
    76   ActionRegistry::purgeRegistry();
    77 }
    78 
    79 // some helper functions
    80 static bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
    81   for(int i=min;i<max;++i){
    82     if(!excluded.count(i)){
    83       std::vector<atom*>::iterator iter;
    84       bool res=false;
    85       for(iter=atoms.begin();iter!=atoms.end();++iter){
    86         res |= (*iter)->getId() == i;
    87       }
    88       if(!res) {
    89         cout << "Atom " << i << " missing in returned list" << endl;
    90         return false;
    91       }
    92     }
    93   }
    94   return true;
    95 }
    96 
    97 static bool hasNoDuplicates(std::vector<atom*> atoms){
    98   std::set<int> found;
    99   std::vector<atom*>::iterator iter;
    100   for(iter=atoms.begin();iter!=atoms.end();++iter){
    101     int id = (*iter)->getId();
    102     if(found.count(id))
    103       return false;
    104     found.insert(id);
    105   }
    106   return true;
     79  World::purgeInstance();
     80  ActionRegistry::purgeInstance();
    10781}
    10882
     
    11589
    11690void manipulateAtomsTest::testManipulateSimple(){
    117   ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
     91  ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
    11892  proc->call();
    119   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     93  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    12094  std::vector<atom*>::iterator iter;
    12195  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    128102
    129103void manipulateAtomsTest::testManipulateExcluded(){
    130   ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
     104
     105  ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
    131106  proc->call();
    132   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     107  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    133108  std::vector<atom*>::iterator iter;
    134109  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    145120void manipulateAtomsTest::testObserver(){
    146121  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));
     122  World::getInstance().signOn(obs);
     123  ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
    149124  proc->call();
    150125
    151126  CPPUNIT_ASSERT_EQUAL(1,obs->count);
    152   World::get()->signOff(obs);
     127  World::getInstance().signOff(obs);
    153128  delete obs;
    154129}
Note: See TracChangeset for help on using the changeset viewer.