ATLAS Offline Software
KitManager.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef TRKRIO_ONTRACKCREATOR_KITMANAGER_H
5 #define TRKRIO_ONTRACKCREATOR_KITMANAGER_H
6 
7 #include <ostream>
8 #include <map>
9 #include <memory>
10 #include <mutex>
12 
14 {
15 protected:
17  virtual ~KitManagerBase();
18 
19  const void *kitPtr(const std::string &name) const;
20 
21  bool registerKit(const std::string& name, const void *a_kit);
22 
24  std::map<std::string, const void * > m_registry;
25 public:
26  void dumpKits(std::ostream &out) const;
27 
28 };
29 
30 template <class T_KitInterface>
31 class KitManager : public KitManagerBase {
32 public:
34  for( std::pair<const std::string, const void *> &elm : m_registry ) {
35  const T_KitInterface *ptr=reinterpret_cast<const T_KitInterface *>(elm.second);
36  delete ptr;
37  elm.second = nullptr;
38  }
39  }
40 
41  bool registerKit(const std::string& name, const T_KitInterface *a_kit) {
42  return KitManagerBase::registerKit(name, static_cast< const void *>(a_kit));
43  }
44 
45  const T_KitInterface &kit(const std::string &name) const {
46  return *(reinterpret_cast< const T_KitInterface *>(KitManagerBase::kitPtr(name)));
47  }
48 
49  static
51  /* in C++11 this is to happen once the issue is that we return a ref
52  * rather than const ref. To be thread safe we need to have static const */
53  // Map is protected with a lock.
55  return s_instance;
56  }
57 };
58 
59 
60 #endif
KitManager
Definition: KitManager.h:31
KitManager::~KitManager
~KitManager()
Definition: KitManager.h:33
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
KitManager::registerKit
bool registerKit(const std::string &name, const T_KitInterface *a_kit)
Definition: KitManager.h:41
KitManagerBase
Definition: KitManager.h:14
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
KitManagerBase::~KitManagerBase
virtual ~KitManagerBase()
KitManager::instance
static KitManager< T_KitInterface > & instance()
Definition: KitManager.h:50
KitManagerBase::KitManagerBase
KitManagerBase()
KitManagerBase::dumpKits
void dumpKits(std::ostream &out) const
Definition: KitManager.cxx:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
KitManagerBase::m_mutex
std::mutex m_mutex
Definition: KitManager.h:23
KitManagerBase::registerKit
bool registerKit(const std::string &name, const void *a_kit)
Definition: KitManager.cxx:16
KitManagerBase::m_registry
std::map< std::string, const void * > m_registry
Definition: KitManager.h:24
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
checker_macros.h
Define macros for attributes used to control the static checker.
KitManagerBase::kitPtr
const void * kitPtr(const std::string &name) const
Definition: KitManager.cxx:11
KitManager::kit
const T_KitInterface & kit(const std::string &name) const
Definition: KitManager.h:45