Ignore:
File:
1 edited

Legend:

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

    r952f38 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
     
    512 *      Author: heber
    613 */
     14
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
    719
    820#include "Helpers/MemDebug.hpp"
     
    2638class CommandLineVerboseState : public ActionState {
    2739public:
    28   CommandLineVerboseState(int _verbosity) :
    29     verbosity(_verbosity)
     40  CommandLineVerboseState(const int _oldverbosity, const int _newverbosity) :
     41    oldverbosity(_oldverbosity),
     42    newverbosity(_newverbosity)
    3043  {}
    31   int verbosity;
     44  int oldverbosity;
     45  int newverbosity;
    3246};
    3347
     
    5670
    5771Action::state_ptr CommandLineVerboseAction::performCall() {
    58   int verbosity = 2;
     72  int oldverbosity = getVerbosity();
     73  int newverbosity = 2;
    5974
    60   ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
     75  ValueStorage::getInstance().queryCurrentValue(NAME, newverbosity);
    6176
    62   setVerbosity(verbosity);
    63   DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
    64   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  }
    6586}
    6687
     
    6889  CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
    6990
    70   int verbosity = 2;
    71   ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
     91  DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << state->newverbosity << " to " << state->oldverbosity << "." << endl);
     92  setVerbosity(state->oldverbosity);
    7293
    73   setVerbosity(state->verbosity);
    74   return Action::state_ptr(new CommandLineVerboseState(verbosity));
     94  return Action::state_ptr(_state);
    7595}
    7696
    7797Action::state_ptr CommandLineVerboseAction::performRedo(Action::state_ptr _state){
    78   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);
    79104}
    80105
Note: See TracChangeset for help on using the changeset viewer.