HerdSoftware  0.1.1
CooArray.h
Go to the documentation of this file.
1 /*
2  * CooArray.h
3  *
4  * Created on: 9 Jan 2019
5  * Author: Nicola Mori
6  */
7 
8 #ifndef HERD_COOARRAY_H_
9 #define HERD_COOARRAY_H_
10 
11 // HerdSoftware headers
12 #include "common/ArrayForwarder.h"
13 #include "common/RefFrame.h"
14 
15 namespace Herd {
22 template <typename ContainedClass> class CooArray : public ArrayForwarder<ContainedClass, 3> {
23 public:
25 
28  CooArray() {}
29 
35 
41  // Note by VF: This one used to have a variadic template and was tricky to write. See
42  // https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list
43  // Note by NM: the implementation making use of variadic templates blocked the possibility to implement a copy
44  // constructor
45  template <typename V>
46  CooArray(V &&v1, V &&v2, V &&v3)
47  : BaseType({static_cast<ContainedClass>(v1), static_cast<ContainedClass>(v2), static_cast<ContainedClass>(v3)}) {}
48 
54  CooArray(const std::array<ContainedClass, 3> &values) : BaseType(values) {}
55  CooArray(std::array<ContainedClass, 3> &&values) : BaseType(values) {}
56 
63  BaseType::operator=(lhs);
64  return *this;
65  }
66 
75  ContainedClass &operator[](const RefFrame::Coo &coo) { return BaseType::operator[](static_cast<int>(coo)); }
76 
85  const ContainedClass &operator[](const RefFrame::Coo &coo) const {
86  return BaseType::operator[](static_cast<int>(coo));
87  }
88 
98  ContainedClass &at(const RefFrame::Coo &coo) { return BaseType::at(static_cast<int>(coo)); }
99 
109  const ContainedClass &at(const RefFrame::Coo &coo) const { return BaseType::at(static_cast<int>(coo)); }
110 };
111 
112 } // namespace Herd
113 
114 #endif /* HERD_COOARRAY_H_ */
Coo
Aliases for the three space coordinates. RefFrame.h common/RefFrame.h.
Definition: RefFrame.h:24
CssGeoParams.h CssGeoParams class declaration.
Definition: CaloPDCalibrationAlgo.h:24
ContainedClass & operator[](const RefFrame::Coo &coo)
Accesses an element without validity check on the element index.
Definition: CooArray.h:75
An array that accepts coordinates as subscripts.
Definition: CooArray.h:22
CooArray()
Default constructor.
Definition: CooArray.h:28
const ContainedClass & operator[](const RefFrame::Coo &coo) const
Accesses an element without validity check on the element index.
Definition: CooArray.h:85
A forwarder class for std::array.
Definition: ArrayForwarder.h:48
CooArray(std::array< ContainedClass, 3 > &&values)
Definition: CooArray.h:55
CooArray(const std::array< ContainedClass, 3 > &values)
Array constructors.
Definition: CooArray.h:54
_GLIBCXX17_CONSTEXPR reference operator[](size_type __n) noexcept
Definition: ArrayForwarder.h:148
CooArray(const CooArray< ContainedClass > &c)
Copy constructor.
Definition: CooArray.h:34
CooArray< ContainedClass > & operator=(const CooArray< ContainedClass > &lhs)
Assignment operator.
Definition: CooArray.h:62
CooArray(V &&v1, V &&v2, V &&v3)
Initializer list constructor.
Definition: CooArray.h:46
_GLIBCXX17_CONSTEXPR reference at(size_type __n)
Definition: ArrayForwarder.h:152
const ContainedClass & at(const RefFrame::Coo &coo) const
Accesses an element with validity check on the element index.
Definition: CooArray.h:109
ContainedClass & at(const RefFrame::Coo &coo)
Accesses an element with validity check on the element index.
Definition: CooArray.h:98