From 62a9df39d365fea6cfec68bf640e4cd57e8f7191 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 13 Nov 2022 02:23:33 +0100 Subject: [PATCH] add UR_Test + remove operator-> for index classes where it conflicts with c++ syntax --- src/include/ranges/crange.h | 4 --- src/include/ranges/dindex.h | 4 --- src/include/ranges/index_base.h | 4 --- src/include/ranges/mrange.cc.h | 6 ----- src/include/ranges/mrange.h | 1 - src/include/ranges/prange.h | 3 --- src/include/ranges/urange.cc.h | 30 +++++++-------------- src/include/ranges/urange.h | 5 ++-- src/include/ranges/xindex.cc.h | 20 -------------- src/include/ranges/xindex.h | 8 ------ src/include/ranges/yrange.h | 4 --- src/lib/ranges/crange.cc | 17 ------------ src/lib/ranges/dindex.cc | 19 ------------- src/lib/ranges/yrange.cc | 20 -------------- src/tests/range_unit_test.cc | 48 ++++++++++++++++++++++++++++++++- 15 files changed, 58 insertions(+), 135 deletions(-) diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 505b87c..354df24 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -30,11 +30,7 @@ namespace CNORXZ IndexId<0> id() const; SizeT operator*() const; - SizeT operator->() const; - Int pp(PtrId idxPtrNum); - Int mm(PtrId idxPtrNum); - SizeT dim() const; // = 1 Sptr range() const; UPos stepSize(const IndexId<0>& id) const; diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index 5e7dcbd..e2a2504 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -36,10 +36,6 @@ namespace CNORXZ IndexId<0> id() const; DType operator*() const; - DType operator->() const; - - Int pp(PtrId idxPtrNum); - Int mm(PtrId idxPtrNum); SizeT dim() const; RangePtr range() const; diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index a09c4f0..6d77c6a 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -41,11 +41,7 @@ namespace CNORXZ bool operator<=(const IndexInterface& in) const; bool operator>=(const IndexInterface& in) const; decltype(auto) operator*() const { return THIS().operator*(); } - decltype(auto) operator->() const { return THIS().operator->(); } - Int pp(PtrId idxPtrNum) { return THIS().pp(idxPtrNum); } - Int mm(PtrId idxPtrNum) { return THIS().mm(idxPtrNum); } - SizeT dim() const { return THIS().dim(); } decltype(auto) range() const { return THIS().range(); } diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index cc8720e..6c8442a 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -198,12 +198,6 @@ namespace CNORXZ return meta(); } - template - MetaType MIndex::operator->() const - { - return meta(); - } - template SizeT MIndex::dim() const { diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index e8ec9a3..1b0437a 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -46,7 +46,6 @@ namespace CNORXZ IndexId<0> id() const; MetaType operator*() const; - MetaType operator->() const; SizeT dim() const Sptr range() const; diff --git a/src/include/ranges/prange.h b/src/include/ranges/prange.h index c6a8e1c..7c5f0a3 100644 --- a/src/include/ranges/prange.h +++ b/src/include/ranges/prange.h @@ -48,9 +48,6 @@ namespace CNORXZ SubIndex& operator()(const std::shared_ptr& ind); // set full index - int pp(std::intptr_t idxPtrNum); - int mm(std::intptr_t idxPtrNum); - std::string stringMeta() const; MetaType meta() const; const MetaType* metaPtr() const; diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index 897e836..1d1c46c 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -17,7 +17,7 @@ namespace CNORXZ template UIndex::UIndex(const RangePtr& range, SizeT pos) : IndexInterface,MetaType>(pos), - mRangePtr(rangeCast(range)), + mRangePtr(rangeCast(range)), mMetaPtr(&mRangePtr->get(0)) {} @@ -86,12 +86,6 @@ namespace CNORXZ return mMetaPtr[IB::mPos]; } - template - const MetaType* UIndex::operator->() const - { - return mMetaPtr + IB::mPos; - } - template String UIndex::stringMeta() const { @@ -134,7 +128,7 @@ namespace CNORXZ template decltype(auto) UIndex::ifor(const Xpr& xpr, F&& f) const { - return For<0,Xpr>(this->max(), this->id(), xpr, std::forward(f)); + return For<0,Xpr,F>(this->max(), this->id(), xpr, std::forward(f)); } /********************** @@ -160,9 +154,9 @@ namespace CNORXZ template void URangeFactory::make() { - auto info = typeid(URange); + const auto& info = typeid(URange); if(mRef != nullptr) { - mProd = this->fromCreated[info.hash_code()][mRef->id()]; + mProd = this->fromCreated(info, {mRef->id()}); } if(mProd == nullptr){ RangePtr key = mProd = std::shared_ptr> @@ -188,7 +182,7 @@ namespace CNORXZ template URange::URange(Vector&& space) : - RangeInterface,MetaType>(), + RangeInterface,MetaType>(), mSpace(space) { std::sort(mSpace.begin(), mSpace.end(), std::less()); @@ -230,21 +224,15 @@ namespace CNORXZ } template - typename URange::IndexType URange::begin() const + const TypeInfo& URange::type() const { - UIndex i( std::dynamic_pointer_cast > - ( RangePtr( RB::mThis ) ) ); - i = 0; - return i; + return typeid(URange); } template - typename URange::IndexType URange::end() const + const TypeInfo& URange::metaType() const { - UIndex i( std::dynamic_pointer_cast > - ( RangePtr( RB::mThis ) ) ); - i = this->size(); - return i; + return typeid(MetaType); } /******************* diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index 4798c56..9543b94 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -33,7 +33,6 @@ namespace CNORXZ IndexId<0> id() const; const MetaType& operator*() const; - const MetaType* operator->() const; SizeT dim() const; // = 1 Sptr range() const; @@ -82,8 +81,8 @@ namespace CNORXZ virtual SizeT size() const override final; virtual SizeT dim() const override final; virtual String stringMeta(SizeT pos) const override final; - virtual IndexType begin() const override final; - virtual IndexType end() const override final; + virtual const TypeInfo& type() const override final; + virtual const TypeInfo& metaType() const override final; const MetaType& get(SizeT pos) const; SizeT getMeta(const MetaType& metaPos) const; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 03c0b1f..50e0109 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -95,26 +95,6 @@ namespace CNORXZ { return DType(*(*mI)); } - - template - DType XIndex::operator->() const - { - return DType(*(*mI)); - } - - template - Int XIndex::pp(PtrId idxPtrNum) - { - Int out = mI->pp(idxPtrNum); - return out; - } - - template - Int XIndex::mm(PtrId idxPtrNum) - { - Int out = mI->mm(idxPtrNum); - return out; - } template SizeT XIndex::dim() const diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index ab65d3e..434c64c 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -29,10 +29,6 @@ namespace CNORXZ virtual IndexId<0> id() const = 0; virtual DType operator*() const = 0; - virtual DType operator->() const = 0; - - virtual Int pp(PtrId idxPtrNum) = 0; - virtual Int mm(PtrId idxPtrNum) = 0; virtual SizeT dim() const = 0; virtual RangePtr range() const = 0; @@ -79,10 +75,6 @@ namespace CNORXZ virtual IndexId<0> id() const override final; virtual DType operator*() const override final; - virtual DType operator->() const override final; - - virtual Int pp(PtrId idxPtrNum) override final; - virtual Int mm(PtrId idxPtrNum) override final; virtual SizeT dim() const override final; virtual RangePtr range() const override final; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index bb3b440..c078900 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -38,10 +38,6 @@ namespace CNORXZ IndexId<0> id() const; DType operator*() const; - DType operator->() const; - - Int pp(PtrId idxPtrNum); - Int mm(PtrId idxPtrNum); SizeT dim() const; Sptr range() const; diff --git a/src/lib/ranges/crange.cc b/src/lib/ranges/crange.cc index 1c539a7..93495f1 100644 --- a/src/lib/ranges/crange.cc +++ b/src/lib/ranges/crange.cc @@ -66,23 +66,6 @@ namespace CNORXZ return IB::mPos; } - SizeT CIndex::operator->() const - { - return IB::mPos; // check if this makes sense!!! - } - - Int CIndex::pp(PtrId idxPtrNum) - { - ++(*this); - return 1; - } - - Int CIndex::mm(PtrId idxPtrNum) - { - --(*this); - return 1; - } - SizeT CIndex::dim() const // = 1 { return 1; diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index 83fe638..00e541a 100644 --- a/src/lib/ranges/dindex.cc +++ b/src/lib/ranges/dindex.cc @@ -87,25 +87,6 @@ namespace CNORXZ return *(*mI); } - DType DIndex::operator->() const - { - return *(*mI); - } - - Int DIndex::pp(PtrId idxPtrNum) - { - const Int out = mI->pp(idxPtrNum); - IB::mPos = mI->pos(); - return out; - } - - Int DIndex::mm(PtrId idxPtrNum) - { - const Int out = mI->mm(idxPtrNum); - IB::mPos = mI->pos(); - return out; - } - SizeT DIndex::dim() const { return mI->dim(); diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 8af907b..e0ca97c 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -106,26 +106,6 @@ namespace CNORXZ return DType(); } - DType YIndex::operator->() const - { - assert(0); - return DType(); - } - - Int YIndex::pp(PtrId idxPtrNum) - { - assert(0); - // sub inds !!! - return 0; - } - - Int YIndex::mm(PtrId idxPtrNum) - { - assert(0); - // sub inds !!! - return 0; - } - SizeT YIndex::dim() const { return mRangePtr->dim(); diff --git a/src/tests/range_unit_test.cc b/src/tests/range_unit_test.cc index f1f1935..44667f1 100644 --- a/src/tests/range_unit_test.cc +++ b/src/tests/range_unit_test.cc @@ -25,6 +25,19 @@ namespace SizeT mSize; }; + class UR_Test : public ::testing::Test + { + protected: + + UR_Test() + { + mMeta = { "These", "are", "test", "strings", "foo", "bar", "baz" }; + std::sort(mMeta.begin(), mMeta.end(), std::less()); + } + + Vector mMeta; + }; + TEST_F(CR_Test, Basics) { auto cr = CRangeFactory(mSize).create(); @@ -47,7 +60,8 @@ namespace auto endxi = cr->end(); for(auto xi = cr->begin(); xi != endxi; ++xi){ EXPECT_EQ(xi.pos(), cnt); - EXPECT_EQ(*xi, cnt); + EXPECT_TRUE(*xi == DType(cnt)); + EXPECT_EQ((*xi).str(), std::to_string(cnt)); ++cnt; } @@ -58,6 +72,38 @@ namespace } + TEST_F(UR_Test, Basics) + { + auto ur = URangeFactory(mMeta).create(); + auto urx = std::dynamic_pointer_cast>(ur); + EXPECT_EQ(ur->size(), mMeta.size()); + EXPECT_EQ(urx->size(), mMeta.size()); + + EXPECT_TRUE(urx->begin() != urx->end()); + EXPECT_FALSE(urx->begin() == urx->end()); + EXPECT_EQ(urx->begin().pos(), 0u); + EXPECT_EQ(urx->end().pos(), mMeta.size()); + + EXPECT_TRUE(ur->begin() != ur->end()); + EXPECT_FALSE(ur->begin() == ur->end()); + EXPECT_EQ(ur->begin().pos(), 0u); + EXPECT_EQ(ur->end().pos(), mMeta.size()); + + SizeT cnt = 0; + auto endxi = ur->end(); + for(auto xi = ur->begin(); xi != endxi; ++xi){ + EXPECT_EQ(xi.pos(), cnt); + EXPECT_TRUE(*xi == DType(mMeta[cnt])); + EXPECT_EQ((*xi).str(), mMeta[cnt]); + ++cnt; + } + + SizeT cnt2 = 0; + for(auto x: *urx){ + EXPECT_EQ(x, mMeta[cnt2++]); + } + } + // UR_Test // RCast_Test }