From 8a40075ee8fa701bb0bf3cf223141e5ae121555f Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 6 Jan 2009 06:09:46 +0100 Subject: [PATCH] WIP expand on this draft to build a prospective solution --- src/common/instancehandle.hpp | 2 +- src/include/interfaceproxy.hpp | 109 ++++++++++++++++++++++++--------- 2 files changed, 80 insertions(+), 31 deletions(-) diff --git a/src/common/instancehandle.hpp b/src/common/instancehandle.hpp index 13a85bf97..b2a6e9ffd 100644 --- a/src/common/instancehandle.hpp +++ b/src/common/instancehandle.hpp @@ -40,6 +40,7 @@ #include "include/nobugcfg.h" +#include "lib/error.hpp" extern "C" { #include "common/interface.h" @@ -55,7 +56,6 @@ extern "C" { namespace lumiera { using std::string; -// using boost::scoped_ptr; namespace { // implementation details diff --git a/src/include/interfaceproxy.hpp b/src/include/interfaceproxy.hpp index 14b5e51ad..2b2396fe9 100644 --- a/src/include/interfaceproxy.hpp +++ b/src/include/interfaceproxy.hpp @@ -77,6 +77,7 @@ #define LUMIERA_INTERFACE_PROXY_H +#include "lib/error.hpp" #include @@ -92,74 +93,122 @@ namespace lumiera { template class FacadeAccessor { - FA* insta_; + protected: + static FA* implProxy_; public: FA& operator() () { - if (insta_) - return *insta_; + if (implProxy_) + return *implProxy_; else throw error::State("Facade interface currently closed."); } }; - template - class Holder + template + void openProxy (IHA& iha); + + template + void closeProxy (IHA& iha); + + template + class Proxy; + +} + +#include "common/instancehandle.hpp" + +namespace lumiera { + + template + class Holder; + + template + class Holder > + : FacadeAccessor, + protected FA { - static IMP& open() + protected: + typedef InstanceHandle IHandle; + typedef FacadeAccessor Access; + typedef Holder THolder; + typedef Proxy Proxy; + + static Proxy& open(IHandle& iha) { - static char buff[sizeof(IMP)]; - IMP* p = new(buff) IMP(); - insta_ = p; + static char buff[sizeof(Proxy)]; + Proxy* p = new(buff) Proxy(iha); + Access::implProxy_ = p; return *p; } - template static void close() { - IMP* p = static_cast (insta_); - insta_ = 0; - p->~IMP(); + if (!Access::implProxy_) return; + Proxy* p = static_cast (Access::implProxy_); + Access::implProxy_ = 0; + p->~Proxy(); } + I& _i_; + + Holder (IHandle& iha) + : _i_(iha.get()) + { } + }; + template - class Proxy; + FA* FacadeAccessor::implProxy_; - template - class Mixi; - template - class Mixi > - : Holder >, - public FA + struct XYZ { - I* _i_; - public: - void setupInterface(I& interface) { _i_ = &interface; } + virtual ~XYZ(){} + virtual int zoing(int i) =0; }; - class XYZ; + struct II {}; + typedef InstanceHandle IIXYZ; + + template<> - class Proxy - : public Mixi + class Proxy + : public Holder { + //----Proxy-Implementation-of-XYZ-------- + virtual int + zoing (int i) + { + return (rand() % i); + } + + + public: + Proxy (IHandle iha) : THolder(iha) {} }; - template + + template void - pullUp (InstanceHandle& iha) + openProxy (IHA& iha) { - Proxy >::open().setupInterface(iha.get()); - + Proxy::open(iha); + } + + template + void + closeProxy (IHA& iha) + { + Proxy::close(); } } // namespace lumiera