diff --git a/tests/components/proc/mobject/placement-hierarchy-test.cpp b/tests/components/proc/mobject/placement-hierarchy-test.cpp index 0c21621f8..454e583ea 100644 --- a/tests/components/proc/mobject/placement-hierarchy-test.cpp +++ b/tests/components/proc/mobject/placement-hierarchy-test.cpp @@ -29,11 +29,12 @@ //#include "proc/mobject/placement.hpp" //#include "proc/mobject/placement-ref.hpp" //#include "proc/mobject/explicitplacement.hpp" -//#include "lib/util.hpp" +#include "lib/util.hpp" #include #include #include +#include using std::tr1::shared_ptr; using boost::format; @@ -41,6 +42,7 @@ using boost::format; //using util::contains; using std::string; using std::cout; +using std::rand; namespace mobject { @@ -48,28 +50,120 @@ namespace session { namespace test { + /** + * a dummy version of the MObject hierarchy, + * used to experiment with the Placement template structure + */ + struct MOj; - template - struct Pla; - - struct MOj { }; - struct Sub1 : MOj { }; + + template + class Pla; template<> - struct Pla - : shared_ptr + class Pla + : protected shared_ptr { + protected: + typedef shared_ptr Base; + typedef void (*Deleter)(MOj*); + + Pla (MOj & subject, Deleter killer) + : Base (&subject, killer) {}; + + friend class MOjFac; + + public: + virtual MOj * + operator-> () const + { + ENSURE (*this); + return Base::operator-> (); + } + + size_t use_count() const { return Base::use_count(); } + + virtual ~Pla() {}; }; template - struct Pla - : Pla + class Pla + : public Pla { + protected: + typedef Pla _Par; + typedef typename _Par::Base Base; + typedef typename _Par::Deleter Deleter; + + Pla (TY & mo, Deleter killer) + : _Par (mo, killer) + { }; + + friend class MOjFac; + + public: + virtual TY* + operator-> () const + { + ENSURE (INSTANCEOF (TY, this->get())); + return static_cast + (Base::operator-> ()); + } + }; + + + class MOjFac; + + struct MOj + { + static MOjFac create; + + int id_; + + MOj() : id_(rand() % 1000) {} + virtual ~MOj() {} + + void show() { cout << "ID=" << id_ << "\n"; } + }; + struct Sub1 : MOj { }; + struct Sub2 : MOj + { + void specialAPI() { cout << "specialAPI()\n";} + }; + struct Sub3 : Sub2 + { }; + + class MOjFac + { + static void deleterFunc (MOj* o) { delete o; } + + public: + + template + Pla + special () + { + return Pla (*new MO, &deleterFunc); + } + + typedef Pla Pla3; + + Pla3 + specialSub3 () + { + return Pla3 (*new Sub3, &deleterFunc); + } + }; + + MOjFac MOj::create; + + + /******************************************************************************* * @test Currently (5/09) this is a concept draft separate of any existing types. * The intention is to rework the Placement implementation based on the @@ -84,11 +178,24 @@ namespace test { virtual void run (Arg) { - Pla pSub1; + Pla pSub1 = MOj::create.special(); + Pla pSub2 = MOj::create.special(); + Pla pSub3 = MOj::create.specialSub3(); + + Pla pSubM (pSub3); /////////////////////////////////TODO format fmt ("sizeof( %s ) = %d\n"); - cout << fmt % "Pla" % sizeof(pSub1); + cout << fmt % "Pla" % sizeof(pSub1); + cout << fmt % "Pla" % sizeof(pSub2); + cout << fmt % "Pla" % sizeof(pSub3); + + pSub1->show(); + pSub2->show(); + pSub3->show(); + pSubM->show(); + pSub3->specialAPI(); + cout << "Hurgha!\n"; } };