implement missing prange member functions

This commit is contained in:
Christian Zimmermann 2023-10-21 19:23:38 +02:00
parent 301967288f
commit cf0e7c5856
5 changed files with 50 additions and 33 deletions

View file

@ -482,17 +482,14 @@ namespace CNORXZ
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
RangePtr GMIndex<FormatT,Indices...>::prange(const MIndex<Indices...>& end) const RangePtr GMIndex<FormatT,Indices...>::prange(const MIndex<Indices...>& end) const
{ {
CXZ_ERROR("IMPLEMENT!!!"); return iter<0,NI>
return nullptr;
/*
return ifor<0,NI>
( [&](auto i) { ( [&](auto i) {
typedef typename std::remove_reference<decltype(mIPack[i])>::type::RangeType RangeT; typedef typename std::remove_reference<decltype(*mIPack[i])>::type::RangeType RangeT;
return std::dynamic_pointer_cast<RangeT>( mIPack[i]->prange( *end.pack()[i] ) ); return std::dynamic_pointer_cast<RangeT>( mIPack[i]->prange( *end.pack()[i] ) );
}, },
[](const auto&... e) { return mrange(e...); } [](const auto&... e) { return mrange(e...); }
); );
*/
} }
template <class FormatT, class... Indices> template <class FormatT, class... Indices>

View file

@ -126,8 +126,15 @@ namespace CNORXZ
template <class IndexT> template <class IndexT>
RangePtr PIndex<IndexT>::prange(const PIndex<IndexT>& end) const RangePtr PIndex<IndexT>::prange(const PIndex<IndexT>& end) const
{ {
CXZ_ERROR("IMPLEMENT!!!"); CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
return nullptr; auto oi = *orig();
auto oend = *end.orig();
const SizeT beginPos = oi.lex();
Vector<SizeT> parts(oend.lex()-beginPos);
for(auto i = oi; i != oend; ++i){
parts[i.lex()-beginPos] = i.lex();
}
return CNORXZ::prange(mRangePtr->orig(), parts);
} }
template <class IndexT> template <class IndexT>
@ -206,6 +213,12 @@ namespace CNORXZ
return *this; return *this;
} }
template <class IndexT>
const Sptr<IndexT>& PIndex<IndexT>::orig() const
{
return mOrig;
}
/************************ /************************
* PIndex (private) * * PIndex (private) *
************************/ ************************/
@ -302,7 +315,7 @@ namespace CNORXZ
} }
template <class RangeT> template <class RangeT>
RangePtr PRange<RangeT>::orig() const Sptr<RangeT> PRange<RangeT>::orig() const
{ {
return mRange; return mRange;
} }

View file

@ -104,7 +104,7 @@ namespace CNORXZ
virtual const TypeInfo& metaType() const override final; virtual const TypeInfo& metaType() const override final;
virtual RangePtr extend(const RangePtr& r) const override final; virtual RangePtr extend(const RangePtr& r) const override final;
RangePtr orig() const; Sptr<RangeT> orig() const;
const Vector<SizeT>& parts() const; const Vector<SizeT>& parts() const;
RangePtr derive() const; RangePtr derive() const;

View file

@ -3,6 +3,7 @@
#define __cxz_range_cc_h__ #define __cxz_range_cc_h__
#include "srange.h" #include "srange.h"
#include "prange.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -144,8 +145,13 @@ namespace CNORXZ
template <typename MetaT, SizeT S> template <typename MetaT, SizeT S>
RangePtr SIndex<MetaT,S>::prange(const SIndex<MetaType,S>& end) const RangePtr SIndex<MetaT,S>::prange(const SIndex<MetaType,S>& end) const
{ {
CXZ_ERROR("IMPLEMENT!!!"); CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
return nullptr; const SizeT beginPos = lex();
Vector<SizeT> parts(end.lex()-beginPos);
for(auto i = *this; i != end; ++i){
parts[i.lex()-beginPos] = i.lex();
}
return CNORXZ::prange(mRangePtr, parts);
} }
template <typename MetaT, SizeT S> template <typename MetaT, SizeT S>

View file

@ -65,34 +65,35 @@ namespace CNORXZ
const MetaT* mMetaPtr; const MetaT* mMetaPtr;
}; };
template <typename MetaType, SizeT S, class I1> template <typename MetaT, SizeT S, class I1>
decltype(auto) operator*(const Sptr<SIndex<MetaType,S>>& a, const Sptr<I1>& b); decltype(auto) operator*(const Sptr<SIndex<MetaT,S>>& a, const Sptr<I1>& b);
template <typename MetaType, SizeT S> template <typename MetaT, SizeT S>
class SRangeFactory : public RangeFactoryBase class SRangeFactory : public RangeFactoryBase
{ {
public: public:
SRangeFactory(const Arr<MetaType,S>& space); SRangeFactory(const Arr<MetaT,S>& space);
SRangeFactory(Arr<MetaType,S>&& space); SRangeFactory(Arr<MetaT,S>&& space);
SRangeFactory(const Arr<MetaType,S>& space, const RangePtr& ref); SRangeFactory(const Arr<MetaT,S>& space, const RangePtr& ref);
SRangeFactory(Arr<MetaType,S>&& space, const RangePtr& ref); SRangeFactory(Arr<MetaT,S>&& space, const RangePtr& ref);
private: private:
SRangeFactory() = default; SRangeFactory() = default;
virtual void make() override final; virtual void make() override final;
Arr<MetaType,S> mSpace; Arr<MetaT,S> mSpace;
RangePtr mRef; RangePtr mRef;
}; };
template <typename MetaType, SizeT S> template <typename MetaT, SizeT S>
class SRange : public RangeInterface<SRange<MetaType,S>> class SRange : public RangeInterface<SRange<MetaT,S>>
{ {
public: public:
typedef RangeBase RB; typedef RangeBase RB;
typedef SIndex<MetaType,S> IndexType; typedef SIndex<MetaT,S> IndexType;
typedef MetaT MetaType;
friend SRangeFactory<MetaType,S>; friend SRangeFactory<MetaT,S>;
virtual SizeT size() const override final; virtual SizeT size() const override final;
virtual SizeT dim() const override final; virtual SizeT dim() const override final;
@ -101,28 +102,28 @@ namespace CNORXZ
virtual const TypeInfo& metaType() const override final; virtual const TypeInfo& metaType() const override final;
virtual RangePtr extend(const RangePtr& r) const override final; virtual RangePtr extend(const RangePtr& r) const override final;
const MetaType& get(SizeT pos) const; const MetaT& get(SizeT pos) const;
const MetaType* get() const; const MetaT* get() const;
SizeT getMeta(const MetaType& metaPos) const; SizeT getMeta(const MetaT& metaPos) const;
private: private:
SRange() = default; SRange() = default;
SRange(const SRange& in) = delete; SRange(const SRange& in) = delete;
SRange(const Arr<MetaType,S>& space); SRange(const Arr<MetaT,S>& space);
SRange(Arr<MetaType,S>&& space); SRange(Arr<MetaT,S>&& space);
Arr<MetaType,S> mSpace; Arr<MetaT,S> mSpace;
virtual Vector<Uuid> key() const override final; virtual Vector<Uuid> key() const override final;
SERIALIZATION_FUNCTIONS_NOPUB; SERIALIZATION_FUNCTIONS_NOPUB;
}; };
template <typename MetaType, SizeT S> template <typename MetaT, SizeT S>
struct RangeCast<SRange<MetaType,S>> struct RangeCast<SRange<MetaT,S>>
{ {
static Sptr<SRange<MetaType,S>> func(const RangePtr& r); static Sptr<SRange<MetaT,S>> func(const RangePtr& r);
}; };
} }