#ifndef __cxz_urange_cc_h__ #define __cxz_urange_cc_h__ #include #include #include "urange.h" namespace CNORXZ { /***************** * UIndex * *****************/ namespace { template Sptr> rc(const RangePtr r) { if(typeid(URange) == r.type()){ return std::dynamic_pointer_cast>(r) } else { return rangeCast>(r); } } } template UIndex::UIndex(const RangePtr& range) : IndexInterface,MetaType>(0), mRange(rc(range)), mMetaPtr(&get(0)) {} template UIndex& UIndex::operator=(size_t pos) { IB::mPos = pos; return *this; } template UIndex& UIndex::operator++() { ++IB::mPos; return *this; } template UIndex& UIndex::operator--() { --IB::mPos; return *this; } template int UIndex::pp(std::intptr_t idxPtrNum) { ++(*this); return 1; } template int UIndex::mm(std::intptr_t idxPtrNum) { --(*this); return 1; } template String UIndex::stringMeta() const { return toString(this->meta()); } template MetaType& UIndex::meta() const { return mSpace[IB::mPos]; } template UIndex& UIndex::at(const MetaType& metaPos) { (*this) = mRangePtr->getMeta(metaPos); return *this; } template size_t UIndex::dim() // = 1 { return 1; } template Sptr> UIndex::range() { return mRangePtr; } template size_t UIndex::getStepSize(size_t n) { return 1; } template template auto UIndex::ifor(size_t step, Expr ex) const -> For,Expr> { return For,Expr>(this, step, ex); } template template auto UIndex::iforh(size_t step, Expr ex) const -> For,Expr,ForType::HIDDEN> { return For,Expr,ForType::HIDDEN>(this, step, ex); } template template auto UIndex::pifor(size_t step, Expr ex) const -> PFor,Expr> { return PFor,Expr>(this, step, ex); } /******************** * SingleRange * ********************/ template URangeFactory::URangeFactory(const Vector& space) : mSpace(space) {} template URangeFactory::URangeFactory(Vector&& space) : mSpace(space) {} template URangeFactory::URangeFactory(const Vector& space, const RangePtr& ref) : mSpace(space), mRef(ref) {} template URangeFactory::URangeFactory(Vector&& space, const RangePtr& ref) : mSpace(space), mRef(ref) {} template void URangeFactory::make() { if(mRef != nullptr) { mProd = this->fromCreated[typeid(oType)][mRef->id()]; } if(mProd == nullptr){ RangePtr key = mProd = std::shared_ptr ( new URange( std::move(mSpace) ) ); if(mRef != nullptr) { key = mRef->id(); } this->addToCreated(typeid(oType), { key }, mProd); } } /******************** * SingleRange * ********************/ template URange::URange(const Vector& space) : RangeInterface>(), mSpace(space) { std::sort(mSpace.begin(), mSpace.end(), std::less()); auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end()); CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl); } template URange::URange(Vector&& space) : RangeInterface>(), mSpace(space) { std::sort(mSpace.begin(), mSpace.end(), std::less()); auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end()); CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl); } template const MetaType& URange::get(size_t pos) const { return mSpace[pos]; } template SizeT URange::getMeta(const MetaType& meta) const { auto b = mSpace.begin(); auto e = mSpace.end(); return std::lower_bound(b, e, meta, std::less()) - b; } template SizeT URange::size() const { return mSpace.size(); } template SizeT URange::dim() const { return 1; } template String URange::stringMeta(SizeT pos) const { return toString(this->get(pos)); } template typename URange::IndexType URange::begin() const { UIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = 0; return i; } template typename URange::IndexType URange::end() const { UIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = this->size(); return i; } /******************* * Range Casts * *******************/ template Sptr> rangeCast>(const RangePtr& r) { CXZ_ERROR("to be implemented..."); return nullptr; } } #endif