UI-Dispatch: draft basic interface of a queue helper (#1098)

This commit is contained in:
Fischlurch 2017-08-05 17:28:31 +02:00
parent 9b285a95c0
commit 3dea3c0fa0
4 changed files with 67 additions and 7 deletions

View file

@ -40,9 +40,11 @@
#include "lib/error.hpp"
#include <boost/noncopyable.hpp>
#include <functional>
namespace lib {
namespace error = lumiera::error;
@ -54,6 +56,48 @@ namespace lib {
struct CallQueue
: boost::noncopyable
{
public:
CallQueue() { }
using Operation = std::function<void(void)>;
CallQueue&
feed (Operation&& op)
{
if (not op)
throw error::Logic( "Unbound Functor fed to dispatcher CallQueue"
, error::LUMIERA_ERROR_BOTTOM_VALUE);
// lib::IterQueue<Command>::feed (move(cmd));
return *this;
}
void
invoke()
{
UNIMPLEMENTED ("pop operation");
}
void
clear()
{
// this->stateCore().clear();
}
/* == diagnostics == */
size_t
size() const
{
// return unConst(this)->stateCore().size();
}
bool
empty() const
{
return 0 == size();
}
};

View file

@ -67,8 +67,7 @@ namespace control {
{
public:
CommandQueue()
{ }
CommandQueue() { }
CommandQueue&
@ -79,7 +78,7 @@ namespace control {
% cmd.getID() % cmd
, LUMIERA_ERROR_UNBOUND_ARGUMENTS);
lib::IterQueue<Command>::feed (move (cmd));
lib::IterQueue<Command>::feed (move(cmd));
return *this;
}
@ -103,7 +102,6 @@ namespace control {
{
return 0 == size();
}
};

View file

@ -40,7 +40,7 @@
namespace lib {
namespace test{
using util::cStr;
using util::isnil;
using std::bind;
using std::string;
@ -77,7 +77,20 @@ namespace test{
void
verify_SimpleUse ()
{
UNIMPLEMENTED("verify_SimpleUse");
CallQueue queue;
CHECK (isnil (queue));
int val = 2;
queue.feed ([&]() { val = -1; });
CHECK (1 == queue.size());
CHECK (val == 2);
queue.invoke();
CHECK (val == -1);
CHECK (0 == queue.size());
queue.invoke();
CHECK (0 == queue.size());
}

View file

@ -1047,7 +1047,12 @@
</node>
<node CREATED="1501939193031" HGAP="3" ID="ID_1045913810" MODIFIED="1501939200829" TEXT="Test" VSHIFT="20">
<icon BUILTIN="pencil"/>
<node CREATED="1501939204166" ID="ID_383444966" MODIFIED="1501939211537" TEXT="CallQueue_test"/>
<node CREATED="1501939204166" ID="ID_383444966" MODIFIED="1501946866881" TEXT="CallQueue_test">
<icon BUILTIN="pencil"/>
<node CREATED="1501946847700" ID="ID_1917302142" MODIFIED="1501946851847" TEXT="basic"/>
<node CREATED="1501946852555" ID="ID_1617455971" MODIFIED="1501946855975" TEXT="mehrere"/>
<node CREATED="1501946856587" ID="ID_1780067399" MODIFIED="1501946862958" TEXT="Stre&#xdf;"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1501939212693" ID="ID_1007296291" MODIFIED="1501940740143" TEXT="#1099 DemoGuiRoundtrip">
<linktarget COLOR="#e5e53f" DESTINATION="ID_1007296291" ENDARROW="Default" ENDINCLINATION="-767;134;" ID="Arrow_ID_1440938291" SOURCE="ID_1925240675" STARTARROW="None" STARTINCLINATION="-51;592;"/>
<icon BUILTIN="flag-yellow"/>