CMS 3D CMS Logo

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