diff --git a/src/include/ranges/prange.cc.h b/src/include/ranges/prange.cc.h index 2774f0e..ea40bf4 100644 --- a/src/include/ranges/prange.cc.h +++ b/src/include/ranges/prange.cc.h @@ -14,7 +14,7 @@ namespace CNORXZ PIndex::PIndex(const RangePtr& range, SizeT pos) : IndexInterface(pos), mRangePtr(rangeCast(range)), - mOrig(mRangePtr->orig(),mRangePtr->parts()[pos]) + mOrig(std::make_shared(mRangePtr->orig(),mRangePtr->parts()[pos])) {} template @@ -208,6 +208,101 @@ namespace CNORXZ CXZ_ERROR("meta position '" << mOrig->meta() << "' not part of range"); } + /********************* + * PRangeFactory * + *********************/ + + template + PRangeFactory::PRangeFactory(const Sptr& range, const Vector& _parts) : + mRange(range), mParts(_parts) + {} + + template + void PRangeFactory::make() + { + const Vector key = { mRange->id() }; + const auto& info = typeid(PRange); + mProd = this->fromCreated(info, key); + if(mProd == nullptr) { + mProd = std::make_shared>( new PRange(mRange, mParts) ); + this->addToCreated(info, key, mProd); + } + } + + /************** + * PRange * + **************/ + + template + SizeT PRange::size() const + { + return mParts.size(); + } + + template + SizeT PRange::dim() const + { + return 1; + } + + template + String PRange::stringMeta(SizeT pos) const + { + return mRange->stringMeta( mParts[pos] ); + } + + template + const TypeInfo& PRange::type() const + { + return typeid(PRange); + } + + template + const TypeInfo& PRange::metaType() const + { + return mRange->metaType(); + } + + template + RangePtr PRange::extend(const RangePtr& r) const + { + CXZ_ERROR("implement!!!"); + return nullptr; + } + + template + RangePtr PRange::orig() const + { + return mRange; + } + + template + const Vector& PRange::parts() const + { + return mParts; + } + + template + RangePtr PRange::derive() const + { + Vector meta(this->size()); + auto i = mRange->begin(); + for(const auto& p: mParts){ + meta = *(i = p); + } + return URangeFactory( meta ).create(); + } + + + /************************ + * PRange (private) * + ************************/ + + template + PRange::PRange(const Sptr& range, const Vector& _parts) : + mRange(range), mParts(_parts) + {} + } #endif diff --git a/src/include/ranges/prange.h b/src/include/ranges/prange.h index a6e8775..0ea83ce 100644 --- a/src/include/ranges/prange.h +++ b/src/include/ranges/prange.h @@ -77,7 +77,8 @@ namespace CNORXZ PRangeFactory() = default; virtual void make() override final; - RangePtr mRef; + RangePtr mRange; + Vector mParts; }; template @@ -86,6 +87,7 @@ namespace CNORXZ public: typedef RangeBase RB; typedef PIndex IndexType; + typedef typename Range::MetaType MetaType; friend PRangeFactory;