7 #ifndef MT4CPP_COMMAND_HISTORY_HPP
8 #define MT4CPP_COMMAND_HISTORY_HPP
12 #include <boost/noncopyable.hpp>
27 void insert(CommandID
id, PCommand cmd) {
28 boost::mutex::scoped_lock lock(m_);
29 history_.insert( std::make_pair(
id, cmd ) );
33 PCommand
find(CommandID
id)
const {
34 boost::mutex::scoped_lock lock(m_);
35 std::map<CommandID, PCommand>::const_iterator i = history_.find(
id);
36 if(i != history_.end() )
43 std::vector<CommandID>
keys()
const {
44 std::vector<CommandID>
keys;
45 keys.reserve(history_.size());
46 typedef std::pair<CommandID, PCommand> Pair;
47 std::transform(history_.begin(), history_.end(), std::back_inserter(keys), [](
const Pair& p) -> CommandID {
return p.first; });
56 mutable boost::mutex m_;
57 std::map<CommandID, PCommand> history_;
64 inline CommandDesc findCommandDescriptor(
const CommandHistory& history, CommandID
id) {
65 PCommand cmd = history.find(
id);
67 return cmd->getDescriptor();
73 inline CommandID executeAsynchronouslyAndRemember(Scheduler& scheduler, CommandHistory& history, PCommand cmd) {
74 CommandID
id = scheduler.executeAsynchronously(cmd);
75 history.insert(
id, cmd);
80 inline CommandID executeSynchronouslyAndRemember(Scheduler& scheduler, CommandHistory& history, PCommand cmd) {
81 CommandID
id = scheduler.executeSynchronously(cmd);
82 history.insert(
id, cmd);
88 #endif //MT4CPP_COMMAND_HISTORY_HPP
std::vector< CommandID > keys() const
Definition: CommandHistory.hpp:43
void clear()
Definition: CommandHistory.hpp:52
Definition: CommandHistory.hpp:21
The active object scheduler module (Scheduler, CommandQueue and working thread main function) ...
void insert(CommandID id, PCommand cmd)
Definition: CommandHistory.hpp:27
Definition: Command.hpp:21
PCommand find(CommandID id) const
Definition: CommandHistory.hpp:33