mt4cpp
OstreamCommandObserver.hpp
Go to the documentation of this file.
1 /**
2  * \file OstreamCommandObserver.hpp
3  * \brief The command observer using standard std::ostream for notify.
4  */
5 
6 
7 #ifndef MT4CPP_OSTREAM_COMMAND_OBSERVER_HPP
8 #define MT4CPP_OSTREAM_COMMAND_OBSERVER_HPP
9 
10 #include <ostream>
11 #include <boost/thread.hpp>
12 
13 #include "Command.hpp"
14 
15 namespace mt4cpp {
16 
17  /** simple command observer, send notification to ostream */
19  public:
20  OstreamCommandObserver(std::ostream& out) : out_(out) {}
21  virtual ~OstreamCommandObserver() {}
22 
23  /** new progress */
24  virtual void notifyProgress(const Command&, double progress) {
25  boost::mutex::scoped_lock scoped_lock(out_mutex);
26  out_ << static_cast<int>(progress * 100) << '%' << std::endl;
27  }
28 
29  /** next step */
30  virtual void notifyStep(const Command&) {
31  boost::mutex::scoped_lock scoped_lock(out_mutex);
32  out_ << '.' << std::flush;
33  }
34 
35  /** change command state */
36  virtual void notifyState(const Command&, CommandDesc::State) {}
37  private:
38  OstreamCommandObserver& operator=(const OstreamCommandObserver&); //!< not allowed
39 
40  boost::mutex out_mutex;
41  std::ostream& out_;
42  };
43 
44 } // namespace mt4cpp
45 
46 
47 #endif // MT4CPP_OSTREAM_COMMAND_OBSERVER_HPP
48 
The command module (Command base class, progress, command description).
virtual void notifyState(const Command &, CommandDesc::State)
Definition: OstreamCommandObserver.hpp:36
virtual void notifyStep(const Command &)
Definition: OstreamCommandObserver.hpp:30
State
available states of Command NONE - command created, but not put in activation queue QUEUED - command ...
Definition: Command.hpp:37
Definition: Command.hpp:21
Definition: Command.hpp:120
virtual void notifyProgress(const Command &, double progress)
Definition: OstreamCommandObserver.hpp:24
Definition: OstreamCommandObserver.hpp:18
Definition: Command.hpp:51