Commands: change API to allow moving commands into the dispatcher queue
This commit is contained in:
parent
67e1032f7d
commit
079ad715b0
6 changed files with 25 additions and 11 deletions
|
|
@ -130,6 +130,13 @@ namespace lib {
|
|||
return *this;
|
||||
}
|
||||
|
||||
IterStack&
|
||||
push (TY&& movedElm)
|
||||
{
|
||||
this->stateCore().emplace_back (movedElm);
|
||||
return *this;
|
||||
}
|
||||
|
||||
IterStack&
|
||||
insert (TY const& elm)
|
||||
{
|
||||
|
|
@ -177,6 +184,13 @@ namespace lib {
|
|||
return *this;
|
||||
}
|
||||
|
||||
IterQueue&
|
||||
feed (TY&& movedElm)
|
||||
{
|
||||
this->stateCore().emplace_front (movedElm);
|
||||
return *this;
|
||||
}
|
||||
|
||||
IterQueue&
|
||||
insert (TY const& elm)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ namespace control {
|
|||
public:
|
||||
virtual ~CommandDispatch() { } ///< this is an interface
|
||||
|
||||
virtual void clear() =0; /////TODO do we actually need that operation?
|
||||
virtual void enqueue (Command) =0;
|
||||
virtual void clear() =0; /////TODO do we actually need that operation?
|
||||
virtual void enqueue (Command&&) =0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ namespace control {
|
|||
|
||||
|
||||
CommandQueue&
|
||||
feed (Command const& cmd)
|
||||
feed (Command&& cmd)
|
||||
{
|
||||
if (not cmd.canExec())
|
||||
throw error::Logic(_Fmt("Reject '%s'. Not suitably prepared for invocation: %s")
|
||||
|
|
|
|||
|
|
@ -204,10 +204,10 @@ namespace control {
|
|||
/* === CommandDispatch interface === */
|
||||
|
||||
void
|
||||
enqueue (Command cmd) override
|
||||
enqueue (Command&& cmd) override
|
||||
{
|
||||
Lock sync(this);
|
||||
queue_.feed (cmd);
|
||||
queue_.feed (move (cmd));
|
||||
sync.notifyAll();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,9 +75,9 @@ namespace test {
|
|||
}
|
||||
|
||||
void
|
||||
enqueue (Command cmd) override
|
||||
enqueue (Command&& cmd) override
|
||||
{
|
||||
queue_.emplace_front(move (cmd));
|
||||
queue_.emplace_front (cmd);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ namespace test {
|
|||
CommandQueue queue;
|
||||
CHECK (isnil(queue));
|
||||
|
||||
queue.feed (com11);
|
||||
queue.feed (com12);
|
||||
queue.feed (Command{com11});
|
||||
queue.feed (Command{com12});
|
||||
|
||||
CHECK (2 == queue.size());
|
||||
|
||||
|
|
@ -141,10 +141,10 @@ namespace test {
|
|||
// NOT binding the second command...
|
||||
|
||||
CommandQueue queue;
|
||||
queue.feed (com11);
|
||||
queue.feed (Command{com11});
|
||||
CHECK (1 == queue.size());
|
||||
|
||||
VERIFY_ERROR (UNBOUND_ARGUMENTS, queue.feed (com12));
|
||||
VERIFY_ERROR (UNBOUND_ARGUMENTS, queue.feed (Command{com12}));
|
||||
CHECK (1 == queue.size());
|
||||
|
||||
queue.pop().execSync();
|
||||
|
|
|
|||
Loading…
Reference in a new issue