12#ifndef __cxz_range_cc_h__
13#define __cxz_range_cc_h__
24 template <
typename MetaT, SizeT S>
28 mMetaPtr(&mRangePtr->get(0))
30 CXZ_ASSERT(mRangePtr->size() ==
S,
"got range of size " << mRangePtr->size()
31 <<
", expected " <<
S);
34 template <
typename MetaT, SizeT S>
41 template <
typename MetaT, SizeT S>
48 template <
typename MetaT, SizeT S>
55 template <
typename MetaT, SizeT S>
58 return SIndex(mRangePtr, IB::mPos +
n);
61 template <
typename MetaT, SizeT S>
64 return SIndex(mRangePtr, IB::mPos -
n);
67 template <
typename MetaT, SizeT S>
70 return lex() -
i.
lex();
73 template <
typename MetaT, SizeT S>
80 template <
typename MetaT, SizeT S>
87 template <
typename MetaT, SizeT S>
93 template <
typename MetaT, SizeT S>
99 template <
typename MetaT, SizeT S>
105 template <
typename MetaT, SizeT S>
111 template <
typename MetaT, SizeT S>
114 return mMetaPtr[IB::mPos];
117 template <
typename MetaT, SizeT S>
123 template <
typename MetaT, SizeT S>
129 template <
typename MetaT, SizeT S>
133 return UPos(
id == this->
id() ? 1 : 0);
136 template <
typename MetaT, SizeT S>
142 template <
typename MetaT, SizeT S>
145 return mMetaPtr[IB::mPos];
148 template <
typename MetaT, SizeT S>
151 (*this) = mRangePtr->getMeta(
metaPos);
155 template <
typename MetaT, SizeT S>
161 template <
typename MetaT, SizeT S>
164 CXZ_ASSERT(
last > *
this,
"got last index position smaller than begin index position");
167 for(
auto i = *
this;
i !=
last+1; ++
i){
173 template <
typename MetaT, SizeT S>
179 template <
typename MetaT, SizeT S>
185 template <
typename MetaT, SizeT S>
188 CXZ_ASSERT(
f[0]*
s[0] == lmax().val(),
"got wrong extension: " <<
f[0]*
s[0]
189 <<
" vs " << lmax().val());
195 template <
typename MetaT, SizeT S>
196 template <
class Xpr,
class F>
202 template <
typename MetaT, SizeT S>
208 template <
typename MetaType, SizeT S,
class I1>
219 template <
typename MetaType, SizeT S>
220 SRangeFactory<MetaType,S>::SRangeFactory(
const Arr<MetaType,S>& space) :
223 template <
typename MetaType, SizeT S>
224 SRangeFactory<MetaType,S>::SRangeFactory(Arr<MetaType,S>&& space) :
225 mSpace(std::forward<
Arr<MetaType,S>>(space)) {}
227 template <
typename MetaType, SizeT S>
228 SRangeFactory<MetaType,S>::SRangeFactory(
const Arr<MetaType,S>& space,
const RangePtr& ref) :
229 mSpace(space), mRef(ref) {}
231 template <
typename MetaType, SizeT S>
232 SRangeFactory<MetaType,S>::SRangeFactory(Arr<MetaType,S>&& space,
const RangePtr& ref) :
233 mSpace(std::forward<
Arr<MetaType,S>>(space)), mRef(ref) {}
235 template <
typename MetaType, SizeT S>
236 void SRangeFactory<MetaType,S>::make()
238 const auto& info =
typeid(SRange<MetaType,S>);
239 if(mRef !=
nullptr) {
240 mProd = this->fromCreated(info, {mRef->id()});
242 if(mProd ==
nullptr){
243 RangePtr key = mProd = std::shared_ptr<SRange<MetaType,S>>
244 (
new SRange<MetaType,S>( std::move(mSpace) ) );
245 if(mRef !=
nullptr) { key = mRef; }
246 this->addToCreated(info, { key->id() }, mProd);
254 template <
typename MetaType, SizeT S>
255 SRange<MetaType,S>::SRange(
const Arr<MetaType,S>& space) :
256 RangeInterface<SRange<MetaType,S>>(),
259 std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
260 auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
264 template <
typename MetaType, SizeT S>
265 SRange<MetaType,S>::SRange(Arr<MetaType,S>&& space) :
266 RangeInterface<SRange<MetaType,S>>(),
267 mSpace(std::forward<
Arr<MetaType,S>>(space))
269 std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
270 auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
274 template <
typename MetaType, SizeT S>
280 template <
typename MetaType, SizeT S>
286 template <
typename MetaType, SizeT S>
292 template <
typename MetaType, SizeT S>
298 template <
typename MetaType, SizeT S>
304 template <
typename MetaType, SizeT S>
308 auto rx = rangeCast<URange<MetaType>>(r);
310 space.insert(space.end(), rx->begin(), rx->end());
314 template <
typename MetaType, SizeT S>
320 template <
typename MetaType, SizeT S>
323 return mSpace.data();
326 template <
typename MetaType, SizeT S>
329 auto b = mSpace.
begin();
330 auto e = mSpace.end();
331 return std::lower_bound(b, e, metaPos, std::less<MetaType>()) - b;
334 template <
typename MetaType, SizeT S>
344 template <
typename MetaType, SizeT S>
345 Sptr<SRange<MetaType,S>> RangeCast<SRange<MetaType,S>>::func(
const RangePtr& r)
347 Sptr<URange<MetaType>> tmp;
348 if(r->type() !=
typeid(URange<MetaType>)){
349 tmp = rangeCast<URange<MetaType>>(r);
352 tmp = std::dynamic_pointer_cast<URange<MetaType>>(r);
354 CXZ_ASSERT(tmp->size() == S,
"cannot cast range of size " << tmp->size()
355 <<
" into static range of size " << S);
356 Arr<MetaType,S> space;
357 std::copy(tmp->begin(), tmp->end(), space.begin());
358 return std::dynamic_pointer_cast<SRange<MetaType,S>>
359 ( SRangeFactory<MetaType,S>(std::move(space)).create() );
#define CXZ_ASSERT(statement, errmsg)
decltype(auto) begin() const
SIndex operator-(Int n) const
SIndex & operator=(SizeT lexpos)
String stringMeta() const
bool formatIsTrivial() const
RangePtr prange(const SIndex< MetaType, S > &last) const
UPos stepSize(const IndexId< I > &id) const
SIndex & operator+=(Int n)
SIndex & reformat(const Vector< SizeT > &f, const Vector< SizeT > &s)
Sptr< RangeType > range() const
SIndex operator+(Int n) const
const MetaT & operator*() const
SIndex & operator-=(Int n)
SIndex(const RangePtr &range, SizeT pos=0)
const MetaT & meta() const
SIndex & at(const MetaT &metaPos)
constexpr decltype(auto) coproot(const CArrayBase< T > &a, const Sptr< IndexT > &ind)
Sptr< RangeBase > RangePtr
std::vector< T, Allocator< T > > Vector
decltype(auto) xpr(const Sptr< I > &i)
Sptr< Range > rangeCast(const RangePtr r)
decltype(auto) iptrMul(const Sptr< I1 > &a, const Sptr< I2 > &b)
bool formatIsTrivial(const Vector< SizeT > &f, const Vector< SizeT > &s)
String toString(const T &a)
RangePtr prange(const Sptr< RangeT > &range, const Vector< SizeT > &parts)
std::shared_ptr< T > Sptr
PRange, PRangeFactory and PIndex declaration.
SRange, SRangeFactory and SIndex declaration.