CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
pos_type.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_pos_type_h__
13#define __cxz_pos_type_h__
14
15#include "base/base.h"
16
17namespace CNORXZ
18{
19
20 template <SizeT N>
21 class SPos
22 {
23 public:
24 constexpr SPos() = default;
25 constexpr SPos(const SPos& a) = default;
26 constexpr SPos(SPos&& a) = default;
27
28 constexpr SizeT size() const;
29 constexpr SizeT val() const;
30
31 template <SizeT N1>
32 constexpr auto operator+(const SPos<N1>& a) const;
33 template <SizeT N1>
34 constexpr auto operator-(const SPos<N1>& a) const;
35 template <SizeT N1>
36 constexpr auto operator*(const SPos<N1>& a) const;
37 template <SizeT N1>
38 constexpr auto operator()(const SPos<N1>& a) const;
39
40 constexpr auto operator+(const UPos& a) const;
41 constexpr auto operator*(const UPos& a) const;
42 constexpr auto operator()(const UPos& a) const;
43
44 template <class PosT>
45 constexpr decltype(auto) extend(const PosT& a) const;
46
47 template <class PosT>
48 constexpr decltype(auto) operator<<(const PosT& a) const;
49
50 explicit constexpr operator UPos() const;
51 explicit constexpr operator SizeT() const;
52 };
53
54 class UPos
55 {
56 private:
57 SizeT mExt = 0;
58 public:
60
61 constexpr UPos(SizeT ext);
62
63 constexpr SizeT size() const;
64 constexpr const SizeT& val() const;
65
66 template <class PosT>
67 constexpr UPos operator+(const PosT& a) const;
68
69 template <class PosT>
70 constexpr UPos operator-(const PosT& a) const;
71
72 constexpr SPos<0> operator*(const SPos<0>& a) const;
73
74 template <class PosT>
75 constexpr UPos operator*(const PosT& a) const;
76
77 constexpr SPos<0> operator()(const SPos<0>& a) const;
78
79 template <class PosT>
80 constexpr UPos operator()(const PosT& a) const;
81
82 template <class PosT>
83 constexpr decltype(auto) extend(const PosT& a) const;
84
85 template <class PosT>
86 constexpr decltype(auto) operator<<(const PosT& a) const;
87
88 explicit constexpr operator SizeT() const;
89 };
90
91 class FPos
92 {
93 private:
94 SizeT mExt = 0;
95 const SizeT* mMap = nullptr;
96
97 public:
99
100 inline FPos(SizeT ext, const SizeT* map);
101
102 constexpr SizeT size() const;
103 constexpr const SizeT& val() const;
104
105 template <class PosT1>
106 constexpr UPos operator+(const PosT1& a) const;
107
108 template <class PosT1>
109 constexpr FPos operator*(const PosT1& a) const;
110
111 template <class PosT>
112 constexpr UPos operator()(const PosT& a) const;
113
114 template <class PosT>
115 constexpr decltype(auto) extend(const PosT& a) const;
116
117 template <class PosT>
118 constexpr decltype(auto) operator<<(const PosT& a) const;
119
120 explicit constexpr operator SizeT() const;
121 };
122
123 template <SizeT N, SizeT... Ms>
124 class SFPos
125 {
126 private:
127 static Arr<SizeT,sizeof...(Ms)> sMs;
128 public:
129 constexpr SFPos() = default;
130
131 constexpr SizeT size() const;
132 constexpr SizeT val() const;
133
134 template <SizeT N1>
135 constexpr auto operator+(const SPos<N1>& a) const;
136 template <SizeT N1>
137 constexpr auto operator*(const SPos<N1>& a) const;
138 template <SizeT N1>
139 constexpr auto operator()(const SPos<N1>& a) const;
140
141 constexpr auto operator+(const UPos& a) const;
142 constexpr auto operator*(const UPos& a) const;
143 constexpr auto operator()(const UPos& a) const;
144
145 template <class PosT>
146 constexpr decltype(auto) extend(const PosT& a) const;
147
148 template <class PosT>
149 constexpr decltype(auto) operator<<(const PosT& a) const;
150
151 explicit constexpr operator FPos() const;
152
153 explicit constexpr operator SizeT() const;
154 };
155
156 template <class BPosT, class NPosT>
157 class MPos : public BPosT // BPos should be a SCALAR PosT (NO MPos!)
158 {
159 protected:
161 public:
162 constexpr MPos();
163
164 constexpr MPos(const BPosT& b, const NPosT& n);
165
166 template <typename... Args>
167 constexpr MPos(Args&&... args, const NPosT& next);
168
169 template <typename... Args>
170 constexpr MPos(Args&&... args, NPosT&& next);
171
172 constexpr SizeT size() const;
173 constexpr const NPosT& next() const;
174
175 template <class PosT>
176 constexpr auto operator+(const PosT& a) const;
177
178 template <class PosT>
179 constexpr auto operator*(const PosT& a) const;
180
181 // same as operator*, except for FPos/SFPos, where map is executed
182 template <class PosT>
183 constexpr auto operator()(const PosT& a) const;
184
185 template <class PosT>
186 constexpr decltype(auto) extend(const PosT& a) const;
187
188 template <class PosT>
189 constexpr decltype(auto) operator<<(const PosT& a) const;
190 };
191
192 // treat as scalar pos!
193 class DPos : public ObjHandle<VPosBase>
194 {
195 public:
197
198 inline DPos(Uptr<VPosBase>&& a);
199 inline DPos(const DPosRef& a);
200
201 template <class PosT>
202 inline explicit DPos(const PosT& a);
203
204 template <class PosT>
205 inline explicit DPos(PosT&& a);
206
207 inline const VPosBase* get() const;
208 inline const VPosBase* vpos() const;
209 inline SizeT size() const;
210 inline SizeT val() const;
211 inline DPosRef sub() const;
212 //inline DPosRef next() const;
213
214 template <class PosT>
215 inline DPos operator+(const PosT& a) const;
216
217 template <class PosT>
218 inline DPos operator*(const PosT& a) const;
219
220 // same as operator*, except for FPos/SFPos, where map is executed
221 template <class PosT>
222 inline DPos operator()(const PosT& a) const;
223
224 template <class PosT>
225 inline decltype(auto) extend(const PosT& a) const;
226
227 template <class PosT>
228 inline decltype(auto) operator<<(const PosT& a) const;
229
230 explicit inline operator SizeT() const;
231 };
232
234 {
235 private:
236 const VPosBase* mP = nullptr;
237
238 public:
240
241 explicit DPosRef(const VPosBase* p);
242
243 inline const VPosBase* get() const;
244 inline const VPosBase* vpos() const;
245 inline SizeT size() const;
246 inline SizeT val() const;
247 inline DPosRef sub() const;
248 //inline DPosRef next() const;
249
250 template <class PosT>
251 inline DPos operator+(const PosT& a) const;
252
253 template <class PosT>
254 inline DPos operator*(const PosT& a) const;
255
256 // same as operator*, except for FPos/SFPos, where map is executed
257 template <class PosT>
258 inline DPos operator()(const PosT& a) const;
259
260 template <class PosT>
261 inline decltype(auto) extend(const PosT& a) const;
262
263 template <class PosT>
264 inline decltype(auto) operator<<(const PosT& a) const;
265
266 explicit inline operator SizeT() const;
267 };
268
269 // for common call of extension vector elements
270 // BPos = base pos type
271 // OPos = offset pos type (i.e. step/ext * for index of lowest for layer)
272 // currently EPos must be used only at the lowest for layer
273 template <class BPosT, class... OPosTs>
274 class EPos : public BPosT
275 {
276 private:
277 Tuple<OPosTs...> mP;
278
279 template <SizeT... Is>
280 constexpr decltype(auto) ival(std::index_sequence<Is...> is) const;
281
282 template <SizeT... Is>
283 constexpr decltype(auto) inext(std::index_sequence<Is...> is) const;
284
285 public:
287
288 constexpr EPos(const BPosT& b, const OPosTs&... os);
289 constexpr EPos(BPosT&& b, OPosTs&&... os);
290
291 template <class PosT>
292 constexpr decltype(auto) operator+(const PosT& a) const;
293
294 template <class PosT>
295 constexpr decltype(auto) operator*(const PosT& a) const;
296
297 template <class PosT>
298 constexpr decltype(auto) operator()(const PosT& a) const;
299
300 constexpr decltype(auto) val() const;
301 constexpr decltype(auto) next() const;
302
303 constexpr decltype(auto) scal() const;
304
305 template <SizeT I>
306 constexpr decltype(auto) get() const;
307 };
308
309 /*===============================+
310 | Traits and Helper-Classes |
311 +===============================*/
312
313 template <class T>
315
316 template <class T>
318
319 template <class T>
321
322 template <class T>
324
325 template <class PosT>
327 {
328 static constexpr SizeT value = is_pos_type<PosT>::value ? 1 : 0;
329 };
330
331 template <class PosT>
333 {
334 static constexpr SizeT value = 1;
335 };
336
337 template <class OPosT1, class OPosT2, class... OPosTs>
339 {
340 private:
341 static constexpr bool eval();
342
343 public:
344 static constexpr bool value = eval();
345 };
346
347 template <class OPosT1, class... OPosTs>
349 {
350 static constexpr bool value = sizeof...(OPosTs) == 0 ? is_pos_type<OPosT1>::value : pos_types_consecutive_2<OPosT1,OPosTs...>::value;
351 };
352
353 template <class OPosT1, class... OPosTs>
355 {
356 private:
357 static constexpr bool eval();
358
359 public:
360 static constexpr bool value = eval();
361 };
362
363 template <class PosT> struct pos_type_is_consecutive { CXZ_CVAL_TRUE; };
364
365 template <class BPosT, class OPosT, SizeT N>
366 struct MkEPos
367 {
368 static decltype(auto) mk(const BPosT& a, const OPosT& b);
369 };
370
371 template <class BPosT, class NPosT, class OPosT, class ONPosT, SizeT N>
372 struct MkEPos<MPos<BPosT,NPosT>,MPos<OPosT,ONPosT>,N>
373 {
374 static decltype(auto) mk(const MPos<BPosT,NPosT>& a, const MPos<OPosT,ONPosT>& b);
375 };
376
377 template <SizeT N, class BPosT, class OPosT>
378 decltype(auto) mkEPos(const BPosT& a, const OPosT& b);
379
380 template <class BPosT, class OPosT, SizeT... Is>
381 decltype(auto) mkiEPos(const BPosT& a, const OPosT& b, std::index_sequence<Is...> is);
382
383 /*================================================+
384 | Traits and Helper-Classes: Specializations |
385 +================================================*/
386
387 template <SizeT N> struct is_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
388 template <SizeT N> struct is_scalar_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
389 template <SizeT N> struct is_static_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
390
391 template <> struct is_pos_type<UPos> { CXZ_CVAL_TRUE; };
392 template <> struct is_scalar_pos_type<UPos> { CXZ_CVAL_TRUE; };
393
394 template <> struct is_pos_type<FPos> { CXZ_CVAL_TRUE; };
395 template <> struct is_scalar_pos_type<FPos> { CXZ_CVAL_TRUE; };
396
397 template <SizeT N, SizeT... Ms> struct is_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
398 template <SizeT N, SizeT... Ms> struct is_scalar_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
399 template <SizeT N, SizeT... Ms> struct is_static_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
400
401 template <class BPosT, class NPosT> struct is_pos_type<MPos<BPosT,NPosT>> { CXZ_CVAL_TRUE; };
402
403 template <> struct is_pos_type<DPos> { CXZ_CVAL_TRUE; };
404 template <> struct is_pos_type<DPosRef> { CXZ_CVAL_TRUE; };
405 template <> struct is_scalar_pos_type<DPos> { CXZ_CVAL_TRUE; };
406 template <> struct is_scalar_pos_type<DPosRef> { CXZ_CVAL_TRUE; };
407
408 template <class BPosT, class... OPosTs> struct is_pos_type<EPos<BPosT,OPosTs...>> { CXZ_CVAL_TRUE; };
409 template <class BPosT, class... OPosTs> struct is_scalar_pos_type<EPos<BPosT,OPosTs...>>
410 { static constexpr bool value = is_scalar_pos_type<BPosT>::value; };
411 template <class BPosT, class... OPosTs> struct is_static_pos_type<EPos<BPosT,OPosTs...>>
413 template <class BPosT, class... OPosTs> struct is_epos_type<EPos<BPosT,OPosTs...>> { CXZ_CVAL_TRUE; };
414
415 template <class BPosT, class NPosT> struct is_epos_type<MPos<BPosT,NPosT>> { static constexpr bool value = is_epos_type<BPosT>::value or is_epos_type<NPosT>::value; };
416
417 template <class BPosT, class NPosT>
419 {
421 };
422
423 template <class BPosT, class... OPosTs>
424 struct epos_size<EPos<BPosT,OPosTs...>>
425 {
426 static constexpr SizeT value = sizeof...(OPosTs);
427 };
428
429 template <class BPosT, class NPosT>
430 struct epos_size<MPos<BPosT,NPosT>>
431 {
433 };
434
435 template <class BPosT, class... OPosTs>
437 {
438 static constexpr bool value = pos_types_consecutive<OPosTs...>::value;
439 };
440
441 template <class BPosT, class NPosT>
443 {
444 static constexpr bool value = pos_type_is_consecutive<BPosT>::value;
445 };
446
447} // end namespace CNORXZ
448
449
450#endif
basic headers
const VPosBase * vpos() const
const VPosBase * get() const
SizeT val() const
DPosRef sub() const
DPos operator()(const PosT &a) const
decltype(auto) extend(const PosT &a) const
SizeT size() const
DEFAULT_MEMBERS(DPosRef)
DPos operator+(const PosT &a) const
DPos operator*(const PosT &a) const
DPosRef(const VPosBase *p)
DPos(Uptr< VPosBase > &&a)
DEFAULT_MEMBERS(DPos)
SizeT val() const
DPos operator+(const PosT &a) const
SizeT size() const
const VPosBase * get() const
DPosRef sub() const
DPos operator()(const PosT &a) const
const VPosBase * vpos() const
decltype(auto) extend(const PosT &a) const
constexpr decltype(auto) scal() const
constexpr decltype(auto) val() const
constexpr decltype(auto) next() const
constexpr decltype(auto) get() const
constexpr EPos(const BPosT &b, const OPosTs &... os)
DEFAULT_MEMBERS(EPos)
FPos(SizeT ext, const SizeT *map)
constexpr FPos operator*(const PosT1 &a) const
DEFAULT_MEMBERS(FPos)
constexpr const SizeT & val() const
constexpr UPos operator()(const PosT &a) const
constexpr UPos operator+(const PosT1 &a) const
constexpr decltype(auto) extend(const PosT &a) const
constexpr SizeT size() const
constexpr decltype(auto) extend(const PosT &a) const
constexpr const NPosT & next() const
constexpr auto operator()(const PosT &a) const
constexpr auto operator+(const PosT &a) const
constexpr SizeT size() const
NPosT mNext
Definition pos_type.h:160
constexpr MPos()
constexpr auto operator*(const PosT &a) const
constexpr SFPos()=default
constexpr decltype(auto) extend(const PosT &a) const
constexpr SizeT val() const
constexpr auto operator*(const SPos< N1 > &a) const
constexpr SizeT size() const
constexpr auto operator+(const SPos< N1 > &a) const
constexpr auto operator()(const SPos< N1 > &a) const
constexpr auto operator*(const SPos< N1 > &a) const
Definition pos_type.cc.h:53
constexpr SizeT val() const
Definition pos_type.cc.h:32
constexpr SizeT size() const
Definition pos_type.cc.h:26
constexpr auto operator+(const SPos< N1 > &a) const
Definition pos_type.cc.h:39
constexpr auto operator-(const SPos< N1 > &a) const
Definition pos_type.cc.h:46
constexpr SPos(SPos &&a)=default
constexpr SPos()=default
constexpr auto operator()(const SPos< N1 > &a) const
Definition pos_type.cc.h:60
constexpr SPos(const SPos &a)=default
constexpr decltype(auto) extend(const PosT &a) const
constexpr UPos(SizeT ext)
constexpr UPos operator+(const PosT &a) const
constexpr SPos< 0 > operator()(const SPos< 0 > &a) const
DEFAULT_MEMBERS(UPos)
constexpr SPos< 0 > operator*(const SPos< 0 > &a) const
constexpr SizeT size() const
constexpr const SizeT & val() const
constexpr decltype(auto) extend(const PosT &a) const
constexpr UPos operator-(const PosT &a) const
decltype(auto) mkiEPos(const BPosT &a, const OPosT &b, std::index_sequence< Is... > is)
decltype(auto) mkEPos(const BPosT &a, const OPosT &b)
uint64_t SizeT
Definition types.h:38
std::unique_ptr< T > Uptr
Definition types.h:54
Sptr< Range > rangeCast(const RangePtr r)
std::tuple< T... > Tuple
Definition types.h:60
std::array< T, N > Arr
Definition types.h:45
static decltype(auto) mk(const BPosT &a, const OPosT &b)
static constexpr SizeT value
Definition pos_type.h:334
static constexpr bool value
Definition pos_type.h:360
static constexpr bool value
Definition pos_type.h:344
static constexpr bool value
Definition pos_type.h:350
static constexpr SizeT value
Definition pos_type.h:328