CMS 3D CMS Logo

Proxy.cc
Go to the documentation of this file.
1 #include <map>
2 
3 #include <boost/thread.hpp>
4 
6 
7 using namespace ThePEG;
8 
10 
11 typedef std::map<ProxyBase::ProxyID, std::weak_ptr<ProxyBase> > ProxyMap;
12 
14  static struct Sentinel {
15  Sentinel() : instance(new ProxyMap) {}
16  ~Sentinel() {
17  delete instance;
18  instance = nullptr;
19  }
20 
22  } sentinel;
23 
24  return sentinel.instance;
25 }
26 
28 
30  boost::mutex::scoped_lock scoped_lock(mutex);
31 
33  if (map)
34  map->erase(id);
35 }
36 
37 std::shared_ptr<ProxyBase> ProxyBase::create(ctor_t ctor) {
38  static ProxyBase::ProxyID nextProxyID = 0;
39 
40  boost::mutex::scoped_lock scoped_lock(mutex);
41 
42  std::shared_ptr<ProxyBase> proxy(ctor(++nextProxyID));
43 
45  if (map)
46  map->insert(ProxyMap::value_type(proxy->getID(), proxy));
47 
48  return proxy;
49 }
50 
51 std::shared_ptr<ProxyBase> ProxyBase::find(ProxyID id) {
52  boost::mutex::scoped_lock scoped_lock(mutex);
53 
55  if (!map)
56  return std::shared_ptr<ProxyBase>();
57 
58  ProxyMap::const_iterator pos = map->find(id);
59  if (pos == map->end())
60  return std::shared_ptr<ProxyBase>();
61 
62  return std::shared_ptr<ProxyBase>(pos->second);
63 }
pos
Definition: PixelAliasList.h:18
ThePEG::ProxyBase::ProxyBase
ProxyBase(ProxyID id)
Definition: Proxy.cc:27
ThePEG
Definition: Herwig7Interface.h:24
mutex
static boost::mutex mutex
Definition: Proxy.cc:9
ThePEG::ProxyBase::find
static std::shared_ptr< ProxyBase > find(ProxyID id)
Definition: Proxy.cc:51
ThePEG::ProxyBase::ProxyID
unsigned long ProxyID
Definition: Proxy.h:16
Proxy.h
getProxyMapInstance
static ProxyMap * getProxyMapInstance()
Definition: Proxy.cc:13
ThePEG::ProxyBase::~ProxyBase
virtual ~ProxyBase()
Definition: Proxy.cc:29
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
ProxyMap
std::map< ProxyBase::ProxyID, std::weak_ptr< ProxyBase > > ProxyMap
Definition: Proxy.cc:11
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
ThePEG::ProxyBase::create
static std::shared_ptr< ProxyBase > create(ctor_t ctor)
Definition: Proxy.cc:37
genParticles_cff.map
map
Definition: genParticles_cff.py:11