CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Proxy.h
Go to the documentation of this file.
1 #ifndef GeneratorInterface_Herwig7Interface_Proxy_h
2 #define GeneratorInterface_Herwig7Interface_Proxy_h
3 #include <memory>
4 
5 namespace ThePEG {
6 
7  // forward declarations
8  class LHEEvent;
9  class LHERunInfo;
10 
11  template <class T>
12  class Proxy;
13 
14  class ProxyBase {
15  public:
16  typedef unsigned long ProxyID;
17 
18  // not allowed and not implemented
19  ProxyBase(const ProxyBase &orig) = delete;
20  ProxyBase &operator=(const ProxyBase &orig) = delete;
21 
22  virtual ~ProxyBase();
23 
24  ProxyID getID() const { return id; }
25 
26  private:
27  typedef ProxyBase *(*ctor_t)(ProxyID id);
28 
29  template <class T>
30  friend class Proxy;
31 
32  ProxyBase(ProxyID id);
33 
34  static std::shared_ptr<ProxyBase> create(ctor_t ctor);
35  static std::shared_ptr<ProxyBase> find(ProxyID id);
36 
37  const ProxyID id;
38  };
39 
40  template <class T>
41  class Proxy : public ProxyBase {
42  public:
43  typedef Proxy Base;
44 
45  static inline std::shared_ptr<T> create() { return std::static_pointer_cast<T>(ProxyBase::create(&Proxy::ctor)); }
46  static inline std::shared_ptr<T> find(ProxyID id) { return std::dynamic_pointer_cast<T>(ProxyBase::find(id)); }
47 
48  protected:
49  inline Proxy(ProxyID id) : ProxyBase(id) {}
50 
51  private:
52  static ProxyBase *ctor(ProxyID id) { return new T(id); }
53  };
54 
55 } // namespace ThePEG
56 
57 #endif // GeneratorProxy_Herwig7Interface_Proxy_h
static ProxyBase * ctor(ProxyID id)
Definition: Proxy.h:52
Proxy(ProxyID id)
Definition: Proxy.h:49
const ProxyID id
Definition: Proxy.h:37
Proxy Base
Definition: Proxy.h:43
ProxyID getID() const
Definition: Proxy.h:24
ProxyBase(const ProxyBase &orig)=delete
static std::shared_ptr< ProxyBase > find(ProxyID id)
Definition: Proxy.cc:50
ProxyBase & operator=(const ProxyBase &orig)=delete
static std::shared_ptr< T > find(ProxyID id)
Definition: Proxy.h:46
static std::shared_ptr< T > create()
Definition: Proxy.h:45
static std::shared_ptr< ProxyBase > create(ctor_t ctor)
Definition: Proxy.cc:36
virtual ~ProxyBase()
Definition: Proxy.cc:28
ProxyBase *(* ctor_t)(ProxyID id)
Definition: Proxy.h:27
unsigned long ProxyID
Definition: Proxy.h:16
long double T