ATLAS Offline Software
Loading...
Searching...
No Matches
KitManager< T_KitInterface > Class Template Reference

#include <KitManager.h>

Inheritance diagram for KitManager< T_KitInterface >:
Collaboration diagram for KitManager< T_KitInterface >:

Public Member Functions

 ~KitManager ()
bool registerKit (const std::string &name, const T_KitInterface *a_kit)
const T_KitInterface & kit (const std::string &name) const
void dumpKits (std::ostream &out) const

Static Public Member Functions

static KitManager< T_KitInterface > & instance ()

Protected Member Functions

const void * kitPtr (const std::string &name) const
bool registerKit (const std::string &name, const void *a_kit)

Protected Attributes

std::mutex m_mutex
std::map< std::string, const void * > m_registry

Detailed Description

template<class T_KitInterface>
class KitManager< T_KitInterface >

Definition at line 31 of file KitManager.h.

Constructor & Destructor Documentation

◆ ~KitManager()

template<class T_KitInterface>
KitManager< T_KitInterface >::~KitManager ( )
inline

Definition at line 33 of file KitManager.h.

33 {
35 const T_KitInterface *ptr=reinterpret_cast<const T_KitInterface *>(elm.second);
36 delete ptr;
37 elm.second = nullptr;
38 }
39 }
std::map< std::string, const void * > m_registry
Definition KitManager.h:24

Member Function Documentation

◆ dumpKits()

void KitManagerBase::dumpKits ( std::ostream & out) const
inherited

Definition at line 27 of file KitManager.cxx.

27 {
28 std::lock_guard<std::mutex> lock (m_mutex);
29 for(const std::pair<const std::string, const void *> &elm: m_registry) {
30 out << " " << elm.first;
31 }
32}
std::mutex m_mutex
Definition KitManager.h:23

◆ instance()

template<class T_KitInterface>
KitManager< T_KitInterface > & KitManager< T_KitInterface >::instance ( )
inlinestatic

Definition at line 50 of file KitManager.h.

50 {
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 }

◆ kit()

template<class T_KitInterface>
const T_KitInterface & KitManager< T_KitInterface >::kit ( const std::string & name) const
inline

Definition at line 45 of file KitManager.h.

45 {
46 return *(reinterpret_cast< const T_KitInterface *>(KitManagerBase::kitPtr(name)));
47 }
const void * kitPtr(const std::string &name) const

◆ kitPtr()

const void * KitManagerBase::kitPtr ( const std::string & name) const
protectedinherited

Definition at line 11 of file KitManager.cxx.

11 {
12 std::lock_guard<std::mutex> lock (m_mutex);
13 return m_registry.at(name);
14}

◆ registerKit() [1/2]

template<class T_KitInterface>
bool KitManager< T_KitInterface >::registerKit ( const std::string & name,
const T_KitInterface * a_kit )
inline

Definition at line 41 of file KitManager.h.

41 {
42 return KitManagerBase::registerKit(name, static_cast< const void *>(a_kit));
43 }
bool registerKit(const std::string &name, const void *a_kit)

◆ registerKit() [2/2]

bool KitManagerBase::registerKit ( const std::string & name,
const void * a_kit )
protectedinherited

Definition at line 16 of file KitManager.cxx.

16 {
17 std::lock_guard<std::mutex> lock (m_mutex);
18 std::pair<std::string, const void *> elm = std::make_pair(name, a_kit);
19 if (!m_registry.insert(elm).second) {
20 std::stringstream message;
21 message << "Failed to register kit " << elm.first;
22 throw std::runtime_error(message.str());
23 }
24 return true;
25}

Member Data Documentation

◆ m_mutex

std::mutex KitManagerBase::m_mutex
mutableprotectedinherited

Definition at line 23 of file KitManager.h.

◆ m_registry

std::map<std::string, const void * > KitManagerBase::m_registry
protectedinherited

Definition at line 24 of file KitManager.h.


The documentation for this class was generated from the following file: