ATLAS Offline Software
Loading...
Searching...
No Matches
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{
15protected:
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
23 mutable std::mutex m_mutex;
24 std::map<std::string, const void * > m_registry;
25public:
26 void dumpKits(std::ostream &out) const;
27
28};
29
30template <class T_KitInterface>
31class KitManager : public KitManagerBase {
32public:
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
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
const void * kitPtr(const std::string &name) const
std::mutex m_mutex
Definition KitManager.h:23
bool registerKit(const std::string &name, const void *a_kit)
void dumpKits(std::ostream &out) const
virtual ~KitManagerBase()
std::map< std::string, const void * > m_registry
Definition KitManager.h:24
static KitManager< T_KitInterface > & instance()
Definition KitManager.h:50
bool registerKit(const std::string &name, const T_KitInterface *a_kit)
Definition KitManager.h:41
const T_KitInterface & kit(const std::string &name) const
Definition KitManager.h:45