LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::thread_safe_registry_via_id< K, M > Class Template Reference

#include "thread_safe_registry_via_id.h"

Public Types

using collection_type = std::map< K, M >
 
using value_type = typename collection_type::value_type
 

Static Public Member Functions

template<typename C >
static void put (C const &container)
 
static auto emplace (value_type const &value)
 
static auto emplace (K const &key, M const &mapped)
 
static bool empty ()
 
static collection_type const & get ()
 
static bool get (K const &key, M &mapped)
 
static auto instance (bool cleanup=false)
 

Static Private Member Functions

static auto & mutex_ ()
 

Detailed Description

template<typename K, typename M>
class art::thread_safe_registry_via_id< K, M >

Definition at line 33 of file thread_safe_registry_via_id.h.

Member Typedef Documentation

template<typename K , typename M >
using art::thread_safe_registry_via_id< K, M >::collection_type = std::map<K, M>

Definition at line 35 of file thread_safe_registry_via_id.h.

template<typename K , typename M >
using art::thread_safe_registry_via_id< K, M >::value_type = typename collection_type::value_type

Definition at line 36 of file thread_safe_registry_via_id.h.

Member Function Documentation

template<typename K , typename M >
auto art::thread_safe_registry_via_id< K, M >::emplace ( value_type const &  value)
static
template<typename K , typename M >
auto art::thread_safe_registry_via_id< K, M >::emplace ( K const &  key,
M const &  mapped 
)
static

Definition at line 93 of file thread_safe_registry_via_id.h.

References art::thread_safe_registry_via_id< K, M >::instance(), and art::thread_safe_registry_via_id< K, M >::mutex_().

94  {
95  std::lock_guard sentry{mutex_()};
96  return instance()->emplace(key, mapped);
97  }
static auto instance(bool cleanup=false)
template<typename K , typename M >
bool art::thread_safe_registry_via_id< K, M >::empty ( )
static

Definition at line 101 of file thread_safe_registry_via_id.h.

References art::thread_safe_registry_via_id< K, M >::instance(), and art::thread_safe_registry_via_id< K, M >::mutex_().

102  {
103  std::lock_guard sentry{mutex_()};
104  return instance()->empty();
105  }
static auto instance(bool cleanup=false)
template<typename K , typename M >
auto art::thread_safe_registry_via_id< K, M >::get ( )
static
template<typename K , typename M >
bool art::thread_safe_registry_via_id< K, M >::get ( K const &  key,
M &  mapped 
)
static

Definition at line 116 of file thread_safe_registry_via_id.h.

References art::thread_safe_registry_via_id< K, M >::instance(), and art::thread_safe_registry_via_id< K, M >::mutex_().

117  {
118  std::lock_guard sentry{mutex_()};
119  auto me = instance();
120  auto it = me->find(k);
121  if (it != me->cend()) {
122  mapped = it->second;
123  return true;
124  }
125  return false;
126  }
static auto instance(bool cleanup=false)
template<typename K , typename M >
static auto art::thread_safe_registry_via_id< K, M >::instance ( bool  cleanup = false)
inlinestatic

Definition at line 46 of file thread_safe_registry_via_id.h.

References art::thread_safe_registry_via_id< K, M >::mutex_().

Referenced by art::thread_safe_registry_via_id< K, M >::emplace(), art::thread_safe_registry_via_id< K, M >::empty(), art::EventProcessor::EventProcessor(), art::thread_safe_registry_via_id< K, M >::get(), and art::thread_safe_registry_via_id< K, M >::put().

47  {
48  std::lock_guard sentry{mutex_()};
49  static collection_type* me = new collection_type{};
50  if (cleanup) {
51  delete me;
52  me = nullptr;
53  return me;
54  }
55  if (me == nullptr) {
56  // We have been cleaned up and are now being used again.
57  me = new collection_type{};
58  }
59  return me;
60  }
template<typename K , typename M >
static auto& art::thread_safe_registry_via_id< K, M >::mutex_ ( )
inlinestaticprivate
template<typename K , typename M >
template<typename C >
void art::thread_safe_registry_via_id< K, M >::put ( C const &  container)
static

Definition at line 74 of file thread_safe_registry_via_id.h.

References e, art::thread_safe_registry_via_id< K, M >::instance(), and art::thread_safe_registry_via_id< K, M >::mutex_().

75  {
76  std::lock_guard sentry{mutex_()};
77  auto me = instance();
78  for (auto const& e : container) {
79  me->emplace(e);
80  }
81  }
static auto instance(bool cleanup=false)
Float_t e
Definition: plot.C:35

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