From 211a2dabddd627cd214eb65b79a4366efc97a720 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 24 Jul 2009 17:50:14 +0200 Subject: [PATCH] WIP stubbing undefined operations... --- src/proc/control/command-def.hpp | 5 + src/proc/control/command.cpp | 91 +++++++++++++++++++ src/proc/control/command.hpp | 42 ++++++++- src/proc/control/handling-pattern.hpp | 6 ++ .../proc/control/command-use1-test.cpp | 12 +-- .../proc/control/test-dummy-commands.hpp | 1 + 6 files changed, 147 insertions(+), 10 deletions(-) diff --git a/src/proc/control/command-def.hpp b/src/proc/control/command-def.hpp index 9c2316b86..159bdcdc7 100644 --- a/src/proc/control/command-def.hpp +++ b/src/proc/control/command-def.hpp @@ -57,6 +57,7 @@ #include "lib/meta/typelist.hpp" #include "lib/meta/typelist-util.hpp" #include "lib/meta/tuple.hpp" +#include "lib/bool-checkable.hpp" //#include #include @@ -184,6 +185,7 @@ namespace control { * */ class CommandDef + : public lib::BoolCheckable { Symbol id_; @@ -200,6 +202,9 @@ namespace control { function opera1 (operation_to_define); return stage::BasicDefinition(opera1); } + + + bool isValid() const; }; ////////////////TODO currently just fleshing out the API.... diff --git a/src/proc/control/command.cpp b/src/proc/control/command.cpp index 44ed430c4..fbdebf4ab 100644 --- a/src/proc/control/command.cpp +++ b/src/proc/control/command.cpp @@ -31,7 +31,9 @@ #include "proc/control/command.hpp" +#include "proc/control/command-def.hpp" #include "proc/control/command-registry.hpp" +#include "proc/control/handling-pattern.hpp" //#include "proc/mobject/mobject-ref.hpp" //#include "proc/mobject/mobject.hpp" //#include "proc/mobject/placement.hpp" @@ -46,6 +48,9 @@ namespace control { + Command::~Command() { } + + /** */ Command& Command::get (Symbol cmdID) @@ -53,6 +58,92 @@ namespace control { UNIMPLEMENTED ("fetch an existing command from the internal cmd registry"); } + + bool + Command::remove (Symbol cmdID) + { + UNIMPLEMENTED ("de-register a single command instance"); + } + + + bool + Command::undef (Symbol cmdID) + { + UNIMPLEMENTED ("completely drop a command definition, together with all dependent instances"); + } + + + + size_t + Command::definition_count() + { + UNIMPLEMENTED ("return number of command definitions currently in the registry"); + } + + + + size_t + Command::instance_count() + { + UNIMPLEMENTED ("return number individual command instances currently in the registry"); + } + + + + bool + CommandDef::isValid() const + { + UNIMPLEMENTED ("command *definition* validity self check"); + } + + + + bool + Command::isValid() const + { + UNIMPLEMENTED ("command validity self check"); + } + + + + bool + Command::canExec() const + { + UNIMPLEMENTED ("state check: sufficiently defined to be invoked"); + } + + + + bool + Command::canUndo() const + { + UNIMPLEMENTED ("state check: has undo state been captured?"); + } + + + + + void + Command::undo () + { + exec (getDefaultHandlingPattern().howtoUNDO()); + } + + + void + Command::exec (HandlingPattern const& execPattern) + { + execPattern.invoke (*this); + } + + + HandlingPattern const& + Command::getDefaultHandlingPattern() const + { + UNIMPLEMENTED ("manage the default command handling pattern"); + } + + diff --git a/src/proc/control/command.hpp b/src/proc/control/command.hpp index d48dba207..7c16761e5 100644 --- a/src/proc/control/command.hpp +++ b/src/proc/control/command.hpp @@ -38,6 +38,7 @@ #include "include/symbol.hpp" #include "proc/control/command-mutation.hpp" #include "proc/control/command-closure.hpp" +#include "lib/bool-checkable.hpp" //#include @@ -51,24 +52,57 @@ namespace control { // using std::tr1::shared_ptr; + class HandlingPattern; + + /** * @todo Type-comment */ class Command + : public lib::BoolCheckable { public: + /* === command registry === */ static Command& get (Symbol cmdID); + static bool remove (Symbol cmdID); + static bool undef (Symbol cmdID); - virtual ~Command() {}; - virtual void operator() () =0; - virtual void undo () =0; + ~Command(); + + void operator() () ; + void undo () ; + + + /** core operation: invoke the command + * @param execPattern describes the individual steps + * necessary to get this command invoked properly + */ + void exec (HandlingPattern const& execPattern); + + HandlingPattern const& getDefaultHandlingPattern() const; + + + /* === diagnostics === */ + + static size_t definition_count(); + static size_t instance_count(); + + bool isValid() const; + bool canExec() const; + bool canUndo() const; }; ////////////////TODO currently just fleshing out the API.... - + + inline void + Command::operator() () + { + exec (getDefaultHandlingPattern()); + } + } // namespace control diff --git a/src/proc/control/handling-pattern.hpp b/src/proc/control/handling-pattern.hpp index 92bc776b9..d325453dd 100644 --- a/src/proc/control/handling-pattern.hpp +++ b/src/proc/control/handling-pattern.hpp @@ -58,6 +58,12 @@ namespace control { public: + virtual ~HandlingPattern() {} + + virtual void invoke (Command& command) const =0; + + virtual HandlingPattern const& howtoUNDO() const =0; + }; ////////////////TODO currently just fleshing out the API.... diff --git a/tests/components/proc/control/command-use1-test.cpp b/tests/components/proc/control/command-use1-test.cpp index 2b1749f05..bc43e2aaf 100644 --- a/tests/components/proc/control/command-use1-test.cpp +++ b/tests/components/proc/control/command-use1-test.cpp @@ -88,7 +88,7 @@ namespace test { virtual void run (Arg) { - command1::checksum_ = 0; + command1::check_ = 0; uint cnt_defs = Command::definition_count(); uint cnt_inst = Command::instance_count(); @@ -116,7 +116,7 @@ namespace test { .execSync() ; - ASSERT (randVal == checksum_); + ASSERT (randVal == command1::check_); Command::get("test.command1.1").undo(); ASSERT ( 0 == command1::check_); @@ -250,10 +250,10 @@ namespace test { void undef() { - ASSERT (CommandDef ("test.command1.1")) - ASSERT (CommandDef ("test.command1.2")) - ASSERT (CommandDef ("test.command1.3")) - ASSERT (CommandDef ("test.command1.4")) + ASSERT (CommandDef ("test.command1.1")); + ASSERT (CommandDef ("test.command1.2")); + ASSERT (CommandDef ("test.command1.3")); + ASSERT (CommandDef ("test.command1.4")); ASSERT (Command::get("test.command1.1")); ASSERT (Command::get("test.command1.2")); diff --git a/tests/components/proc/control/test-dummy-commands.hpp b/tests/components/proc/control/test-dummy-commands.hpp index 4bbf9ed0e..b3a2a9c45 100644 --- a/tests/components/proc/control/test-dummy-commands.hpp +++ b/tests/components/proc/control/test-dummy-commands.hpp @@ -149,3 +149,4 @@ namespace test { }} // namespace control::test +#endif