From c9f3a345dcfbf14f7c53dad5bce777aa0b3a0f37 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 24 Sep 2009 05:09:51 +0200 Subject: [PATCH] WIP towards CommandRegistry implementation --- src/proc/control/command-registry.hpp | 19 +++++++++++++++++++ .../proc/control/command-registry-test.cpp | 4 +--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/proc/control/command-registry.hpp b/src/proc/control/command-registry.hpp index c82b5396c..975c126c9 100644 --- a/src/proc/control/command-registry.hpp +++ b/src/proc/control/command-registry.hpp @@ -51,14 +51,18 @@ #include "proc/control/typed-allocation-manager.hpp" //#include "proc/control/memento-tie.hpp" +#include +#include #include //#include #include +#include namespace control { + using boost::noncopyable; using std::tr1::shared_ptr; // using std::ostream; using std::string; @@ -71,9 +75,16 @@ namespace control { */ class CommandRegistry : public lib::Sync<> + , noncopyable { TypedAllocationManager allocator_; + typedef std::tr1::unordered_map CmdIndex; + typedef std::map ReverseIndex; + + CmdIndex index_; + ReverseIndex ridx_; + public: static lumiera::Singleton instance; @@ -87,6 +98,14 @@ namespace control { { Lock sync(this); UNIMPLEMENTED ("place a commandHandle into the command index, or return the command already registered there"); + Command& indexSlot (index_[cmdID]); + if (!indexSlot) + { + indexSlot = commandHandle; + ridx_[&indexSlot] = cmdID; + } + return indexSlot; + ///////////////////////////TODO possible to return a const& ?? } diff --git a/tests/components/proc/control/command-registry-test.cpp b/tests/components/proc/control/command-registry-test.cpp index 13dcb257c..a4d473db8 100644 --- a/tests/components/proc/control/command-registry-test.cpp +++ b/tests/components/proc/control/command-registry-test.cpp @@ -124,8 +124,7 @@ namespace test { // represented internally by a prototype instance ASSERT (1+cnt_inst == registry.instance_count()); cnt_inst++; - - UNIMPLEMENTED ("cover all relevant API functions"); + checkRegistration (registry); checkAllocation(registry); @@ -226,7 +225,6 @@ namespace test { ASSERT (!isSameObject (*pImpl, *clone)); ASSERT (*pImpl == *clone); - ///////////////////////////////////////////////TODO: maybe do a simulated command lifecycle here? ASSERT (!pImpl->canExec()); typedef Types ArgType; TypedArguments > arg (Tuple(98765));