/* * 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) : Action(_trait), result(0), done(false) {} template Reaction::~Reaction() { delete result; } template ActionState::ptr Reaction::performCall(){ reset(); (*this)(); return Action::success; } template ActionState::ptr Reaction::performUndo(ActionState::ptr){ ASSERT(0,"Cannot undo a calculation"); return Action::success; } template ActionState::ptr Reaction::performRedo(ActionState::ptr){ ASSERT(0,"Cannot redo a calculation"); return Action::success; } template bool Reaction::canUndo() { return false; } template bool Reaction::shouldUndo() { return false; } template void Reaction::outputAsCLI(std::ostream &ost) const {} template void Reaction::outputAsPython(std::ostream &ost, const std::string &prefix) const {} // methods for calculation infrastructure template T Reaction::operator()(){ if(!done){ result = doCalc(); done = true; } return *result; } template bool Reaction::hasResult() const { return done; } template T Reaction::getResult() const { ASSERT(done, "Reaction::getResult() - No result calculated yet."); return *result; } template void Reaction::reset(){ done = false; delete result; result = NULL; } #endif /* REACTION_IMPL_HPP_ */