Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/CmdAction/VerboseAction.cpp

    rbf3817 rbcf653  
     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
    18/*
    29 * VerboseAction.cpp
     
    3138class CommandLineVerboseState : public ActionState {
    3239public:
    33   CommandLineVerboseState(int _verbosity) :
    34     verbosity(_verbosity)
     40  CommandLineVerboseState(const int _oldverbosity, const int _newverbosity) :
     41    oldverbosity(_oldverbosity),
     42    newverbosity(_newverbosity)
    3543  {}
    36   int verbosity;
     44  int oldverbosity;
     45  int newverbosity;
    3746};
    3847
     
    6170
    6271Action::state_ptr CommandLineVerboseAction::performCall() {
    63   int verbosity = 2;
     72  int oldverbosity = getVerbosity();
     73  int newverbosity = 2;
    6474
    65   ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
     75  ValueStorage::getInstance().queryCurrentValue(NAME, newverbosity);
    6676
    67   setVerbosity(verbosity);
    68   DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
    69   return Action::success;
     77  if (oldverbosity != newverbosity) {
     78    CommandLineVerboseState *UndoState = new CommandLineVerboseState(oldverbosity, newverbosity);
     79    setVerbosity(newverbosity);
     80    DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << oldverbosity << " to " << newverbosity << "." << endl);
     81    return Action::state_ptr(UndoState);
     82  } else {
     83    DoLog(0) && (Log() << Verbose(0) << "Verbosity remains unchanged at " << oldverbosity << "." << endl);
     84    return Action::failure;
     85  }
    7086}
    7187
     
    7389  CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
    7490
    75   int verbosity = 2;
    76   ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
     91  DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << state->newverbosity << " to " << state->oldverbosity << "." << endl);
     92  setVerbosity(state->oldverbosity);
    7793
    78   setVerbosity(state->verbosity);
    79   return Action::state_ptr(new CommandLineVerboseState(verbosity));
     94  return Action::state_ptr(_state);
    8095}
    8196
    8297Action::state_ptr CommandLineVerboseAction::performRedo(Action::state_ptr _state){
    83   return performUndo(_state);
     98  CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
     99
     100  DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << state->oldverbosity << " to " << state->newverbosity << "." << endl);
     101  setVerbosity(state->newverbosity);
     102
     103  return Action::state_ptr(_state);
    84104}
    85105
Note: See TracChangeset for help on using the changeset viewer.