/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * SetRandomNumbersDistribution.cpp * * Created on: Jan 01, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "CodePatterns/Log.hpp" #include "molecule.hpp" #include "CodePatterns/Verbose.hpp" #include "World.hpp" #include "RandomNumbers/RandomNumberGeneratorFactory.hpp" #include #include #include using namespace std; #include "SetRandomNumbersDistributionAction.hpp" // and construct the stuff #include "SetRandomNumbersDistributionAction.def" #include "Action_impl_pre.hpp" /** =========== define the function ====================== */ Action::state_ptr CommandSetRandomNumbersDistributionAction::performCall() { // obtain information getParametersfromValueStorage(); CommandSetRandomNumbersDistributionState *state = new CommandSetRandomNumbersDistributionState( RandomNumberGeneratorFactory::getInstance().getDistributionName(), params); RandomNumberGeneratorFactory::getInstance().setDistribution(params.distribution_type); DoLog(0) && (Log() << Verbose(0) << "Distribution of random number generator is now: " << RandomNumberGeneratorFactory::getInstance().getDistributionName() << std::endl); return Action::state_ptr(state); } Action::state_ptr CommandSetRandomNumbersDistributionAction::performUndo(Action::state_ptr _state) { CommandSetRandomNumbersDistributionState *state = assert_cast(_state.get()); CommandSetRandomNumbersDistributionState *newstate = new CommandSetRandomNumbersDistributionState( RandomNumberGeneratorFactory::getInstance().getDistributionName(), state->params); RandomNumberGeneratorFactory::getInstance().setDistribution(state->old_distribution_type); DoLog(0) && (Log() << Verbose(0) << "Distribution of random number generator is undone to: " << RandomNumberGeneratorFactory::getInstance().getDistributionName() << std::endl); return Action::state_ptr(newstate); } Action::state_ptr CommandSetRandomNumbersDistributionAction::performRedo(Action::state_ptr _state){ return performUndo(_state); } bool CommandSetRandomNumbersDistributionAction::canUndo() { return true; } bool CommandSetRandomNumbersDistributionAction::shouldUndo() { return true; } /** =========== end of function ====================== */