From 03047e6d176f4b24525c2eeb8d11fcae32c4fb18 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 26 Apr 2008 05:38:19 +0200 Subject: [PATCH] WIP maybe a solution for getting the correct wrapper within Builder Tools. works, but problem is: you need to know the exact type of the wrapper, e.g. Placement or shared_ptr --- src/proc/mobject/session/clip.hpp | 1 + src/tool/try.cpp | 11 ++ .../proc/mobject/builder/buildertooltest.cpp | 112 ++++++++++++++++-- 3 files changed, 114 insertions(+), 10 deletions(-) diff --git a/src/proc/mobject/session/clip.hpp b/src/proc/mobject/session/clip.hpp index cf15cbd27..7f1fe23c0 100644 --- a/src/proc/mobject/session/clip.hpp +++ b/src/proc/mobject/session/clip.hpp @@ -66,6 +66,7 @@ namespace mobject and the unlink() function of the asset should take it into account when breaking circular references. */ +public: ////////////////////////////////////TODO: temporarily for buildertooltest const Media & mediaDef_; const asset::Clip & clipDef_; diff --git a/src/tool/try.cpp b/src/tool/try.cpp index 90bdfadf8..da5ca97c0 100644 --- a/src/tool/try.cpp +++ b/src/tool/try.cpp @@ -8,25 +8,36 @@ // 1/08 - working out a static initialisation problem for Visitor (Tag creation) // 1/08 - check 64bit longs // 4/08 - comparison operators on shared_ptr +// 4/08 - conversions on the value_type used for boost::any #include #include #include +#include using std::string; using std::cout; +using boost::any; +using boost::any_cast; +struct B {}; +struct D : B {}; int main (int argc, char* argv[]) { NOBUG_INIT; + D d; + D* pD =&d; + + any aD (pD); + any_cast (aD); cout << "\ngulp\n"; diff --git a/tests/components/proc/mobject/builder/buildertooltest.cpp b/tests/components/proc/mobject/builder/buildertooltest.cpp index 584b41ea0..995325025 100644 --- a/tests/components/proc/mobject/builder/buildertooltest.cpp +++ b/tests/components/proc/mobject/builder/buildertooltest.cpp @@ -29,7 +29,7 @@ #include "proc/mobject/explicitplacement.hpp" //////////TODO - +#include #include using std::string; using std::cout; @@ -45,8 +45,62 @@ namespace mobject using session::Clip; using session::AbstractMO; +/////////////////////////////////////////////////////TODO: move to buildertool.hpp + using boost::any; + using boost::any_cast; + +// Problem +/* + - brauche Laufzeittyp des Zielobjektes + - an wen wird die Dispatcher-Tabelle gebunden? + - falls an den Wrapper: Gefahr, zur Laufzeit nicht die Tabelle zu bekommen, in die das Trampolin registriert wurde + - falls an das Zielobjekt: wie gebe ich Referenz und konkreten Typ des Wrappers an den Funktionsaufruf im Tool? + - vieleicht einen allgemeinen Argument-Adapter nutzen? + - Zielobjekt oder Wrapper als Argumenttyp? +*/ - class DummyMO : public AbstractMO + class BuTuul + : public lumiera::visitor::Tool + { + any currentArgument_; + + public: + + void rememberWrapper (any argument) + { + currentArgument_ = argument; + } + + template + WRA& getCurrentArgumentWrapper () + { + WRA* argument = any_cast (currentArgument_); + ASSERT (argument); + return *argument; + } + }; + + + + + template + < class TOOLImpl, // concrete BuilderTool implementation + class TYPELIST // list of all concrete Buildables to be treated + > + class Appli + : public lumiera::visitor::Applicable + { } + ; + + using lumiera::typelist::Types; // convienience for the users of "Applicable" + + class BDable : public lumiera::visitor::Visitable + { + + }; +/////////////////////////////////////////////////////TODO: move to buildertool.hpp + + class DummyMO : public AbstractMO, public BDable { public: DummyMO() { }; @@ -54,8 +108,34 @@ namespace mobject // DEFINE_PROCESSABLE_BY (BuilderTool); static void killDummy (AbstractMO* dum) { delete (DummyMO*)dum; } + + virtual void + apply (BuTuul& tool) + { + return BDable::dispatchOp (*this, tool); + } + }; + class Clop : public Clip, public BDable + { + Clop (Clip& base) : Clip (base.clipDef_, base.mediaDef_) {} + + virtual void + apply (BuTuul& tool) + { + return BDable::dispatchOp (*this, tool); + } + }; + + + template + inline BDable::ReturnType + apply (BuTuul& tool, TAR& wrappedTargetObj) + { + tool.rememberWrapper(any (&wrappedTargetObj)); + wrappedTargetObj->apply (tool); + } //////////////////////////////////////////////////////TODO: wip-wip @@ -71,12 +151,23 @@ namespace mobject class TestTool - : public Applicable, Placement >::List> + : public Appli::List> { public: - void treat (Placement& pC) { cout << "media is: "<< str(pC->getMedia()) <<"\n"; } - void treat (Placement&){ cout << "unspecific MO.\n"; } - void onUnknown (Buildable&){ cout << "catch-all-function called.\n"; } + void treat (Clip& c) + { + Placement& pC = getCurrentArgumentWrapper >(); + cout << "media is: "<< str(pC->getMedia()) <<"\n"; + } + void treat (AbstractMO&) + { + Placement& placement = getCurrentArgumentWrapper(); + cout << "unspecific MO; Placement(adr) " << &placement <<"\n"; + } + void onUnknown (Buildable&) + { + cout << "catch-all-function called.\n"; + } }; @@ -105,13 +196,14 @@ namespace mobject { TestTool t1; - BuilderTool& tool (t1); + BuTuul& tool (t1); DummyPlacement dumm; - PMO clip = asset::Media::create("test-1", asset::VIDEO)->createClip(); + Placement clip = asset::Media::create("test-1", asset::VIDEO)->createClip(); - clip.apply (tool); - dumm.apply (tool); + apply (tool, clip); + cout << "Placement(adr) " << &dumm <<"\n"; + apply (tool, dumm); } };