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 | * SetRandomNumbersEngine.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/RandomNumberEngine.hpp"
|
---|
28 | #include "RandomNumbers/RandomNumberEngineFactory.hpp"
|
---|
29 |
|
---|
30 | #include <iostream>
|
---|
31 | #include <fstream>
|
---|
32 | #include <string>
|
---|
33 |
|
---|
34 | using namespace std;
|
---|
35 |
|
---|
36 | #include "SetRandomNumbersEngineAction.hpp"
|
---|
37 |
|
---|
38 | // and construct the stuff
|
---|
39 | #include "SetRandomNumbersEngineAction.def"
|
---|
40 | #include "Action_impl_pre.hpp"
|
---|
41 | /** =========== define the function ====================== */
|
---|
42 | Action::state_ptr CommandSetRandomNumbersEngineAction::performCall() {
|
---|
43 | // obtain information
|
---|
44 | getParametersfromValueStorage();
|
---|
45 |
|
---|
46 | // create a new state for undo
|
---|
47 | CommandSetRandomNumbersEngineState *state =
|
---|
48 | new CommandSetRandomNumbersEngineState(
|
---|
49 | RandomNumberEngineFactory::getInstance().getCurrentTypeName(),
|
---|
50 | RandomNumberEngineFactory::getInstance().getPrototype().getseed(),
|
---|
51 | params);
|
---|
52 | // set new default
|
---|
53 | RandomNumberEngineFactory::getInstance().setCurrentType(params.engine_type);
|
---|
54 | // set new seed if given, have to use ugly const_cast as prototype is not manipulable
|
---|
55 | if (params.seed != -1) {
|
---|
56 | RandomNumberEngine &engine =
|
---|
57 | const_cast<RandomNumberEngine &>(
|
---|
58 | RandomNumberEngineFactory::getInstance().getPrototype(params.engine_type)
|
---|
59 | );
|
---|
60 | engine.seed(params.seed);
|
---|
61 | }
|
---|
62 |
|
---|
63 | DoLog(0) && (Log() << Verbose(0) << "Default random number engine is now: "
|
---|
64 | << RandomNumberEngineFactory::getInstance().getCurrentTypeName() << std::endl);
|
---|
65 |
|
---|
66 | return Action::state_ptr(state);
|
---|
67 | }
|
---|
68 |
|
---|
69 | Action::state_ptr CommandSetRandomNumbersEngineAction::performUndo(Action::state_ptr _state) {
|
---|
70 | CommandSetRandomNumbersEngineState *state =
|
---|
71 | assert_cast<CommandSetRandomNumbersEngineState*>(_state.get());
|
---|
72 |
|
---|
73 | // create a new state for redo
|
---|
74 | CommandSetRandomNumbersEngineState *newstate =
|
---|
75 | new CommandSetRandomNumbersEngineState(
|
---|
76 | RandomNumberEngineFactory::getInstance().getCurrentTypeName(),
|
---|
77 | RandomNumberEngineFactory::getInstance().getPrototype().getseed(),
|
---|
78 | state->params);
|
---|
79 | // set new default
|
---|
80 | RandomNumberEngineFactory::getInstance().setCurrentType(state->old_engine_type);
|
---|
81 | RandomNumberEngine &engine = const_cast<RandomNumberEngine &>(
|
---|
82 | RandomNumberEngineFactory::getInstance().getPrototype(state->params.engine_type)
|
---|
83 | );
|
---|
84 | // set new seed if given, have to use ugly const_cast as prototype is not manipulable
|
---|
85 | if (state->params.seed != -1) {
|
---|
86 | engine.seed(state->params.seed);
|
---|
87 | }
|
---|
88 |
|
---|
89 | DoLog(0) && (Log() << Verbose(0) << "Default random number engine is undone to: "
|
---|
90 | << RandomNumberEngineFactory::getInstance().getCurrentTypeName() << std::endl);
|
---|
91 |
|
---|
92 | return Action::state_ptr(newstate);
|
---|
93 | }
|
---|
94 |
|
---|
95 | Action::state_ptr CommandSetRandomNumbersEngineAction::performRedo(Action::state_ptr _state){
|
---|
96 | return performUndo(_state);
|
---|
97 | }
|
---|
98 |
|
---|
99 | bool CommandSetRandomNumbersEngineAction::canUndo() {
|
---|
100 | return true;
|
---|
101 | }
|
---|
102 |
|
---|
103 | bool CommandSetRandomNumbersEngineAction::shouldUndo() {
|
---|
104 | return true;
|
---|
105 | }
|
---|
106 | /** =========== end of function ====================== */
|
---|