CbmRoot
Loading...
Searching...
No Matches
CbmEnumArray.h
Go to the documentation of this file.
1/* Copyright (C) 2024 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::core
18{
25 template<class E, class T>
26 class EnumArray : public std::array<T, static_cast<std::size_t>(E::END)> {
27 using U = typename std::underlying_type<E>::type;
28 using Arr = std::array<T, static_cast<std::size_t>(E::END)>;
29
30 public:
33 T& operator[](const E& entry) { return Arr::operator[](static_cast<U>(entry)); }
34
37 T& operator[](U index) { return Arr::operator[](index); }
38
41 const T& operator[](const E& entry) const { return Arr::operator[](static_cast<U>(entry)); }
42
45 const T& operator[](U index) const { return Arr::operator[](index); }
46
48 operator Arr&() const { return *this; }
49
50 private:
52 template<typename Archive>
53 void serialize(Archive& ar, const unsigned int /*version*/)
54 {
55 ar& boost::serialization::base_object<Arr>(*this);
56 }
57 };
58} // namespace cbm::core
const T & operator[](U index) const
Constant access operator, indexed by underlying index type.
T & operator[](U index)
Mutable access operator, indexed by underlying index type.
T & operator[](const E &entry)
Mutable access operator, indexed by enum entry.
friend class boost::serialization::access
typename std::underlying_type< E >::type U
Underlying type of enumeration.
const T & operator[](const E &entry) const
Constant access operator, indexed by enum entry.
std::array< T, static_cast< std::size_t >(E::END)> Arr
void serialize(Archive &ar, const unsigned int)