Gaudi::Hive::ContextSpecificPtr< T > Class Template Reference

Simple implementation of a smart pointer with different values for different event contexts (slots). More...

#include </tmp/marcocle/lhcb-release/1122/GAUDI/GAUDI_v27r0/InstallArea/x86_64-slc6-gcc49-opt/include/GaudiKernel/ContextSpecificPtr.h>

Collaboration diagram for Gaudi::Hive::ContextSpecificPtr< T >:

Public Member Functions

T * get () const
 Return the pointer for the current context (null for a new context). More...
 
T *& set (T *ptr)
 Set the pointer for the current context. More...
 
T *& operator= (T *ptr)
 Assignment operator (. More...
 
bool isValid () const
 Return true if the pointer is not null. More...
 
 operator bool () const
 Conversion to boolean (. More...
 
bool operator== (T *rhs) const
 Comparison with another pointer. More...
 
T * get () const
 Return the pointer for the current context (null for a new context). More...
 
T *& set (T *ptr)
 Set the pointer for the current context. More...
 
T *& operator= (T *ptr)
 Assignment operator (. More...
 
bool isValid () const
 Return true if the pointer is not null. More...
 
 operator bool () const
 Conversion to boolean (. More...
 
bool operator== (T *rhs) const
 Comparison with another pointer. More...
 
T & operator* ()
 Dereference operators. More...
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
T & operator* ()
 Dereference operators. More...
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
void clear ()
 Non thread-safe methods. More...
 
template<class Mapper >
std::result_of< Mapper(const T *)>::type accumulate (Mapper f, typename std::result_of< Mapper(const T *)>::type init) const
 Taking a function f that from a T* produces a value, return the sum of all the values corresponding to the contained pointers using init as first value. More...
 
template<class Mapper , class BinaryOperation >
std::result_of< Mapper(const T *)>::type accumulate (Mapper f, typename std::result_of< Mapper(const T *)>::type init, BinaryOperation op) const
 Taking a function f that from a T* produces a value, return the accumulated result, through the operation 'op', of all the values corresponding to the contained pointers using init as first value. More...
 
template<class F >
void for_each (F f) const
 Call a function on each contained pointer. More...
 
template<class F >
void for_each (F f)
 Call a function on each contained pointer. (non-const version) More...
 
void deleteAll ()
 

Private Types

typedef std::unordered_map< ContextIdType, T * > StorageType
 Type used for the internal storage. More...
 
typedef std::unordered_map< ContextIdType, T * > StorageType
 Type used for the internal storage. More...
 
StorageType m_ptrs
 Internal storage for the different internal pointers. More...
 
std::mutex m_ptrs_lock
 Mutex for the m_ptrs container. More...
 
void clear ()
 Non thread-safe methods. More...
 
template<class Mapper >
std::result_of< Mapper(const T *)>::type accumulate (Mapper f, typename std::result_of< Mapper(const T *)>::type init) const
 Taking a function f that from a T* produces a value, return the sum of all the values corresponding to the contained pointers using init as first value. More...
 
template<class Mapper , class BinaryOperation >
std::result_of< Mapper(const T *)>::type accumulate (Mapper f, typename std::result_of< Mapper(const T *)>::type init, BinaryOperation op) const
 Taking a function f that from a T* produces a value, return the accumulated result, through the operation 'op', of all the values corresponding to the contained pointers using init as first value. More...
 
template<class F >
void for_each (F f) const
 Call a function on each contained pointer. More...
 
template<class F >
void for_each (F f)
 Call a function on each contained pointer. (non-const version) More...
 
void deleteAll ()
 

Detailed Description

template<typename T>
class Gaudi::Hive::ContextSpecificPtr< T >

Simple implementation of a smart pointer with different values for different event contexts (slots).

When the copy for a new context is requested, the returned pointer is null.

The interface is meant to allow for a drop-in replacement for regular pointers. It's still responsibility of the user to delete the memory associated to the pointers.

Definition at line 44 of file ContextSpecificPtr.h.

Member Typedef Documentation

template<typename T>
typedef std::unordered_map<ContextIdType, T*> Gaudi::Hive::ContextSpecificPtr< T >::StorageType
private

Type used for the internal storage.

Definition at line 47 of file ContextSpecificPtr.h.

template<typename T>
typedef std::unordered_map<ContextIdType, T*> Gaudi::Hive::ContextSpecificPtr< T >::StorageType
private

Type used for the internal storage.

Definition at line 47 of file ContextSpecificPtr.h.

Member Function Documentation

template<typename T>
template<class Mapper >
std::result_of<Mapper(const T*)>::type Gaudi::Hive::ContextSpecificPtr< T >::accumulate ( Mapper  f,
typename std::result_of< Mapper(const T *)>::type  init 
) const
inline

Taking a function f that from a T* produces a value, return the sum of all the values corresponding to the contained pointers using init as first value.

Definition at line 90 of file ContextSpecificPtr.h.

90  {
91  typedef typename std::result_of<Mapper(const T*)>::type R;
92  return accumulate(f, init, std::plus<R>());
93  }
std::result_of< Mapper(const T *)>::type accumulate(Mapper f, typename std::result_of< Mapper(const T *)>::type init) const
Taking a function f that from a T* produces a value, return the sum of all the values corresponding t...
string type
Definition: gaudirun.py:151
template<typename T>
template<class Mapper >
std::result_of<Mapper(const T*)>::type Gaudi::Hive::ContextSpecificPtr< T >::accumulate ( Mapper  f,
typename std::result_of< Mapper(const T *)>::type  init 
) const
inline

Taking a function f that from a T* produces a value, return the sum of all the values corresponding to the contained pointers using init as first value.

Definition at line 90 of file ContextSpecificPtr.h.

90  {
91  typedef typename std::result_of<Mapper(const T*)>::type R;
92  return accumulate(f, init, std::plus<R>());
93  }
std::result_of< Mapper(const T *)>::type accumulate(Mapper f, typename std::result_of< Mapper(const T *)>::type init) const
Taking a function f that from a T* produces a value, return the sum of all the values corresponding t...
string type
Definition: gaudirun.py:151
template<typename T>
template<class Mapper , class BinaryOperation >
std::result_of<Mapper(const T*)>::type Gaudi::Hive::ContextSpecificPtr< T >::accumulate ( Mapper  f,
typename std::result_of< Mapper(const T *)>::type  init,
BinaryOperation  op 
) const
inline

Taking a function f that from a T* produces a value, return the accumulated result, through the operation 'op', of all the values corresponding to the contained pointers using init as first value.

Definition at line 100 of file ContextSpecificPtr.h.

101  {
102  typedef typename std::result_of<Mapper(const T*)>::type R;
103  typedef typename StorageType::value_type V;
104  std::lock_guard<std::mutex> lock(m_ptrs_lock);
105  return std::accumulate(m_ptrs.begin(), m_ptrs.end(), init,
106  [&f, &op](const R& partial, const V& p) -> R {
107  return op(partial, f(p.second));
108  });
109  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
string type
Definition: gaudirun.py:151
template<typename T>
template<class Mapper , class BinaryOperation >
std::result_of<Mapper(const T*)>::type Gaudi::Hive::ContextSpecificPtr< T >::accumulate ( Mapper  f,
typename std::result_of< Mapper(const T *)>::type  init,
BinaryOperation  op 
) const
inline

Taking a function f that from a T* produces a value, return the accumulated result, through the operation 'op', of all the values corresponding to the contained pointers using init as first value.

Definition at line 100 of file ContextSpecificPtr.h.

101  {
102  typedef typename std::result_of<Mapper(const T*)>::type R;
103  typedef typename StorageType::value_type V;
104  std::lock_guard<std::mutex> lock(m_ptrs_lock);
105  return std::accumulate(m_ptrs.begin(), m_ptrs.end(), init,
106  [&f, &op](const R& partial, const V& p) -> R {
107  return op(partial, f(p.second));
108  });
109  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
string type
Definition: gaudirun.py:151
template<typename T>
void Gaudi::Hive::ContextSpecificPtr< T >::clear ( )
inline

Non thread-safe methods.

Set to null all the used pointers.

Definition at line 83 of file ContextSpecificPtr.h.

83 { m_ptrs.clear(); }
StorageType m_ptrs
Internal storage for the different internal pointers.
template<typename T>
void Gaudi::Hive::ContextSpecificPtr< T >::clear ( )
inline

Non thread-safe methods.

Set to null all the used pointers.

Definition at line 83 of file ContextSpecificPtr.h.

83 { m_ptrs.clear(); }
StorageType m_ptrs
Internal storage for the different internal pointers.
template<typename T>
void Gaudi::Hive::ContextSpecificPtr< T >::deleteAll ( )
inline

Definition at line 125 of file ContextSpecificPtr.h.

125  {
126  for_each([](T*& p) {delete p; p = nullptr;});
127  }
void for_each(F f) const
Call a function on each contained pointer.
template<typename T>
void Gaudi::Hive::ContextSpecificPtr< T >::deleteAll ( )
inline

Definition at line 125 of file ContextSpecificPtr.h.

125  {
126  for_each([](T*& p) {delete p; p = nullptr;});
127  }
void for_each(F f) const
Call a function on each contained pointer.
template<typename T>
template<class F >
void Gaudi::Hive::ContextSpecificPtr< T >::for_each ( f) const
inline

Call a function on each contained pointer.

Definition at line 113 of file ContextSpecificPtr.h.

113  {
114  std::lock_guard<std::mutex> lock(m_ptrs_lock);
115  for(auto& i: m_ptrs) f(i.second);
116  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
list i
Definition: ana.py:128
template<typename T>
template<class F >
void Gaudi::Hive::ContextSpecificPtr< T >::for_each ( f) const
inline

Call a function on each contained pointer.

Definition at line 113 of file ContextSpecificPtr.h.

113  {
114  std::lock_guard<std::mutex> lock(m_ptrs_lock);
115  for(auto& i: m_ptrs) f(i.second);
116  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
list i
Definition: ana.py:128
template<typename T>
template<class F >
void Gaudi::Hive::ContextSpecificPtr< T >::for_each ( f)
inline

Call a function on each contained pointer. (non-const version)

Definition at line 120 of file ContextSpecificPtr.h.

120  {
121  std::lock_guard<std::mutex> lock(m_ptrs_lock);
122  for(auto& i: m_ptrs) f(i.second);
123  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
list i
Definition: ana.py:128
template<typename T>
template<class F >
void Gaudi::Hive::ContextSpecificPtr< T >::for_each ( f)
inline

Call a function on each contained pointer. (non-const version)

Definition at line 120 of file ContextSpecificPtr.h.

120  {
121  std::lock_guard<std::mutex> lock(m_ptrs_lock);
122  for(auto& i: m_ptrs) f(i.second);
123  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
list i
Definition: ana.py:128
template<typename T>
T* Gaudi::Hive::ContextSpecificPtr< T >::get ( ) const
inline

Return the pointer for the current context (null for a new context).

Definition at line 51 of file ContextSpecificPtr.h.

51  {
52  std::lock_guard<std::mutex> lock(m_ptrs_lock);
53  return m_ptrs[currentContextId()];
54  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
GAUDI_API ContextIdType currentContextId()
Return the current context id.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
template<typename T>
T* Gaudi::Hive::ContextSpecificPtr< T >::get ( ) const
inline

Return the pointer for the current context (null for a new context).

Definition at line 51 of file ContextSpecificPtr.h.

51  {
52  std::lock_guard<std::mutex> lock(m_ptrs_lock);
53  return m_ptrs[currentContextId()];
54  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
GAUDI_API ContextIdType currentContextId()
Return the current context id.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
template<typename T>
bool Gaudi::Hive::ContextSpecificPtr< T >::isValid ( ) const
inline

Return true if the pointer is not null.

Definition at line 65 of file ContextSpecificPtr.h.

65 { return get(); }
template<typename T>
bool Gaudi::Hive::ContextSpecificPtr< T >::isValid ( ) const
inline

Return true if the pointer is not null.

Definition at line 65 of file ContextSpecificPtr.h.

65 { return get(); }
template<typename T>
Gaudi::Hive::ContextSpecificPtr< T >::operator bool ( ) const
inline

Conversion to boolean (.

See also
isValid).

Definition at line 68 of file ContextSpecificPtr.h.

68 { return isValid(); }
bool isValid() const
Return true if the pointer is not null.
template<typename T>
Gaudi::Hive::ContextSpecificPtr< T >::operator bool ( ) const
inline

Conversion to boolean (.

See also
isValid).

Definition at line 68 of file ContextSpecificPtr.h.

68 { return isValid(); }
bool isValid() const
Return true if the pointer is not null.
template<typename T>
T& Gaudi::Hive::ContextSpecificPtr< T >::operator* ( )
inline

Dereference operators.

Definition at line 74 of file ContextSpecificPtr.h.

74 { return *get(); }
template<typename T>
T& Gaudi::Hive::ContextSpecificPtr< T >::operator* ( )
inline

Dereference operators.

Definition at line 74 of file ContextSpecificPtr.h.

74 { return *get(); }
template<typename T>
const T& Gaudi::Hive::ContextSpecificPtr< T >::operator* ( ) const
inline

Definition at line 75 of file ContextSpecificPtr.h.

75 { return *get(); }
template<typename T>
const T& Gaudi::Hive::ContextSpecificPtr< T >::operator* ( ) const
inline

Definition at line 75 of file ContextSpecificPtr.h.

75 { return *get(); }
template<typename T>
T* Gaudi::Hive::ContextSpecificPtr< T >::operator-> ( )
inline

Definition at line 76 of file ContextSpecificPtr.h.

76 { return get(); }
template<typename T>
T* Gaudi::Hive::ContextSpecificPtr< T >::operator-> ( )
inline

Definition at line 76 of file ContextSpecificPtr.h.

76 { return get(); }
template<typename T>
const T* Gaudi::Hive::ContextSpecificPtr< T >::operator-> ( ) const
inline

Definition at line 77 of file ContextSpecificPtr.h.

77 { return get(); }
template<typename T>
const T* Gaudi::Hive::ContextSpecificPtr< T >::operator-> ( ) const
inline

Definition at line 77 of file ContextSpecificPtr.h.

77 { return get(); }
template<typename T>
T*& Gaudi::Hive::ContextSpecificPtr< T >::operator= ( T *  ptr)
inline

Assignment operator (.

See also
set).

Definition at line 62 of file ContextSpecificPtr.h.

62 { return set(ptr); }
T *& set(T *ptr)
Set the pointer for the current context.
template<typename T>
T*& Gaudi::Hive::ContextSpecificPtr< T >::operator= ( T *  ptr)
inline

Assignment operator (.

See also
set).

Definition at line 62 of file ContextSpecificPtr.h.

62 { return set(ptr); }
T *& set(T *ptr)
Set the pointer for the current context.
template<typename T>
bool Gaudi::Hive::ContextSpecificPtr< T >::operator== ( T *  rhs) const
inline

Comparison with another pointer.

Definition at line 71 of file ContextSpecificPtr.h.

71 { return get() == rhs; }
template<typename T>
bool Gaudi::Hive::ContextSpecificPtr< T >::operator== ( T *  rhs) const
inline

Comparison with another pointer.

Definition at line 71 of file ContextSpecificPtr.h.

71 { return get() == rhs; }
template<typename T>
T*& Gaudi::Hive::ContextSpecificPtr< T >::set ( T *  ptr)
inline

Set the pointer for the current context.

Definition at line 56 of file ContextSpecificPtr.h.

56  {
57  std::lock_guard<std::mutex> lock(m_ptrs_lock);
58  return m_ptrs[currentContextId()] = ptr;
59  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
GAUDI_API ContextIdType currentContextId()
Return the current context id.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.
template<typename T>
T*& Gaudi::Hive::ContextSpecificPtr< T >::set ( T *  ptr)
inline

Set the pointer for the current context.

Definition at line 56 of file ContextSpecificPtr.h.

56  {
57  std::lock_guard<std::mutex> lock(m_ptrs_lock);
58  return m_ptrs[currentContextId()] = ptr;
59  }
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
GAUDI_API ContextIdType currentContextId()
Return the current context id.
def lock(file)
Definition: locker.py:16
StorageType m_ptrs
Internal storage for the different internal pointers.

Member Data Documentation

template<typename T>
StorageType Gaudi::Hive::ContextSpecificPtr< T >::m_ptrs
mutableprivate

Internal storage for the different internal pointers.

Definition at line 132 of file ContextSpecificPtr.h.

template<typename T>
std::mutex Gaudi::Hive::ContextSpecificPtr< T >::m_ptrs_lock
mutableprivate

Mutex for the m_ptrs container.

Definition at line 134 of file ContextSpecificPtr.h.


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