Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-04 02:02:38

0001 #ifndef GeneratorInterface_Herwig7Interface_Proxy_h
0002 #define GeneratorInterface_Herwig7Interface_Proxy_h
0003 #include <memory>
0004 
0005 namespace ThePEG {
0006 
0007   // forward declarations
0008   class LHEEvent;
0009   class LHERunInfo;
0010 
0011   template <class T>
0012   class Proxy;
0013 
0014   class ProxyBase {
0015   public:
0016     typedef unsigned long ProxyID;
0017 
0018     // not allowed and not implemented
0019     ProxyBase(const ProxyBase &orig) = delete;
0020     ProxyBase &operator=(const ProxyBase &orig) = delete;
0021 
0022     virtual ~ProxyBase();
0023 
0024     ProxyID getID() const { return id; }
0025 
0026   private:
0027     typedef ProxyBase *(*ctor_t)(ProxyID id);
0028 
0029     template <class T>
0030     friend class Proxy;
0031 
0032     ProxyBase(ProxyID id);
0033 
0034     static std::shared_ptr<ProxyBase> create(ctor_t ctor);
0035     static std::shared_ptr<ProxyBase> find(ProxyID id);
0036 
0037     const ProxyID id;
0038   };
0039 
0040   template <class T>
0041   class Proxy : public ProxyBase {
0042   public:
0043     typedef Proxy Base;
0044 
0045     static inline std::shared_ptr<T> create() { return std::static_pointer_cast<T>(ProxyBase::create(&Proxy::ctor)); }
0046     static inline std::shared_ptr<T> find(ProxyID id) { return std::dynamic_pointer_cast<T>(ProxyBase::find(id)); }
0047 
0048   protected:
0049     inline Proxy(ProxyID id) : ProxyBase(id) {}
0050 
0051   private:
0052     static ProxyBase *ctor(ProxyID id) { return new T(id); }
0053   };
0054 
0055 }  // namespace ThePEG
0056 
0057 #endif  // GeneratorProxy_Herwig7Interface_Proxy_h