/* * Reaction_impl.hpp * * Created on: Oct 13, 2011 * Author: heber */ #ifndef REACTION_IMPL_HPP_ #define REACTION_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Assert.hpp" #include "Actions/Action.hpp" #include using namespace MoleCuilder; template Reaction::Reaction(const ActionTrait &_trait, bool _doRegister) : Action(_trait,_doRegister), result(0), done(false) {} template Reaction::~Reaction() { delete result; } template Action::state_ptr Reaction::performCall(){ reset(); (*this)(); return Action::success; } template Action::state_ptr Reaction::performUndo(Action::state_ptr){ ASSERT(0,"Cannot undo a calculation"); return Action::success; } template Action::state_ptr Reaction::performRedo(Action::state_ptr){ ASSERT(0,"Cannot redo a calculation"); return Action::success; } template bool Reaction::canUndo() { return false; } template bool Reaction::shouldUndo() { return false; } // methods for calculation infrastructure template T Reaction::operator()(){ if(!done){ result = doCalc(); done = true; } return *result; } template bool Reaction::hasResult(){ return done; } template T Reaction::getResult(){ ASSERT(done, "Reaction::getResult() - No result calculated yet."); return *result; } template void Reaction::reset(){ done = false; delete result; result = NULL; } #endif /* REACTION_IMPL_HPP_ */