CbmRoot
Loading...
Searching...
No Matches
CaEnumArray.h
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once // include this header only once per compilation unit
11
12#include <boost/serialization/array.hpp>
13#include <boost/serialization/base_object.hpp>
14
15#include <array>
16
17namespace cbm::algo::ca
18{
23 enum class EDummy
24 {
25 END
26 };
27
34 template<class E, class T>
35 class EnumArray : public std::array<T, static_cast<std::size_t>(E::END)> {
36 using U = typename std::underlying_type<E>::type;
37 using Arr = std::array<T, static_cast<std::size_t>(E::END)>;
38
39 public:
41 T& operator[](const E& entry)
42 {
43 return std::array<T, static_cast<std::size_t>(E::END)>::operator[](static_cast<U>(entry));
44 }
45
47 T& operator[](U index) { return std::array<T, static_cast<std::size_t>(E::END)>::operator[](index); }
48
50 const T& operator[](const E& entry) const
51 {
52 return std::array<T, static_cast<std::size_t>(E::END)>::operator[](static_cast<U>(entry));
53 }
54
57 const T& operator[](U index) const { return std::array<T, static_cast<std::size_t>(E::END)>::operator[](index); }
58
60 operator Arr&() const { return *this; }
61
62 private:
64 template<typename Archive>
65 void serialize(Archive& ar, const unsigned int /*version*/)
66 {
67 ar& boost::serialization::base_object<Arr>(*this);
68 }
69 };
70} // namespace cbm::algo::ca
typename std::underlying_type< E >::type U
Underlying type of enumeration.
Definition CaEnumArray.h:36
std::array< T, static_cast< std::size_t >(E::END)> Arr
Definition CaEnumArray.h:37
void serialize(Archive &ar, const unsigned int)
Definition CaEnumArray.h:65
T & operator[](const E &entry)
Mutable access operator, indexed by enum entry.
Definition CaEnumArray.h:41
T & operator[](U index)
Mutable access operator, indexed by underlying index type.
Definition CaEnumArray.h:47
const T & operator[](U index) const
Constant access operator, indexed by underlying index type.
Definition CaEnumArray.h:57
friend class boost::serialization::access
Definition CaEnumArray.h:63
const T & operator[](const E &entry) const
Constant access operator, indexed by enum entry.
Definition CaEnumArray.h:50
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
EDummy
Dummy enum, representing an array with zero elements.
Definition CaEnumArray.h:24