Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    rbcf653 re4afb4  
    2020#include "Helpers/MemDebug.hpp"
    2121
     22#include <iostream>
    2223#include <string>
    2324
     
    2526#include "Actions/ActionRegistry.hpp"
    2627#include "Actions/ActionHistory.hpp"
     28#include "Actions/OptionRegistry.hpp"
     29#include "Actions/OptionTrait.hpp"
    2730#include "Exceptions/MissingValueException.hpp"
    2831#include "UIElements/Dialog.hpp"
     32#include "Helpers/Assert.hpp"
    2933#include "Helpers/MemDebug.hpp"
    3034#include "UIElements/UIFactory.hpp"
     
    4347Action::state_ptr Action::failure = getEmptyState();
    4448
    45 Action::Action(std::string _name,bool _doRegister) :
    46 name(_name)
     49Action::Action(const ActionTraits &_Traits, bool _doRegister) :
     50    Traits(_Traits)
    4751{
     52  // register with ActionRegistry
    4853  if(_doRegister){
    4954    ActionRegistry::getInstance().registerInstance(this);
     55  }
     56
     57  // register with OptionRegistry
     58  for (ActionTraits::options_const_iterator optioniter = Traits.getBeginIter();
     59      optioniter != Traits.getEndIter();
     60      ++optioniter) {
     61    // options may have been re-used by other Actions, so check beforehand whether adding is needed
     62    if (!OptionRegistry::getInstance().isOptionPresentByName((optioniter->first))) {
     63      OptionRegistry::getInstance().registerInstance(optioniter->second);
     64    } else { // if present, ASSERT that types coincide
     65      OptionTrait const * const PresentOption = OptionRegistry::getInstance().getOptionByName(optioniter->first);
     66      ASSERT(PresentOption->getType() == optioniter->second->getType(),
     67          ("Action::Action() - option to add "+
     68              std::string(optioniter->first)+
     69              " of Action "+
     70              std::string(getName())+
     71              " is already present with different type!"
     72          )
     73      );
     74    }
    5075  }
    5176}
     
    5580
    5681const string Action::getName(){
    57   return name;
     82  return Traits.getName();
    5883}
    5984
     
    104129  return true;
    105130}
     131
Note: See TracChangeset for help on using the changeset viewer.