Go to the documentation of this file.
11 #ifndef _GAUDI_CONTEXTSPECIFICPTR_H_
12 #define _GAUDI_CONTEXTSPECIFICPTR_H_
17 #include <type_traits>
18 #include <unordered_map>
64 operator bool()
const {
return isValid(); }
84 template <
class Mapper>
85 auto accumulate( Mapper f, std::invoke_result_t<Mapper, const T*> init )
const -> decltype( init ) {
92 template <
class Mapper,
class BinaryOperation>
93 auto accumulate( Mapper f, std::invoke_result_t<Mapper, const T*> init, BinaryOperation op )
const
97 return op( partial, f( p.second ) );
105 for (
auto& i :
m_ptrs ) f( i.second );
112 for (
auto& i :
m_ptrs ) f( i.second );
119 for (
auto& i :
m_ptrs ) f( i.first, i.second );
124 for (
auto& i :
m_ptrs ) f( i.first, i.second );
147 template <
typename T>
161 operator T&()
const {
167 T&
operator=(
const T& other ) {
return (T&)( *this ) = other; }
174 template <
class T1,
class BinaryOperation>
176 return m_ptr.accumulate( [](
const T* p ) {
return *p; }, init, op );
182 m_ptr.for_each( [&f](
const T* p ) { f( *p ); } );
188 m_ptr.for_each( [&f]( T* p ) { f( *p ); } );
194 m_ptr.for_all( [&f](
size_t s,
const T* p ) { f(
s, *p ); } );
198 m_ptr.for_all( [&f](
size_t s, T* p ) { f(
s, *p ); } );
213 #endif // _GAUDI_CONTEXTSPECIFICPTR_H_
bool operator==(T *rhs) const
Comparison with another pointer.
void clear()
Non thread-safe methods.
T & operator*()
Dereference operators.
ContextSpecificData(T proto={})
Constructor with prototype value.
T accumulate(T init) const
Return the sum of all the contained values using init as first value.
T *& set(T *ptr)
Set the pointer for the current context.
ContextSpecificPtr< T > m_ptr
Internal implementation.
auto accumulate(Mapper f, std::invoke_result_t< Mapper, const T * > init) const -> decltype(init)
Taking a function f that from a T* produces a value, return the sum of all the values corresponding t...
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
T1 accumulate(T1 init, BinaryOperation op) const
Return the accumulated result, through the operation 'op', of all the contained values using init as ...
T & operator=(const T &other)
Assignment operator.
T *& operator=(T *ptr)
Assignment operator (.
Simple implementation of a smart pointer with different values for different event contexts (slots).
void for_each(F f) const
Call a function on each contained value.
ContextSpecificData(const ContextSpecificData &)=delete
void for_all(F f) const
Call a function on each element, passing slot# as well.
StorageType m_ptrs
Internal storage for the different internal pointers.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
void for_each(F f) const
Call a function on each contained pointer.
T * get() const
Return the pointer for the current context (null for a new context).
void for_all(F f) const
Call a function on each element, passing slot# as well.
std::unordered_map< ContextIdType, T * > StorageType
Type used for the internal storage.
~ContextSpecificData()
Destructor.
void for_each(F f)
Call a function on each contained value. (non-const version)
const T * operator->() const
GAUDI_API ContextIdType currentContextId()
Return the current context id.
const T & operator*() const
Implementation of a context specific storage accessible as a sort of smart reference class.
void accumulate(Counter &counter, const Container &container, Fun f=Identity{})
A helper function for accumulating data from a container into a counter This is internally using buff...
bool isValid() const
Return true if the pointer is not null.
auto accumulate(Mapper f, std::invoke_result_t< Mapper, const T * > init, BinaryOperation op) const -> decltype(init)
Taking a function f that from a T* produces a value, return the accumulated result,...
T m_proto
Prototype value.
void for_each(F f)
Call a function on each contained pointer. (non-const version)