HerdSoftware  0.1.1
Public Types | Public Member Functions | List of all members
Herd::SidesArray< ContainedClass > Class Template Reference

An array that accepts side as subscripts. More...

#include <common/SidesArray.h>

Inheritance diagram for Herd::SidesArray< ContainedClass >:
Herd::ArrayForwarder< ContainedClass, RefFrame::NSides > Herd::StkClustersColl

Public Types

using BaseType = ArrayForwarder< ContainedClass, RefFrame::NSides >
 
- Public Types inherited from Herd::ArrayForwarder< ContainedClass, RefFrame::NSides >
typedef ContainedClass value_type
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef value_typeiterator
 
typedef const value_typeconst_iterator
 
typedef std::size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 

Public Member Functions

ContainedClass & operator[] (const RefFrame::Side &side)
 Accesses an element without validity check on the element index. More...
 
const ContainedClass & operator[] (const RefFrame::Side &side) const
 Accesses an element without validity check on the element index. More...
 
ContainedClass & at (const RefFrame::Side &side)
 Accesses an element with validity check on the element index. More...
 
const ContainedClass & at (const RefFrame::Side &side) const
 Accesses an element with validity check on the element index. More...
 
- Public Member Functions inherited from Herd::ArrayForwarder< ContainedClass, RefFrame::NSides >
 ArrayForwarder ()
 
 ArrayForwarder (std::array< ContainedClass, _Nm > arr)
 
void fill (const value_type &__u)
 
void swap (ArrayForwarder &__other) noexcept(noexcept(std::swap(std::declval< ContainedClass & >(), std::declval< ContainedClass & >())))
 
_GLIBCXX17_CONSTEXPR iterator begin () noexcept
 
_GLIBCXX17_CONSTEXPR const_iterator begin () const noexcept
 
_GLIBCXX17_CONSTEXPR iterator end () noexcept
 
_GLIBCXX17_CONSTEXPR const_iterator end () const noexcept
 
_GLIBCXX17_CONSTEXPR reverse_iterator rbegin () noexcept
 
_GLIBCXX17_CONSTEXPR const_reverse_iterator rbegin () const noexcept
 
_GLIBCXX17_CONSTEXPR reverse_iterator rend () noexcept
 
_GLIBCXX17_CONSTEXPR const_reverse_iterator rend () const noexcept
 
_GLIBCXX17_CONSTEXPR const_iterator cbegin () const noexcept
 
_GLIBCXX17_CONSTEXPR const_iterator cend () const noexcept
 
_GLIBCXX17_CONSTEXPR const_reverse_iterator crbegin () const noexcept
 
_GLIBCXX17_CONSTEXPR const_reverse_iterator crend () const noexcept
 
constexpr size_type size () const noexcept
 
constexpr size_type max_size () const noexcept
 
constexpr bool empty () const noexcept
 
_GLIBCXX17_CONSTEXPR reference operator[] (size_type __n) noexcept
 
constexpr const_reference operator[] (size_type __n) const noexcept
 
_GLIBCXX17_CONSTEXPR reference at (size_type __n)
 
constexpr const_reference at (size_type __n) const
 
_GLIBCXX17_CONSTEXPR reference front () noexcept
 
constexpr const_reference front () const noexcept
 
_GLIBCXX17_CONSTEXPR reference back () noexcept
 
constexpr const_reference back () const noexcept
 
_GLIBCXX17_CONSTEXPR pointer data () noexcept
 
_GLIBCXX17_CONSTEXPR const_pointer data () const noexcept
 

Detailed Description

template<typename ContainedClass>
class Herd::SidesArray< ContainedClass >

An array that accepts side as subscripts.

A SidesArray contains elements associated to each side of the Herd detector. The elements in an SidesArray can be indexed using RefFrame::Side values. The class does not support the braced initialization lists like std::array, since it doesn't guarantee any relation between the position in the initializer list and the side value. So it is not possible to initialize Side Array as:

SidesArray<int> sa{0, 1, 2, 3, 4}; // Compiler error
sa = {4, 5, 6, 7, 8}; // Compiler error

The typical usage of a SidesArray involves the subscript operator together with a RefFrame::Side used as the subscript index. For example, suppose to have to store one integer value for each side:

SidesArray<int> array;

To set the value of the TOP element to 1 and of the Xneg element to 2:

This brief example shows the main purpose of the SidesArray: using a RefFrame::Side to index the sides instead of integers removes a potential source of confusion, e.g.:

array[0] = 1; // Which is side 0? TOP?? Xneg???

Loops

With the help of RefFrame::Sides and of RefFrame::NSides is it also possible to loop over all the values of a SidesArray with a range-for loop, e.g.:

for (auto side : RefFrame::Sides){
array[side] = 0;
}

or with a "classic" for loop:

for (int iSide = 0; iSide < RefFrame::NSides; ++iSide){
array[RefFrame::Sides[iSide]] = 0;
}

Member Typedef Documentation

◆ BaseType

template<typename ContainedClass>
using Herd::SidesArray< ContainedClass >::BaseType = ArrayForwarder<ContainedClass, RefFrame::NSides>

Member Function Documentation

◆ at() [1/2]

template<typename ContainedClass>
ContainedClass& Herd::SidesArray< ContainedClass >::at ( const RefFrame::Side side)
inline

Accesses an element with validity check on the element index.

Accesses the element corresponding to the given side; if the side is NONE then a std::out_of_range exception will be thrown.

Parameters
sideThe side of the desired element.
Returns
a reference to the desired element.
Exceptions
std::out_of_rangeif side == RefFrame::Side::NONE.

◆ at() [2/2]

template<typename ContainedClass>
const ContainedClass& Herd::SidesArray< ContainedClass >::at ( const RefFrame::Side side) const
inline

Accesses an element with validity check on the element index.

Accesses the element corresponding to the given side; if the side is NONE then a std::out_of_range exception will be thrown.

Parameters
sideThe side of the desired element.
Returns
a const reference to the desired element.
Exceptions
std::out_of_rangeif side == RefFrame::Side::NONE.

◆ operator[]() [1/2]

template<typename ContainedClass>
ContainedClass& Herd::SidesArray< ContainedClass >::operator[] ( const RefFrame::Side side)
inline

Accesses an element without validity check on the element index.

Accesses the element corresponding to the given side. No check is performed on the side argument, so passing NONE will result in undefined behavior.

Parameters
sideThe side of the desired element.
Returns
a reference to the desired element.

◆ operator[]() [2/2]

template<typename ContainedClass>
const ContainedClass& Herd::SidesArray< ContainedClass >::operator[] ( const RefFrame::Side side) const
inline

Accesses an element without validity check on the element index.

Accesses the element corresponding to the given side. No check is performed on the side argument, so passing NONE will result in undefined behavior.

Parameters
sideThe side of the desired element.
Returns
a const reference to the desired element.

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