CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
xindex.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_xindex_cc_h__
13#define __cxz_xindex_cc_h__
14
15#include "xindex.h"
16
17namespace CNORXZ
18{
19
20 /*============+
21 | XIndex |
22 +============*/
23
24 template <class Index, typename Meta>
27
28 template <class Index, typename Meta>
30 mI(std::make_shared<Index>(i.THIS())) {}
31
32 template <class Index, typename Meta>
34 {
35 return std::make_shared<XIndex<Index,Meta>>(mI->THIS());
36 }
37
38 template <class Index, typename Meta>
40 {
41 return mI->pos();
42 }
43
44 template <class Index, typename Meta>
46 {
47 mI->THIS() = lexpos;
48 assert(mI->lex() == lexpos);
49 return *this;
50 }
51
52 template <class Index, typename Meta>
54 {
55 ++(*mI);
56 return *this;
57 }
58
59 template <class Index, typename Meta>
61 {
62 --(*mI);
63 return *this;
64 }
65
66 template <class Index, typename Meta>
68 {
69 return std::make_shared<XIndex<Index,Meta>>(*mI + n);
70 }
71
72 template <class Index, typename Meta>
74 {
75 return std::make_shared<XIndex<Index,Meta>>(*mI - n);
76 }
77
78 template <class Index, typename Meta>
80 {
81 const XIndex<Index,Meta>* ip = dynamic_cast<const XIndex<Index,Meta>*>(&i);
82 CXZ_ASSERT(ip != nullptr, "bad index type");
83 return (*mI) - (*ip->mI);
84 }
85
86 template <class Index, typename Meta>
88 {
89 (*mI) += n;
90 return *this;
91 }
92
93 template <class Index, typename Meta>
95 {
96 (*mI) -= n;
97 return *this;
98 }
99
100 template <class Index, typename Meta>
102 {
103 return mI->lex();
104 }
105
106 template <class Index, typename Meta>
108 {
109 return UPos(mI->pmax());
110 }
111
112 template <class Index, typename Meta>
114 {
115 return UPos(mI->lmax());
116 }
117
118 template <class Index, typename Meta>
120 {
121 return IndexId<0>(mI->id().id());
122 }
123
124 template <class Index, typename Meta>
126 {
127 return DType(*(*mI));
128 }
129
130 template <class Index, typename Meta>
132 {
133 return mI->dim();
134 }
135
136 template <class Index, typename Meta>
138 {
139 return mI->range();
140 }
141
142 template <class Index, typename Meta>
144 {
145 return mI->stepSize(id);
146 }
147
148 template <class Index, typename Meta>
150 {
151 return mI->prange( std::dynamic_pointer_cast<XIndex<Index,Meta>>(last)->get() );
152 }
153
154 template <class Index, typename Meta>
156 {
157 return toVec( mI->deepFormat() );
158 }
159
160 template <class Index, typename Meta>
162 {
163 return toVec( mI->deepMax() );
164 }
165
166 template <class Index, typename Meta>
168 {
169 mI->reformat(f,s);
170 return *this;
171 }
172
173 template <class Index, typename Meta>
175 {
176 return mI->stringMeta();
177 }
178
179 template <class Index, typename Meta>
181 {
182 return DType(mI->meta());
183 }
184
185 template <class Index, typename Meta>
187 {
188 mI->at(std::any_cast<const Meta&>(meta.get()));
189 return *this;
190 }
191
192 template <class Index, typename Meta>
194 {
195 return DXpr<None>(mI->ifor(xpr, std::forward<NoF>(f)));
196 }
197
198 template <class Index, typename Meta>
200 {
201 return mI->formatIsTrivial();
202 }
203
204 template <class Index, typename Meta>
206 {
207 return mI->THIS();
208 }
209
210 template <class Index, typename Meta>
211 const Index& XIndex<Index,Meta>::get() const
212 {
213 return mI->THIS();
214 }
215
216 template <class Index>
218 {
219 typedef typename Index::MetaType Meta;
220 return std::make_shared<XIndex<Index,Meta>>
221 (std::dynamic_pointer_cast<IndexInterface<Index,Meta>>(i));
222 }
223
224 template <>
226 {
227 return i;
228 }
229}
230
231#endif
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
const std::any & get() const
Definition dtype.h:69
virtual XIndexBase & at(const DType &meta)=0
virtual UPos pmax() const override final
Definition xindex.cc.h:107
virtual UPos stepSize(const IndexId< 0 > &id) const override final
Definition xindex.cc.h:143
virtual XIndexPtr operator-(Int n) const override final
Definition xindex.cc.h:73
Index & get()
Definition xindex.cc.h:205
virtual UPos lmax() const override final
Definition xindex.cc.h:113
virtual DType meta() const override final
Definition xindex.cc.h:180
virtual SizeT lex() const override final
Definition xindex.cc.h:101
virtual DType operator*() const override final
Definition xindex.cc.h:125
virtual String stringMeta() const override final
Definition xindex.cc.h:174
virtual Vector< SizeT > deepMax() const override final
Definition xindex.cc.h:161
XIndex & operator=(const XIndex &i)
virtual DXpr< None > ifor(const DXpr< None > &xpr, NoF &&f) const override final
Definition xindex.cc.h:193
virtual RangePtr prange(const XIndexPtr &last) const override final
Definition xindex.cc.h:149
virtual SizeT pos() const override final
Definition xindex.cc.h:39
virtual XIndex & reformat(const Vector< SizeT > &f, const Vector< SizeT > &s) override final
Definition xindex.cc.h:167
virtual SizeT dim() const override final
Definition xindex.cc.h:131
virtual XIndexPtr copy() const override final
Definition xindex.cc.h:33
XIndex(const XIndex &i)
virtual IndexId< 0 > id() const override final
Definition xindex.cc.h:119
virtual XIndex & operator+=(Int n) override final
Definition xindex.cc.h:87
virtual XIndexBase & at(const DType &meta) override final
Definition xindex.cc.h:186
virtual XIndex & operator--() override final
Definition xindex.cc.h:60
virtual XIndex & operator-=(Int n) override final
Definition xindex.cc.h:94
virtual RangePtr range() const override final
Definition xindex.cc.h:137
virtual bool formatIsTrivial() const override final
Definition xindex.cc.h:199
virtual Vector< SizeT > deepFormat() const override final
Definition xindex.cc.h:155
virtual XIndexPtr operator+(Int n) const override final
Definition xindex.cc.h:67
virtual XIndex & operator++() override final
Definition xindex.cc.h:53
std::string String
Definition types.h:42
uint64_t SizeT
Definition types.h:38
Sptr< RangeBase > RangePtr
Definition types.h:157
Sptr< XIndexBase > XIndexPtr
Definition types.h:216
std::vector< T, Allocator< T > > Vector
Definition types.h:310
int32_t Int
Definition types.h:36
decltype(auto) xpr(const Sptr< I > &i)
Sptr< Range > rangeCast(const RangePtr r)
XIndexPtr xindexPtr(const Sptr< Index > &i)
Definition xindex.cc.h:217
XIndexPtr xindexPtr< XIndexBase >(const Sptr< XIndexBase > &i)
Definition xindex.cc.h:225
Sptr< IndexInterface< I, MetaType > > IndexPtr
Definition types.h:164
std::shared_ptr< T > Sptr
Definition types.h:48
Vector< T > toVec(const Arr< T, N > &a)
Definition utils.h:22
XIndexBase and XIndex template declaration.