WIP expand on this draft to build a prospective solution

This commit is contained in:
Fischlurch 2009-01-06 06:09:46 +01:00
parent 57ca80c2fc
commit 8a40075ee8
2 changed files with 80 additions and 31 deletions

View file

@ -40,6 +40,7 @@
#include "include/nobugcfg.h" #include "include/nobugcfg.h"
#include "lib/error.hpp"
extern "C" { extern "C" {
#include "common/interface.h" #include "common/interface.h"
@ -55,7 +56,6 @@ extern "C" {
namespace lumiera { namespace lumiera {
using std::string; using std::string;
// using boost::scoped_ptr;
namespace { // implementation details namespace { // implementation details

View file

@ -77,6 +77,7 @@
#define LUMIERA_INTERFACE_PROXY_H #define LUMIERA_INTERFACE_PROXY_H
#include "lib/error.hpp"
#include <string> #include <string>
@ -92,74 +93,122 @@ namespace lumiera {
template<class FA> template<class FA>
class FacadeAccessor class FacadeAccessor
{ {
FA* insta_; protected:
static FA* implProxy_;
public: public:
FA& FA&
operator() () operator() ()
{ {
if (insta_) if (implProxy_)
return *insta_; return *implProxy_;
else else
throw error::State("Facade interface currently closed."); throw error::State("Facade interface currently closed.");
} }
}; };
template<class IMP> template<class IHA>
class Holder void openProxy (IHA& iha);
template<class IHA>
void closeProxy (IHA& iha);
template<class IHA>
class Proxy;
}
#include "common/instancehandle.hpp"
namespace lumiera {
template<class IHA>
class Holder;
template<class FA, class I>
class Holder<InstanceHandle<I,FA> >
: FacadeAccessor<FA>,
protected FA
{ {
static IMP& open() protected:
typedef InstanceHandle<I,FA> IHandle;
typedef FacadeAccessor<FA> Access;
typedef Holder<IHandle> THolder;
typedef Proxy<IHandle> Proxy;
static Proxy& open(IHandle& iha)
{ {
static char buff[sizeof(IMP)]; static char buff[sizeof(Proxy)];
IMP* p = new(buff) IMP(); Proxy* p = new(buff) Proxy(iha);
insta_ = p; Access::implProxy_ = p;
return *p; return *p;
} }
template<class IMP>
static void close() static void close()
{ {
IMP* p = static_cast<IMP*> (insta_); if (!Access::implProxy_) return;
insta_ = 0; Proxy* p = static_cast<Proxy*> (Access::implProxy_);
p->~IMP(); Access::implProxy_ = 0;
p->~Proxy();
} }
I& _i_;
Holder (IHandle& iha)
: _i_(iha.get())
{ }
}; };
template<class FA> template<class FA>
class Proxy; FA* FacadeAccessor<FA>::implProxy_;
template<class IH>
class Mixi;
template<class FA, class I> struct XYZ
class Mixi<InstanceHandle<I,FA> >
: Holder<Proxy<FA> >,
public FA
{ {
I* _i_; virtual ~XYZ(){}
public:
void setupInterface(I& interface) { _i_ = &interface; }
virtual int zoing(int i) =0;
}; };
class XYZ; struct II {};
typedef InstanceHandle<II,XYZ> IIXYZ;
template<> template<>
class Proxy<XYZ> class Proxy<IIXYZ>
: public Mixi<XYZ> : public Holder<IIXYZ>
{ {
//----Proxy-Implementation-of-XYZ--------
virtual int
zoing (int i)
{
return (rand() % i);
}
public:
Proxy (IHandle iha) : THolder(iha) {}
}; };
template<class FA, class I>
template<class IHA>
void void
pullUp (InstanceHandle<I,FA>& iha) openProxy (IHA& iha)
{ {
Proxy<InstanceHandle<I,FA> >::open().setupInterface(iha.get()); Proxy<IHA>::open(iha);
}
template<class IHA>
void
closeProxy (IHA& iha)
{
Proxy<IHA>::close();
} }
} // namespace lumiera } // namespace lumiera