1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * SetParserParametersAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: May 8, 2010
|
---|
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 "CodePatterns/Verbose.hpp"
|
---|
24 | #include "Parser/FormatParserStorage.hpp"
|
---|
25 | #include "Parser/MpqcParser.hpp"
|
---|
26 | #include "Parser/MpqcParser_Parameters.hpp"
|
---|
27 |
|
---|
28 | #include <algorithm>
|
---|
29 | #include <iostream>
|
---|
30 | #include <string>
|
---|
31 |
|
---|
32 | #include "SetParserParametersAction.hpp"
|
---|
33 |
|
---|
34 | using namespace MoleCuilder;
|
---|
35 |
|
---|
36 | // and construct the stuff
|
---|
37 | #include "SetParserParametersAction.def"
|
---|
38 | #include "Action_impl_pre.hpp"
|
---|
39 | /** =========== define the function ====================== */
|
---|
40 | Action::state_ptr ParserSetParserParametersAction::performCall() {
|
---|
41 | // get parser
|
---|
42 | ParserTypes type = FormatParserStorage::getInstance().getTypeFromName(params.parsername.get());
|
---|
43 | FormatParser_Parameters *parameters = FormatParserStorage::getInstance().get(type).parameters;
|
---|
44 | ASSERT(parameters != NULL,
|
---|
45 | "ParserSetParserParametersAction::performCall() - parameters of parser is NULL.");
|
---|
46 |
|
---|
47 | // obtain undo state
|
---|
48 | std::stringstream oldparamstream;
|
---|
49 | oldparamstream << *parameters;
|
---|
50 |
|
---|
51 | // obtain information
|
---|
52 | std::stringstream newparamstream;
|
---|
53 | const std::vector< std::string > keyvalues = params.newparams.get();
|
---|
54 | std::for_each(keyvalues.begin(), keyvalues.end(), newparamstream << boost::lambda::_1 << ";");
|
---|
55 | newparamstream >> *parameters;
|
---|
56 |
|
---|
57 | return Action::state_ptr(new ParserSetParserParametersState(oldparamstream.str(), params));
|
---|
58 | }
|
---|
59 |
|
---|
60 | Action::state_ptr ParserSetParserParametersAction::performUndo(Action::state_ptr _state) {
|
---|
61 | ParserSetParserParametersState *state = assert_cast<ParserSetParserParametersState*>(_state.get());
|
---|
62 |
|
---|
63 | ParserTypes type = FormatParserStorage::getInstance().getTypeFromName(state->params.parsername.get());
|
---|
64 | FormatParser_Parameters *parser = FormatParserStorage::getInstance().get(type).parameters;
|
---|
65 | std::stringstream oldparamstream(state->oldparams);
|
---|
66 | oldparamstream >> *parser;
|
---|
67 |
|
---|
68 | return Action::state_ptr(_state);
|
---|
69 | }
|
---|
70 |
|
---|
71 | Action::state_ptr ParserSetParserParametersAction::performRedo(Action::state_ptr _state){
|
---|
72 | ParserSetParserParametersState *state = assert_cast<ParserSetParserParametersState*>(_state.get());
|
---|
73 |
|
---|
74 | ParserTypes type = FormatParserStorage::getInstance().getTypeFromName(state->params.parsername.get());
|
---|
75 | FormatParser_Parameters *parser = FormatParserStorage::getInstance().get(type).parameters;
|
---|
76 | std::stringstream newparamstream;
|
---|
77 | const std::vector< std::string > keyvalues = state->params.newparams.get();
|
---|
78 | std::for_each(keyvalues.begin(), keyvalues.end(), newparamstream << boost::lambda::_1 << ";");
|
---|
79 | newparamstream >> *parser;
|
---|
80 |
|
---|
81 | return Action::state_ptr(_state);
|
---|
82 | }
|
---|
83 |
|
---|
84 | bool ParserSetParserParametersAction::canUndo() {
|
---|
85 | return true;
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool ParserSetParserParametersAction::shouldUndo() {
|
---|
89 | return true;
|
---|
90 | }
|
---|
91 | /** =========== end of function ====================== */
|
---|