11 #ifndef _SHAPEARRAY_H_ 12 #define _SHAPEARRAY_H_ 18 #include "NamespaceHeader.H" 33 template <
typename IIx, std::
size_t D,
typename Tuple>
34 constexpr IIx getLen(
const Tuple& a_lens) noexcept
36 static_assert(std::is_integral<
37 typename std::tuple_element<D, Tuple>::type
39 "ShapeArray requires an integer dimension");
40 return (D == std::tuple_size<Tuple>::value - 1) ? 0 : std::get<D>(a_lens);
104 template <
typename T, std::
size_t D,
typename IIx = std::ptrdiff_t>
105 struct ShapeArray : ShapeArray<T, D-1, IIx>
108 ShapeArray() noexcept
110 ShapeArray<T, D-1, IIx>()
118 template <
typename... Is>
119 ShapeArray(T* a_data, Is... a_lens) noexcept
121 ShapeArray<T, D-1, IIx>(a_data, a_lens...),
122 m_thisDlen(getLen<IIx, D-1>(std::make_tuple(a_lens...)))
137 ShapeArray(T* a_data,
const IntVect& a_lens) noexcept
139 ShapeArray<T, D-1, IIx>(a_data, a_lens),
140 m_thisDlen((D-1 ==
SpaceDim) ? 0 : a_lens[D-1])
144 ShapeArray(
const ShapeArray& a_other) noexcept
146 ShapeArray<T, D-1, IIx>((ShapeArray<T, D-1, IIx>)a_other),
147 m_thisDlen(a_other.m_thisDlen)
151 ShapeArray& operator=(
const ShapeArray& a_other) =
default;
158 template <
typename... Is>
159 void define(T* a_data, Is... a_lens) noexcept
161 ShapeArray<T, D-1, IIx>::define(a_data, a_lens...);
162 m_thisDlen = getLen<IIx, D-1>(std::make_tuple(a_lens...));
177 void define(T* a_data,
const IntVect& a_lens) noexcept
179 ShapeArray<T, D-1, IIx>::define(a_data, a_lens);
180 m_thisDlen = (D-1 ==
SpaceDim) ? 0 : a_lens[D-1];
187 void resetData(T* a_data) noexcept
189 ShapeArray<T, 1, IIx>::resetData(a_data);
193 void clear() noexcept
195 ShapeArray<T, D-1, IIx>::clear();
203 auto operator[](
const IIx a_idx)
const noexcept
205 return ShapeArray<T, D-1, IIx>(m_thisDlen + a_idx,
207 (ShapeArray<T, D-1, IIx>)(*
this));
211 friend struct ShapeArray<T, D+1, IIx>;
219 ShapeArray(
const IIx a_idx,
const ShapeArray& a_other) noexcept
221 ShapeArray<T, D-1, IIx>((ShapeArray<T, D-1, IIx>)a_other),
222 m_thisDlen(a_idx*a_other.m_thisDlen)
231 template <
typename T,
typename IIx>
232 struct ShapeArray<T, 1, IIx>
234 ShapeArray() noexcept
238 template <
typename... Is>
239 ShapeArray(T* a_data, Is... a_lens) noexcept
241 m_thisDlen(getLen<IIx, 0>(std::make_tuple(a_lens...))),
253 ShapeArray(T* a_data,
const IntVect& a_lens) noexcept
255 m_thisDlen(a_lens[0]),
258 ShapeArray(
const ShapeArray& a_other) noexcept
260 m_thisDlen(a_other.m_thisDlen),
261 m_data(a_other.m_data)
263 ShapeArray& operator=(
const ShapeArray& a_other) =
default;
264 template <
typename... Is>
265 void define(T* a_data, Is... a_lens) noexcept
267 m_thisDlen = getLen<IIx, 0>(std::make_tuple(a_lens...));
278 void define(T* a_data,
const IntVect& a_lens) noexcept
280 m_thisDlen = a_lens[0];
283 void resetData(T* a_data) noexcept
287 void clear() noexcept
297 T& operator[](
const IIx a_idx)
const noexcept
299 return *(m_data + m_thisDlen + a_idx);
303 T* data()
const noexcept
305 return m_data + m_thisDlen;
309 friend struct ShapeArray<T, 2, IIx>;
316 ShapeArray(
const IIx a_idx,
const ShapeArray& a_other) noexcept
318 m_thisDlen(a_idx*a_other.m_thisDlen),
319 m_data(a_other.m_data)
332 template <
typename T,
typename... Is>
333 inline auto make_MD_array(T* a_data, Is... a_lens) noexcept
335 return ShapeArray<T,
sizeof...(a_lens),
int>(a_data, a_lens...);
341 #include "NamespaceFooter.H"
const int SpaceDim
Definition: SPACE.H:38
Ordered Tuples for Types T.
Definition: Tuple.H:30
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42