CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Proxy.cc
Go to the documentation of this file.
1 #include <map>
2 
3 #include <boost/thread.hpp>
4 #include <boost/shared_ptr.hpp>
5 #include <boost/weak_ptr.hpp>
6 
8 
9 using namespace ThePEG;
10 
12 
13 typedef std::map<ProxyBase::ProxyID, boost::weak_ptr<ProxyBase> > ProxyMap;
14 
16 {
17  static struct Sentinel {
18  Sentinel() : instance(new ProxyMap) {}
19  ~Sentinel() { delete instance; instance = 0; }
20 
22  } sentinel;
23 
24  return sentinel.instance;
25 }
26 
28  id(id)
29 {
30 }
31 
33 {
34  boost::mutex::scoped_lock scoped_lock(mutex);
35 
37  if (map)
38  map->erase(id);
39 }
40 
41 boost::shared_ptr<ProxyBase> ProxyBase::create(ctor_t ctor)
42 {
43  static ProxyBase::ProxyID nextProxyID = 0;
44 
45  boost::mutex::scoped_lock scoped_lock(mutex);
46 
47  boost::shared_ptr<ProxyBase> proxy(ctor(++nextProxyID));
48 
50  if (map)
51  map->insert(ProxyMap::value_type(proxy->getID(), proxy));
52 
53  return proxy;
54 }
55 
56 boost::shared_ptr<ProxyBase> ProxyBase::find(ProxyID id)
57 {
58  boost::mutex::scoped_lock scoped_lock(mutex);
59 
61  if (!map)
62  return boost::shared_ptr<ProxyBase>();
63 
64  ProxyMap::const_iterator pos = map->find(id);
65  if (pos == map->end())
66  return boost::shared_ptr<ProxyBase>();
67 
68  return boost::shared_ptr<ProxyBase>(pos->second);
69 }
static boost::mutex mutex
Definition: Proxy.cc:11
static boost::shared_ptr< ProxyBase > find(ProxyID id)
Definition: Proxy.cc:56
static PFTauRenderPlugin instance
static ProxyMap * getProxyMapInstance()
Definition: Proxy.cc:15
ProxyBase(ProxyID id)
Definition: Proxy.cc:27
virtual ~ProxyBase()
Definition: Proxy.cc:32
std::map< LHEProxy::ProxyID, boost::weak_ptr< LHEProxy > > ProxyMap
Definition: LHEProxy.cc:13
static boost::shared_ptr< ProxyBase > create(ctor_t ctor)
Definition: Proxy.cc:41
unsigned long ProxyID
Definition: Proxy.h:16