From 3ebb8d02855f5db610eb9a99a3ee81402ced466e Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 26 Jul 2009 02:00:47 +0200 Subject: [PATCH] WIP and more stubbing... --- src/proc/control/command-def.hpp | 38 ++++++++++--------- src/proc/control/command.cpp | 21 ++++++++++ src/proc/control/command.hpp | 12 +++++- src/proc/control/handling-pattern.cpp | 5 +++ src/proc/control/handling-pattern.hpp | 10 +++++ .../proc/control/command-use1-test.cpp | 3 +- .../proc/control/command-use2-test.cpp | 6 +-- 7 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/proc/control/command-def.hpp b/src/proc/control/command-def.hpp index 159bdcdc7..c310a531f 100644 --- a/src/proc/control/command-def.hpp +++ b/src/proc/control/command-def.hpp @@ -53,6 +53,7 @@ #include "proc/control/command-signature.hpp" #include "proc/control/command-mutation.hpp" #include "proc/control/command-closure.hpp" +#include "proc/control/argument-tuple-accept.hpp" #include "lib/meta/function.hpp" #include "lib/meta/typelist.hpp" #include "lib/meta/typelist-util.hpp" @@ -74,7 +75,7 @@ namespace control { using lumiera::typelist::FunctionSignature; using lumiera::typelist::FunctionTypedef; using lumiera::typelist::Types; -//using lumiera::typelist::NullType; + using lumiera::typelist::NullType; using lumiera::typelist::Tuple; @@ -84,11 +85,17 @@ namespace control { template struct UndoDefinition + : AcceptArgumentTupleRet< Command&, SIG // Return type and Argument Signature of the \c bind(..) function + , UndoDefinition // target type (this class) providing the implementation \c bindArg(Tuple<..>) + > { typedef typename FunctionSignature< function >::Args BasicArgs; typedef typename FunctionTypedef::Sig UndoCaptureSig; - UndoDefinition (function& undoCapOperation) + Command& prototype_; + + UndoDefinition (Command& underConstruction, function& undoCapOperation) + : prototype_(underConstruction) { cout << showSizeof(undoCapOperation) << endl; UNIMPLEMENTED ("re-fetch command definition and augment it with Functor for capturing Undo information"); @@ -106,22 +113,15 @@ namespace control { return *this; } - template - < typename T1 - , typename T2 - > - UndoDefinition& ///////TODO return here the completed Command - bind ( T1& p1 - , T2& p2 - ) + + Command& + bindArg (Tuple const& params) { - typedef Types ArgTypes; - Tuple params(p1,p2); Closure clo (params); cout << showSizeof(clo) << endl; UNIMPLEMENTED ("complete Command definition by closing all functions"); - return *this; + return prototype_; } }; @@ -145,7 +145,10 @@ namespace control { template struct BasicDefinition { - BasicDefinition(function& operation) + Command& prototype_; + + BasicDefinition(Command& underConstruction, function& operation) + : prototype_(underConstruction) { cout << showSizeof(operation) << endl; UNIMPLEMENTED ("create new command object and store the operation functor"); @@ -160,7 +163,7 @@ namespace control { typedef typename BuildUndoDefType >::Type SpecificUndoDefinition; function opera2 (how_to_capture_UndoState); - return SpecificUndoDefinition (opera2); + return SpecificUndoDefinition (prototype_, opera2); } }; @@ -188,11 +191,12 @@ namespace control { : public lib::BoolCheckable { Symbol id_; - + Command& prototype_; public: CommandDef (Symbol cmdID) : id_(cmdID) + , prototype_(Command::fetchDef(cmdID)) { } template @@ -200,7 +204,7 @@ namespace control { operation (SIG& operation_to_define) { function opera1 (operation_to_define); - return stage::BasicDefinition(opera1); + return stage::BasicDefinition(prototype_, opera1); } diff --git a/src/proc/control/command.cpp b/src/proc/control/command.cpp index e8a0fb469..25ee53c3f 100644 --- a/src/proc/control/command.cpp +++ b/src/proc/control/command.cpp @@ -61,6 +61,20 @@ namespace control { } + Command& + Command::fetchDef (Symbol cmdID) + { + UNIMPLEMENTED ("fetch an command prototype from the registry, create if necessary"); + } + + + CommandDef + Command::storeDef (Symbol newCmdID) + { + UNIMPLEMENTED ("create a new definition & prototype based on this command"); + } + + bool Command::remove (Symbol cmdID) { @@ -139,6 +153,13 @@ namespace control { } + void + Command::execSync () + { + exec (HandlingPattern::get(HandlingPattern::SYNC_THROW)); + } + + HandlingPattern const& Command::getDefaultHandlingPattern() const { diff --git a/src/proc/control/command.hpp b/src/proc/control/command.hpp index 0a5b47828..ec0867fb8 100644 --- a/src/proc/control/command.hpp +++ b/src/proc/control/command.hpp @@ -58,6 +58,7 @@ namespace control { + class CommandDef; class HandlingPattern; @@ -73,8 +74,9 @@ namespace control { /* === command registry === */ static Command& get (Symbol cmdID); static bool remove (Symbol cmdID); - static bool undef (Symbol cmdID); + static bool undef (Symbol cmdID); + CommandDef storeDef (Symbol newCmdID); ~Command(); @@ -89,6 +91,8 @@ namespace control { */ void exec (HandlingPattern const& execPattern); + void execSync (); + HandlingPattern const& getDefaultHandlingPattern() const; @@ -104,6 +108,12 @@ namespace control { bool isValid() const; bool canExec() const; bool canUndo() const; + + protected: + static Command& fetchDef (Symbol cmdID); + + friend class CommandDef; + }; ////////////////TODO currently just fleshing out the API.... diff --git a/src/proc/control/handling-pattern.cpp b/src/proc/control/handling-pattern.cpp index 05b702c00..bb8987ad9 100644 --- a/src/proc/control/handling-pattern.cpp +++ b/src/proc/control/handling-pattern.cpp @@ -33,6 +33,11 @@ namespace control { /** */ + HandlingPattern const& + HandlingPattern::get (ID id) + { + UNIMPLEMENTED ("Factory for handling patterns"); + } ///////////////////////////////////////////////////////////////////////TODO: is this implementation file actually required?? diff --git a/src/proc/control/handling-pattern.hpp b/src/proc/control/handling-pattern.hpp index d325453dd..1210b5be7 100644 --- a/src/proc/control/handling-pattern.hpp +++ b/src/proc/control/handling-pattern.hpp @@ -35,6 +35,7 @@ #define CONTROL_HANDLING_PATTERN_H //#include "pre.hpp" +#include "lib/error.hpp" //#include "include/symbol.hpp" //#include @@ -58,6 +59,15 @@ namespace control { public: + enum ID + { SYNC + , SYNC_THROW + , ASYNC + }; + + static HandlingPattern const& get (ID id); + + virtual ~HandlingPattern() {} virtual void invoke (Command& command) const =0; diff --git a/tests/components/proc/control/command-use1-test.cpp b/tests/components/proc/control/command-use1-test.cpp index c6c3fdcc9..9dda3d68f 100644 --- a/tests/components/proc/control/command-use1-test.cpp +++ b/tests/components/proc/control/command-use1-test.cpp @@ -267,8 +267,7 @@ namespace test { ASSERT (!unbelievable); // but because the miracle isn't yet defined, any use throws - VERIFY_ERROR (INVALID_COMMAND, Command::get("miracle")); - VERIFY_ERROR (INVALID_COMMAND, unbelievable.bind("abracadabra")); + VERIFY_ERROR (INVALID_COMMAND, Command::get("miracle")); ASSERT (Command::remove("test.command1.1")); ASSERT (Command::remove("test.command1.2")); diff --git a/tests/components/proc/control/command-use2-test.cpp b/tests/components/proc/control/command-use2-test.cpp index 1069a06b0..e1fd8c3da 100644 --- a/tests/components/proc/control/command-use2-test.cpp +++ b/tests/components/proc/control/command-use2-test.cpp @@ -191,17 +191,17 @@ namespace test { Command com = Command::get("test.command2"); blowUp_ = false; - com.exec(HandlingPattern::THROW_SYNC); + com.exec(HandlingPattern::SYNC_THROW); ASSERT (protocolled(randVal_)); blowUp_ = true; string current = command2::check_.str(); - VERIFY_ERROR( EXTERNAL, com.exec(HandlingPattern::THROW_SYNC) ); + VERIFY_ERROR( EXTERNAL, com.exec(HandlingPattern::get(SYNC_THROW)) ); ASSERT (command2::check_.str() == current); // we can achieve the same effect, // after changing the default HandlingPatern for this command instance - com.setHandlingPattern(HandlingPattern::THROW_SYNC); + com.setHandlingPattern(HandlingPattern::SYNC_THROW); com.storeDef ("test.command2.1"); Command com2 = Command::get("test.command2.1");