[41d023] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[41d023] | 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 | #include "Actions/ValueStorage.hpp"
|
---|
| 28 |
|
---|
| 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
|
---|
[f10b0c] | 42 | ParserTypes type = FormatParserStorage::getInstance().getTypeFromName(params.parsername.get());
|
---|
[41d023] | 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
|
---|
[f10b0c] | 52 | std::stringstream newparamstream(params.newparams.get());
|
---|
[41d023] | 53 | newparamstream >> *parameters;
|
---|
| 54 |
|
---|
| 55 | return Action::state_ptr(new ParserSetParserParametersState(oldparamstream.str(), params));
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | Action::state_ptr ParserSetParserParametersAction::performUndo(Action::state_ptr _state) {
|
---|
| 59 | ParserSetParserParametersState *state = assert_cast<ParserSetParserParametersState*>(_state.get());
|
---|
| 60 |
|
---|
[f10b0c] | 61 | ParserTypes type = FormatParserStorage::getInstance().getTypeFromName(state->params.parsername.get());
|
---|
[41d023] | 62 | FormatParser_Parameters *parser = FormatParserStorage::getInstance().get(type).parameters;
|
---|
| 63 | std::stringstream oldparamstream(state->oldparams);
|
---|
| 64 | oldparamstream >> *parser;
|
---|
| 65 |
|
---|
| 66 | return Action::state_ptr(_state);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | Action::state_ptr ParserSetParserParametersAction::performRedo(Action::state_ptr _state){
|
---|
| 70 | ParserSetParserParametersState *state = assert_cast<ParserSetParserParametersState*>(_state.get());
|
---|
| 71 |
|
---|
[f10b0c] | 72 | ParserTypes type = FormatParserStorage::getInstance().getTypeFromName(state->params.parsername.get());
|
---|
[41d023] | 73 | FormatParser_Parameters *parser = FormatParserStorage::getInstance().get(type).parameters;
|
---|
[f10b0c] | 74 | std::stringstream newparamstream(state->params.newparams.get());
|
---|
[41d023] | 75 | newparamstream >> *parser;
|
---|
| 76 |
|
---|
| 77 | return Action::state_ptr(_state);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool ParserSetParserParametersAction::canUndo() {
|
---|
| 81 | return true;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | bool ParserSetParserParametersAction::shouldUndo() {
|
---|
| 85 | return true;
|
---|
| 86 | }
|
---|
| 87 | /** =========== end of function ====================== */
|
---|