Changes in / [2ad482:69baa4]


Ignore:
Location:
src
Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    r2ad482 r69baa4  
    3434{
    3535  if(_doRegister){
    36     ActionRegistry::getInstance().registerInstance(this);
     36    ActionRegistry::getInstance().registerAction(this);
    3737  }
    3838}
  • src/Actions/ActionRegistry.cpp

    r2ad482 r69baa4  
    11/*
    2  * Registry<Action>.cpp
     2 * ActionRegistry.cpp
    33 *
    44 *  Created on: Jan 7, 2010
     
    99
    1010#include "Actions/ActionRegistry.hpp"
     11#include "Actions/Action.hpp"
     12
    1113#include "Patterns/Singleton_impl.hpp"
    12 #include "Patterns/Registry_impl.hpp"
     14
     15#include <string>
     16#include "Helpers/Assert.hpp"
     17#include <iostream>
     18
     19using namespace std;
    1320
    1421/** Constructor for class ActionRegistry.
    1522 */
    1623ActionRegistry::ActionRegistry()
    17 {}
     24{
     25}
    1826
    1927/** Destructor for class ActionRegistry.
    2028 */
    2129ActionRegistry::~ActionRegistry()
    22 {}
     30{
     31  map<const string,Action*>::iterator iter;
     32  for(iter=actionMap.begin();iter!=actionMap.end();++iter) {
     33    delete iter->second;
     34  }
     35  actionMap.clear();
     36}
    2337
    24 /** Just passes on call to Registry<Action>::getByName().
    25  * \param name name of Action
     38/** Returns pointer to an action named by \a name.
     39 * \param name name of action
    2640 * \return pointer to Action
    2741 */
    28 Action* ActionRegistry::getActionByName(const std::string name)
    29 {
    30   return getByName(name);
     42Action* ActionRegistry::getActionByName(const std::string name){
     43  map<const string,Action*>::iterator iter;
     44  iter = actionMap.find(name);
     45  ASSERT(iter!=actionMap.end(),"Query for an action not stored in registry");
     46  return iter->second;
    3147}
    3248
    33 /** Just passes on call to Registry<Action>::isPresentByName().
    34  * \param name name of Action
    35  * \return true - Action instance present, false - not
     49/** States whether action is present or not.
     50 * \note This iss needed as ActionRegistry::getActionByName() ASSERT()s that action is in map.
     51 * \param name name of action
     52 * \return true - Action present, false - Action absent
    3653 */
    37 bool ActionRegistry::isActionPresentByName(const std::string name)
    38 {
    39   return isPresentByName(name);
     54bool ActionRegistry::isActionByNamePresent(const std::string name){
     55  map<const string,Action*>::iterator iter;
     56  iter = actionMap.find(name);
     57  return iter!=actionMap.end();
    4058}
    4159
     60/** Registers an Action with the ActionRegistry.
     61 * \param *action pointer to Action.
     62 */
     63void ActionRegistry::registerAction(Action* action){
     64  pair<map<const string,Action*>::iterator,bool> ret;
     65  //cout << "Trying to register action with name " << action->getName() << "." << endl;
     66  ret = actionMap.insert(pair<const string,Action*>(action->getName(),action));
     67  ASSERT(ret.second,"Two actions with the same name added to registry");
     68}
     69
     70/** Unregisters an Action.
     71 * \param *action pointer to Action.
     72 */
     73void ActionRegistry::unregisterAction(Action* action){
     74  //cout << "Unregistering action with name " << action->getName() << "." << endl;
     75  actionMap.erase(action->getName());
     76}
     77
     78/** Returns an iterator pointing to the start of the map of Action's.
     79 * \return begin iterator
     80 */
     81std::map<const std::string,Action*>::iterator ActionRegistry::getBeginIter()
     82{
     83  return actionMap.begin();
     84}
     85
     86/** Returns an iterator pointing to the end of the map of Action's.
     87 * \return end iterator
     88 */
     89std::map<const std::string,Action*>::iterator ActionRegistry::getEndIter()
     90{
     91  return actionMap.end();
     92}
     93
     94/** Returns a const iterator pointing to the start of the map of Action's.
     95 * \return constant begin iterator
     96 */
     97std::map<const std::string,Action*>::const_iterator ActionRegistry::getBeginIter() const
     98{
     99  return actionMap.begin();
     100}
     101
     102/** Returns a const iterator pointing to the end of the map of Action's.
     103 * \return constant end iterator
     104 */
     105std::map<const std::string,Action*>::const_iterator ActionRegistry::getEndIter() const
     106{
     107  return actionMap.end();
     108}
     109
     110/** Prints the contents of the ActionRegistry \a &m to \a &ost.
     111 * \param &ost output stream
     112 * \param &m reference to ActionRegistry
     113 * \return reference to the above out stream for concatenation
     114 */
     115ostream& operator<<(ostream& ost, const ActionRegistry& m)
     116{
     117  ost << "ActionRegistry contains:" << endl;
     118  for (std::map<const std::string,Action*>::const_iterator iter = m.getBeginIter(); iter != m.getEndIter(); ++iter) {
     119    ost << "\t" << iter->first << " with pointer " << iter->second << endl;
     120  }
     121  return ost;
     122};
     123
     124
     125
    42126CONSTRUCT_SINGLETON(ActionRegistry)
    43 CONSTRUCT_REGISTRY(Action)
  • src/Actions/ActionRegistry.hpp

    r2ad482 r69baa4  
    11/*
    2  * Registry<Action>.hpp
     2 * ActionRegistry.hpp
    33 *
    44 *  Created on: Jan 7, 2010
     
    1313#include <map>
    1414
    15 #include "Patterns/Registry.hpp"
    1615#include "Patterns/Singleton.hpp"
    17 #include "Actions/Action.hpp"
    1816
    19 /** Action Registry.
    20  *
    21  * The Action registry is a storage for any Action instance to retrieved by name.
    22  * It is a singleton and can be called from anywhere.
    23  *
    24  */
    25 class ActionRegistry : public Singleton<ActionRegistry>, public Registry<Action>
     17class Action;
     18
     19class ActionRegistry : public Singleton<ActionRegistry>
    2620{
    2721  friend class Singleton<ActionRegistry>;
    28   //friend class Registry<Action>;
     22public:
     23  Action* getActionByName(const std::string);
     24  bool isActionByNamePresent(const std::string name);
     25  void registerAction(Action*);
     26  void unregisterAction(Action*);
    2927
    30 public:
    31   Action* getActionByName(const std::string name);
    32   bool isActionPresentByName(const std::string name);
     28  std::map<const std::string,Action*>::iterator getBeginIter();
     29  std::map<const std::string,Action*>::const_iterator getBeginIter() const;
     30  std::map<const std::string,Action*>::iterator getEndIter();
     31  std::map<const std::string,Action*>::const_iterator getEndIter() const;
     32
     33private:
     34  std::map<const std::string,Action*> actionMap;
    3335
    3436private:
    3537  ActionRegistry();
    36   ~ActionRegistry();
     38  virtual ~ActionRegistry();
    3739};
    3840
     41std::ostream& operator<<(std::ostream& ost, const ActionRegistry& m);
     42
    3943#endif /* ACTIONREGISTRY_HPP_ */
  • src/Descriptors/MoleculeNameDescriptor.cpp

    r2ad482 r69baa4  
    3030
    3131molecule *MoleculeNameDescriptor_impl::find(){
    32   World::MoleculeSet &molecules = getMolecules();
     32  World::MoleculeSet molecules = getMolecules();
    3333  World::MoleculeSet::iterator res = molecules.begin();
    3434  for (; res != molecules.end(); res++)
  • src/Descriptors/MoleculePtrDescriptor.cpp

    r2ad482 r69baa4  
    3434
    3535molecule *MoleculePtrDescriptor_impl::find(){
    36   World::MoleculeSet &molecules = getMolecules();
     36  World::MoleculeSet molecules = getMolecules();
    3737  World::MoleculeSet::iterator res = molecules.find(ptr->getId());
    3838  return (res!=molecules.end())?((*res).second):0;
  • src/Patterns/ObservedContainer_impl.hpp

    r2ad482 r69baa4  
    1717
    1818template <class Container>
    19 inline ObservedContainer<Container>::ObservedContainer(const ObservedContainer<Container> &src) :
     19inline ObservedContainer<Container>::ObservedContainer(const ObservedContainer &src) :
    2020  content(src.content),
    2121  obs(src.obs)
     
    2929inline
    3030ObservedContainer<Container>&
    31 ObservedContainer<Container>::operator=(const ObservedContainer<Container> &rhs){
     31ObservedContainer<Container>::operator=(const ObservedContainer &rhs){
    3232  content=rhs.content;
    3333  return *this;
  • src/UIElements/CommandLineUI/CommandLineWindow.cpp

    r2ad482 r69baa4  
    4444  for (std::list<std::string>::iterator CommandRunner = CommandLineParser::getInstance().SequenceOfActions.begin(); CommandRunner != CommandLineParser::getInstance().SequenceOfActions.end(); ++CommandRunner) {
    4545    cout << "Checking presence of " << *CommandRunner << ": ";
    46     if (ActionRegistry::getInstance().isActionPresentByName(*CommandRunner)) {
     46    if (ActionRegistry::getInstance().isActionByNamePresent(*CommandRunner)) {
    4747      cout << "calling " << *CommandRunner << endl;
    4848      ActionRegistry::getInstance().getActionByName(*CommandRunner)->call();
Note: See TracChangeset for help on using the changeset viewer.