ATLAS Offline Software
Loading...
Searching...
No Matches
SG::ConstAccessor< T, ALLOC > Class Template Reference

Helper class to provide constant type-safe access to aux data. More...

#include <ConstAccessor.h>

Inheritance diagram for SG::ConstAccessor< T, ALLOC >:
Collaboration diagram for SG::ConstAccessor< T, ALLOC >:

Public Types

using element_type = typename AuxDataTraits<T, ALLOC>::element_type
 Type the user sees.
using const_reference_type
 Type referencing an item.
using const_container_pointer_type
 Pointer into the container holding this item.
using const_span = typename AuxDataTraits<T, ALLOC>::const_span
 A span over elements in the container.

Public Member Functions

 ConstAccessor (const std::string &name)
 Constructor.
 ConstAccessor (const std::string &name, const std::string &clsname)
 Constructor.
 ConstAccessor (const SG::auxid_t auxid)
 Constructor taking an auxid directly.
template<IsConstAuxElement ELT>
const_reference_type operator() (const ELT &e) const
 Fetch the variable for one element, as a const reference.
const_reference_type operator() (const AuxVectorData &container, size_t index) const
 Fetch the variable for one element, as a const reference.
template<IsConstAuxElement ELT>
const_reference_type withDefault (const ELT &e, const T &deflt) const
 Fetch the variable for one element, as a const reference, with a default.
const_reference_type withDefault (const AuxVectorData &container, size_t index, const T &deflt) const
 Fetch the variable for one element, as a const reference.
const_container_pointer_type getDataArray (const AuxVectorData &container) const
 Get a pointer to the start of the auxiliary data array.
const_span getDataSpan (const AuxVectorData &container) const
 Get a span over the auxilary data array.
template<IsConstAuxElement ELT>
bool isAvailable (const ELT &e) const
 Test to see if this variable exists in the store.
bool isAvailable (const AuxVectorData &c) const
 Test to see if this variable exists in the store.
SG::auxid_t auxid () const
 Return the aux id for this variable.

Protected Member Functions

 ConstAccessor (const std::string &name, const std::string &clsname, const SG::AuxVarFlags flags)
 Constructor.
 ConstAccessor (const SG::auxid_t auxid, const SG::AuxVarFlags flags)
 Constructor taking an auxid directly.

Protected Attributes

SG::auxid_t m_auxid
 The cached auxid.

Detailed Description

template<class T, class ALLOC = AuxAllocator_t<T>>
class SG::ConstAccessor< T, ALLOC >

Helper class to provide constant type-safe access to aux data.

This is written as a separate class in order to be able to cache the name -> auxid lookup.

You might use this something like this:

// Only need to do this once.
static const SG::ConstAccessor<int> vint1 ("myInt");
...
const DataVector<MyClass>* v = ...;
const Myclass* m = v->at(2);
int x = vint1 (*m);
#define x
Derived DataVector<T>.
Definition DataVector.h:795
Helper class to provide constant type-safe access to aux data.

This class can be used only for reading data. To modify data, see the class Accessor.

Definition at line 54 of file ConstAccessor.h.

Member Typedef Documentation

◆ const_container_pointer_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::ConstAccessor< T, ALLOC >::const_container_pointer_type
Initial value:
typename vector_type::const_pointer const_container_pointer_type

Pointer into the container holding this item.

Definition at line 65 of file ConstAccessor.h.

◆ const_reference_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::ConstAccessor< T, ALLOC >::const_reference_type
Initial value:

Type referencing an item.

Definition at line 61 of file ConstAccessor.h.

◆ const_span

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::ConstAccessor< T, ALLOC >::const_span = typename AuxDataTraits<T, ALLOC>::const_span

A span over elements in the container.

Definition at line 69 of file ConstAccessor.h.

◆ element_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::ConstAccessor< T, ALLOC >::element_type = typename AuxDataTraits<T, ALLOC>::element_type

Type the user sees.

Definition at line 58 of file ConstAccessor.h.

Constructor & Destructor Documentation

◆ ConstAccessor() [1/5]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::ConstAccessor< T, ALLOC >::ConstAccessor ( const std::string & name)

Constructor.

Parameters
nameName of this aux variable.

The name -> auxid lookup is done here.

◆ ConstAccessor() [2/5]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::ConstAccessor< T, ALLOC >::ConstAccessor ( const std::string & name,
const std::string & clsname )

Constructor.

Parameters
nameName of this aux variable.
clsnameThe name of its associated class. May be blank.

The name -> auxid lookup is done here.

◆ ConstAccessor() [3/5]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::ConstAccessor< T, ALLOC >::ConstAccessor ( const SG::auxid_t auxid)

Constructor taking an auxid directly.

Parameters
auxidID for this auxiliary variable.

Will throw SG::ExcAuxTypeMismatch if the types don't match.

◆ ConstAccessor() [4/5]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::ConstAccessor< T, ALLOC >::ConstAccessor ( const std::string & name,
const std::string & clsname,
const SG::AuxVarFlags flags )
protected

Constructor.

Parameters
nameName of this aux variable.
clsnameThe name of its associated class. May be blank.
flagsOptional flags qualifying the type. See AuxTypeRegistry.

The name -> auxid lookup is done here.

◆ ConstAccessor() [5/5]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::ConstAccessor< T, ALLOC >::ConstAccessor ( const SG::auxid_t auxid,
const SG::AuxVarFlags flags )
protected

Constructor taking an auxid directly.

Parameters
auxidID for this auxiliary variable.
flagsOptional flags qualifying the type. See AuxTypeRegistry.

Will throw SG::ExcAuxTypeMismatch if the types don't match.

Member Function Documentation

◆ auxid()

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::auxid_t SG::ConstAccessor< T, ALLOC >::auxid ( ) const

Return the aux id for this variable.

◆ getDataArray()

template<class T, class ALLOC = AuxAllocator_t<T>>
const_container_pointer_type SG::ConstAccessor< T, ALLOC >::getDataArray ( const AuxVectorData & container) const

Get a pointer to the start of the auxiliary data array.

Parameters
containerThe container from which to fetch the variable.

◆ getDataSpan()

template<class T, class ALLOC = AuxAllocator_t<T>>
const_span SG::ConstAccessor< T, ALLOC >::getDataSpan ( const AuxVectorData & container) const

Get a span over the auxilary data array.

Parameters
containerThe container from which to fetch the variable.

◆ isAvailable() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
bool SG::ConstAccessor< T, ALLOC >::isAvailable ( const AuxVectorData & c) const

Test to see if this variable exists in the store.

Parameters
cThe container in which to test the variable.

◆ isAvailable() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsConstAuxElement ELT>
bool SG::ConstAccessor< T, ALLOC >::isAvailable ( const ELT & e) const

Test to see if this variable exists in the store.

Parameters
eAn element of the container in which to test the variable.

◆ operator()() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
const_reference_type SG::ConstAccessor< T, ALLOC >::operator() ( const AuxVectorData & container,
size_t index ) const

Fetch the variable for one element, as a const reference.

Parameters
containerThe container from which to fetch the variable.
indexThe index of the desired element.

This allows retrieving aux data by container / index. Looping over the index via this method will be faster then looping over the elements of the container.

◆ operator()() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsConstAuxElement ELT>
const_reference_type SG::ConstAccessor< T, ALLOC >::operator() ( const ELT & e) const

Fetch the variable for one element, as a const reference.

Parameters
eThe element for which to fetch the variable.

◆ withDefault() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
const_reference_type SG::ConstAccessor< T, ALLOC >::withDefault ( const AuxVectorData & container,
size_t index,
const T & deflt ) const

Fetch the variable for one element, as a const reference.

Parameters
containerThe container from which to fetch the variable.
indexThe index of the desired element.
defltDefault value.

This allows retrieving aux data by container / index. Looping over the index via this method will be faster then looping over the elements of the container. If this variable is not available, then return deflt instead.

◆ withDefault() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsConstAuxElement ELT>
const_reference_type SG::ConstAccessor< T, ALLOC >::withDefault ( const ELT & e,
const T & deflt ) const

Fetch the variable for one element, as a const reference, with a default.

Parameters
eThe element for which to fetch the variable.
defltDefault value.

If this variable is not available, then return deflt instead.

Member Data Documentation

◆ m_auxid

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::auxid_t SG::ConstAccessor< T, ALLOC >::m_auxid
protected

The cached auxid.

Definition at line 211 of file ConstAccessor.h.


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