[3f9eba] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * SetRandomNumbersDistribution.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Jan 01, 2011
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 21 |
|
---|
| 22 | #include "CodePatterns/Log.hpp"
|
---|
| 23 | #include "molecule.hpp"
|
---|
| 24 | #include "CodePatterns/Verbose.hpp"
|
---|
| 25 | #include "World.hpp"
|
---|
| 26 |
|
---|
| 27 | #include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
|
---|
| 28 |
|
---|
| 29 | #include <iostream>
|
---|
| 30 | #include <fstream>
|
---|
| 31 | #include <string>
|
---|
| 32 |
|
---|
| 33 | using namespace std;
|
---|
| 34 |
|
---|
| 35 | #include "SetRandomNumbersDistributionAction.hpp"
|
---|
| 36 |
|
---|
| 37 | // and construct the stuff
|
---|
| 38 | #include "SetRandomNumbersDistributionAction.def"
|
---|
| 39 | #include "Action_impl_pre.hpp"
|
---|
| 40 | /** =========== define the function ====================== */
|
---|
| 41 | Action::state_ptr CommandSetRandomNumbersDistributionAction::performCall() {
|
---|
| 42 | // obtain information
|
---|
| 43 | getParametersfromValueStorage();
|
---|
| 44 |
|
---|
| 45 | CommandSetRandomNumbersDistributionState *state =
|
---|
| 46 | new CommandSetRandomNumbersDistributionState(
|
---|
[c9bc2b7] | 47 | RandomNumberGeneratorFactory::getInstance().getDistributionName(),
|
---|
[3f9eba] | 48 | params);
|
---|
| 49 | RandomNumberGeneratorFactory::getInstance().setDistribution(params.distribution_type);
|
---|
| 50 |
|
---|
| 51 | DoLog(0) && (Log() << Verbose(0) << "Distribution of random number generator is now: "
|
---|
[c9bc2b7] | 52 | << RandomNumberGeneratorFactory::getInstance().getDistributionName() << std::endl);
|
---|
[3f9eba] | 53 |
|
---|
| 54 | return Action::state_ptr(state);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | Action::state_ptr CommandSetRandomNumbersDistributionAction::performUndo(Action::state_ptr _state) {
|
---|
| 58 | CommandSetRandomNumbersDistributionState *state = assert_cast<CommandSetRandomNumbersDistributionState*>(_state.get());
|
---|
| 59 |
|
---|
| 60 | CommandSetRandomNumbersDistributionState *newstate =
|
---|
| 61 | new CommandSetRandomNumbersDistributionState(
|
---|
[c9bc2b7] | 62 | RandomNumberGeneratorFactory::getInstance().getDistributionName(),
|
---|
[3f9eba] | 63 | state->params);
|
---|
| 64 | RandomNumberGeneratorFactory::getInstance().setDistribution(state->old_distribution_type);
|
---|
| 65 |
|
---|
| 66 | DoLog(0) && (Log() << Verbose(0) << "Distribution of random number generator is undone to: "
|
---|
[c9bc2b7] | 67 | << RandomNumberGeneratorFactory::getInstance().getDistributionName() << std::endl);
|
---|
[3f9eba] | 68 |
|
---|
| 69 | return Action::state_ptr(newstate);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | Action::state_ptr CommandSetRandomNumbersDistributionAction::performRedo(Action::state_ptr _state){
|
---|
| 73 | return performUndo(_state);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | bool CommandSetRandomNumbersDistributionAction::canUndo() {
|
---|
| 77 | return true;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool CommandSetRandomNumbersDistributionAction::shouldUndo() {
|
---|
| 81 | return true;
|
---|
| 82 | }
|
---|
| 83 | /** =========== end of function ====================== */
|
---|