CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/GeneratorInterface/ThePEGInterface/interface/Proxy.h

Go to the documentation of this file.
00001 #ifndef GeneratorInterface_ThePEGInterface_Proxy_h
00002 #define GeneratorInterface_ThePEGInterface_Proxy_h
00003 
00004 #include <boost/shared_ptr.hpp>
00005 
00006 namespace ThePEG {
00007 
00008 // forward declarations
00009 class LHEEvent;
00010 class LHERunInfo;
00011 
00012 template<class T> class Proxy;
00013 
00014 class ProxyBase {
00015     public:
00016         typedef unsigned long ProxyID;
00017 
00018         virtual ~ProxyBase();
00019 
00020         ProxyID getID() const { return id; }
00021 
00022     private:
00023         typedef ProxyBase *(*ctor_t)(ProxyID id);
00024 
00025         template<class T> friend class Proxy;
00026 
00027         ProxyBase(ProxyID id);
00028 
00029         static boost::shared_ptr<ProxyBase> create(ctor_t ctor);
00030         static boost::shared_ptr<ProxyBase> find(ProxyID id);
00031 
00032         // not allowed and not implemented
00033         ProxyBase(const ProxyBase &orig);
00034         ProxyBase &operator = (const ProxyBase &orig);
00035 
00036         const ProxyID   id;
00037 };
00038 
00039 template<class T>
00040 class Proxy : public ProxyBase {
00041     public:
00042         typedef Proxy Base;
00043 
00044         static inline boost::shared_ptr<T> create()
00045         { return boost::static_pointer_cast<T>(ProxyBase::create(&Proxy::ctor)); }
00046         static inline boost::shared_ptr<T> find(ProxyID id)
00047         { return boost::dynamic_pointer_cast<T>(ProxyBase::find(id)); }
00048 
00049     protected:
00050         inline Proxy(ProxyID id) : ProxyBase(id) {}
00051 
00052     private:
00053         static ProxyBase *ctor(ProxyID id) { return new T(id); }
00054 };
00055 
00056 } // namespace ThePEG
00057 
00058 #endif // GeneratorProxy_ThePEGInterface_Proxy_h