17#include <unordered_map>
63 operator bool()
const {
return isValid(); }
83 template <
class Mapper>
84 auto accumulate( Mapper f, std::invoke_result_t<Mapper, const T*> init )
const ->
decltype( init ) {
91 template <
class Mapper,
class BinaryOperation>
92 auto accumulate( Mapper f, std::invoke_result_t<Mapper, const T*> init, BinaryOperation op )
const
95 return std::accumulate(
m_ptrs.begin(),
m_ptrs.end(), init, [&f, &op](
const auto& partial,
const auto& p ) {
96 return op( partial, f( p.second ) );
104 for (
auto& i :
m_ptrs ) f( i.second );
111 for (
auto& i :
m_ptrs ) f( i.second );
118 for (
auto& i :
m_ptrs ) f( i.first, i.second );
123 for (
auto& i :
m_ptrs ) f( i.first, i.second );
146 template <
typename T>
162 operator T&() {
return get(); }
163 operator const T&()
const {
return get(); }
176 T&
operator=(
const T& other ) {
return static_cast<T&
>( *this ) = other; }
183 template <
class T1,
class BinaryOperation>
185 return m_ptr.accumulate( [](
const T* p ) {
return *p; }, init, op );
191 m_ptr.for_each( [&f](
const T* p ) { f( *p ); } );
197 m_ptr.for_each( [&f]( T* p ) { f( *p ); } );
203 m_ptr.for_all( [&f](
size_t s,
const T* p ) { f( s, *p ); } );
207 m_ptr.for_all( [&f](
size_t s, T* p ) { f( s, *p ); } );
This class represents an entry point to all the event specific data.
T m_proto
Prototype value.
~ContextSpecificData()
Destructor.
ContextSpecificData(T proto={})
Constructor with prototype value.
ContextSpecificPtr< T > & operator->()
void for_all(F f) const
Call a function on each element, passing slot# as well.
ContextSpecificData(const ContextSpecificData &)=delete
T & get() const
Access contained value.
ContextSpecificPtr< T > m_ptr
Internal implementation.
T & operator=(const T &other)
Assignment operator.
void for_each(F f) const
Call a function on each contained value.
const ContextSpecificPtr< T > & operator->() const
T accumulate(T init) const
Return the sum of all the contained values using init as first value.
T1 accumulate(T1 init, BinaryOperation op) const
Return the accumulated result, through the operation 'op', of all the contained values using init as ...
void for_each(F f)
Call a function on each contained value. (non-const version)
Simple implementation of a smart pointer with different values for different event contexts (slots).
T & operator*()
Dereference operators.
T * get() const
Return the pointer for the current context (null for a new context).
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,...
std::mutex m_ptrs_lock
Mutex for the m_ptrs container.
const T * operator->() const
T *& set(T *ptr)
Set the pointer for the current context.
void for_all(F f) const
Call a function on each element, passing slot# as well.
const T & operator*() const
std::unordered_map< ContextIdType, T * > StorageType
Type used for the internal storage.
void for_each(F f) const
Call a function on each contained pointer.
StorageType m_ptrs
Internal storage for the different internal pointers.
T *& operator=(T *ptr)
Assignment operator (.
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...
bool isValid() const
Return true if the pointer is not null.
bool operator==(T *rhs) const
Comparison with another pointer.
void for_each(F f)
Call a function on each contained pointer. (non-const version)
void clear()
Non thread-safe methods.
GAUDI_API ContextIdType currentContextId()
Return the current context id.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...