/* * Calculation_impl.hpp * * Created on: Feb 19, 2010 * Author: crueger */ #ifndef CALCULATION_IMPL_HPP_ #define CALCULATION_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Actions/Calculation.hpp" #include #include using namespace MoleCuilder; template Calculation::Calculation(int _maxSteps, const ActionTrait &_trait) : Process(_trait), result(0), done(false) { setMaxSteps(_maxSteps); } template Calculation::~Calculation() { delete result; } // methods inherited from Action template ActionState::ptr Calculation::performCall(){ reset(); (*this)(); return Action::success; } template ActionState::ptr Calculation::performUndo(ActionState::ptr){ ASSERT(0,"Cannot undo a calculation"); return Action::success; } template ActionState::ptr Calculation::performRedo(ActionState::ptr){ ASSERT(0,"Cannot redo a calculation"); return Action::success; } template bool Calculation::canUndo() { return false; } template bool Calculation::shouldUndo() { return false; } template void Calculation::outputAsCLI(std::ostream &ost) const { } template void Calculation::outputAsPython(std::ostream &ost, const std::string &prefix) const {} template void Calculation::setOptionValue(const std::string &_token, const std::string &_value) {} // methods for calculation infrastructure template T Calculation::operator()(){ if(!done){ result = doCalc(); done = true; } return *result; } template bool Calculation::hasResult() const { return done; } template T Calculation::getResult() const { assert(done && "No result calculated"); return *result; } template void Calculation::reset(){ done = false; delete result; result = 0; } #endif /* CALCULATION_IMPL_HPP_ */