From 4dc6846845ff3e03e95e2d2b95149fddb2c0f473 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 12 Oct 2022 15:28:35 +0200 Subject: [PATCH] first DPos test works --- src/include/ranges/xfor/pos_type.cc.h | 58 ++++++++++++++++++++++---- src/include/ranges/xfor/pos_type.h | 9 +++- src/include/ranges/xfor/vpos_type.cc.h | 52 +++++++++++++++++------ src/include/ranges/xfor/vpos_type.h | 26 ++++++++++++ src/tests/xfor_unit_test.cc | 24 +++++------ 5 files changed, 134 insertions(+), 35 deletions(-) diff --git a/src/include/ranges/xfor/pos_type.cc.h b/src/include/ranges/xfor/pos_type.cc.h index 710e2d7..ff36b24 100644 --- a/src/include/ranges/xfor/pos_type.cc.h +++ b/src/include/ranges/xfor/pos_type.cc.h @@ -3,6 +3,7 @@ #define __cxz_pos_type_cc_h__ #include "pos_type.h" +#include "vpos_type.h" namespace CNORXZ { @@ -339,7 +340,12 @@ namespace CNORXZ inline const VPosBase* DPos::get() const { - return mC->get(); + return mC->vget(); + } + + inline const VPosBase* DPos::vpos() const + { + return mC.get(); } inline bool DPos::F() const @@ -365,21 +371,35 @@ namespace CNORXZ template inline DPos DPos::operator+(const PosT& a) const { - return DPos(mC->vplus( VPosRef(&a) )); + if constexpr(std::is_same::value or std::is_same::value){ + return DPos(mC->vplus( a.vpos() )); + } + else { + return DPos(mC->vplus( VPosRef(&a) )); + } } template inline DPos DPos::operator*(const PosT& a) const { - - return DPos(mC->vtimes( VPosRef(&a) )); + if constexpr(std::is_same::value or std::is_same::value){ + return DPos(mC->vtimes( a.vpos() )); + } + else { + return DPos(mC->vtimes( VPosRef(&a) )); + } } // same as operator*, except for FPos/SFPos, where map is executed template inline DPos DPos::operator()(const PosT& a) const { - return DPos(mC->vexec( VPosRef(&a) )); + if constexpr(std::is_same::value or std::is_same::value){ + return DPos(mC->vexec( a.vpos() )); + } + else { + return DPos(mC->vexec( VPosRef(&a) )); + } } template @@ -396,7 +416,12 @@ namespace CNORXZ inline const VPosBase* DPosRef::get() const { - return mP->get(); + return mP->vget(); + } + + inline const VPosBase* DPosRef::vpos() const + { + return mP; } inline bool DPosRef::F() const @@ -422,20 +447,35 @@ namespace CNORXZ template inline DPos DPosRef::operator+(const PosT& a) const { - return DPos(mP->vplus( VPosRef(&a) )); + if constexpr(std::is_same::value or std::is_same::value){ + return DPos(mP->vplus( a.vpos() )); + } + else { + return DPos(mP->vplus( VPosRef(&a) )); + } } template inline DPos DPosRef::operator*(const PosT& a) const { - return DPos(mP->vtimes( VPosRef(&a) )); + if constexpr(std::is_same::value or std::is_same::value){ + return DPos(mP->vtimes( a.vpos() )); + } + else { + return DPos(mP->vtimes( VPosRef(&a) )); + } } // same as operator*, except for FPos/SFPos, where map is executed template inline DPos DPosRef::operator()(const PosT& a) const { - return DPos(mP->vexec( VPosRef(&a) )); + if constexpr(std::is_same::value or std::is_same::value){ + return DPos(mP->vexec( a.vpos() )); + } + else { + return DPos(mP->vexec( VPosRef(&a) )); + } } template diff --git a/src/include/ranges/xfor/pos_type.h b/src/include/ranges/xfor/pos_type.h index 485b9e0..041eff9 100644 --- a/src/include/ranges/xfor/pos_type.h +++ b/src/include/ranges/xfor/pos_type.h @@ -12,7 +12,10 @@ namespace CNORXZ template struct is_scalar_pos_type { CXZ_CVAL_FALSE; }; - + + template + struct is_static_pos_type { CXZ_CVAL_FALSE; }; + template class SPos { @@ -170,6 +173,7 @@ namespace CNORXZ inline explicit DPos(PosT&& a); inline const VPosBase* get() const; + inline const VPosBase* vpos() const; inline bool F() const; inline SizeT size() const; inline SizeT val() const; @@ -200,6 +204,7 @@ namespace CNORXZ explicit DPosRef(const VPosBase* p); inline const VPosBase* get() const; + inline const VPosBase* vpos() const; inline bool F() const; inline SizeT size() const; inline SizeT val() const; @@ -221,12 +226,14 @@ namespace CNORXZ template struct is_pos_type> { CXZ_CVAL_TRUE; }; template struct is_scalar_pos_type> { CXZ_CVAL_TRUE; }; + template struct is_static_pos_type> { CXZ_CVAL_TRUE; }; template <> struct is_pos_type { CXZ_CVAL_TRUE; }; template <> struct is_scalar_pos_type { CXZ_CVAL_TRUE; }; template <> struct is_pos_type { CXZ_CVAL_TRUE; }; template <> struct is_scalar_pos_type { CXZ_CVAL_TRUE; }; template struct is_pos_type> { CXZ_CVAL_TRUE; }; template struct is_scalar_pos_type> { CXZ_CVAL_TRUE; }; + template struct is_static_pos_type> { CXZ_CVAL_TRUE; }; template struct is_pos_type> { CXZ_CVAL_TRUE; }; template <> struct is_pos_type { CXZ_CVAL_TRUE; }; template <> struct is_pos_type { CXZ_CVAL_TRUE; }; diff --git a/src/include/ranges/xfor/vpos_type.cc.h b/src/include/ranges/xfor/vpos_type.cc.h index 3ac2147..5332973 100644 --- a/src/include/ranges/xfor/vpos_type.cc.h +++ b/src/include/ranges/xfor/vpos_type.cc.h @@ -3,6 +3,7 @@ #define __cxz_vpos_type_cc_h__ #include "vpos_type.h" +#include "pos_type.h" namespace CNORXZ { @@ -28,14 +29,14 @@ namespace CNORXZ return this->vextend(static_cast(a))->vextend(a.next()); } - inline Uptr vextend(const DPos& a) const + inline Uptr VPosBase::vextend(const DPos& a) const { - Uptr out = nullptr; + Uptr out = nullptr; if(a.F()){ - out = this->vextend(dynamic_cast(a.get())); + out = this->vextend(*dynamic_cast(a.get())); } else { - out = this->vextend(dynamic_cast(a.get())); + out = this->vextend(*dynamic_cast(a.get())); } if(a.size() > 1){ return out->vextend(a.next()); @@ -45,14 +46,14 @@ namespace CNORXZ } } - inline Uptr vextend(const DPosRef& a) const + inline Uptr VPosBase::vextend(const DPosRef& a) const { - Uptr out = nullptr; + Uptr out = nullptr; if(a.F()){ - out = this->vextend(dynamic_cast(a.get())); + out = this->vextend(*dynamic_cast(a.get())); } else { - out = this->vextend(dynamic_cast(a.get())); + out = this->vextend(*dynamic_cast(a.get())); } if(a.size() > 1){ return out->vextend(a.next()); @@ -77,10 +78,16 @@ namespace CNORXZ return std::make_unique>(*this); } + template + const VPosBase* VPos::vget() const + { + return this; + } + template bool VPos::F() const { - if constexpr(typename std::is_same::value){ + if constexpr(std::is_same::value){ return true; } else { @@ -149,6 +156,7 @@ namespace CNORXZ template VPos>::VPos(const MPos& a) : MPos(a), + mTRef(this), mNRef(&this->next()) {} @@ -158,10 +166,16 @@ namespace CNORXZ return std::make_unique>>(*this); } + template + const VPosBase* VPos>::vget() const + { + return &mTRef; + } + template bool VPos>::F() const { - if constexpr(typename std::is_same::value){ + if constexpr(std::is_same::value){ return true; } else { @@ -237,10 +251,16 @@ namespace CNORXZ return std::make_unique>(*mC); } + template + const VPosBase* VPosRef::vget() const + { + return this; + } + template bool VPosRef::F() const { - if constexpr(typename std::is_same::value){ + if constexpr(std::is_same::value){ return true; } else { @@ -307,7 +327,7 @@ namespace CNORXZ template VPosRef>::VPosRef(const MPos* c) : - mC(c), mNRef(c->vnext()) + mC(c), mTRef(this), mNRef(c->vnext()) {} template @@ -316,10 +336,16 @@ namespace CNORXZ return std::make_unique>>(*mC); } + template + const VPosBase* VPosRef>::vget() const + { + return &mTRef; + } + template bool VPosRef>::F() const { - if constexpr(typename std::is_same::value){ + if constexpr(std::is_same::value){ return true; } else { diff --git a/src/include/ranges/xfor/vpos_type.h b/src/include/ranges/xfor/vpos_type.h index 33bec21..1cf36cf 100644 --- a/src/include/ranges/xfor/vpos_type.h +++ b/src/include/ranges/xfor/vpos_type.h @@ -45,6 +45,7 @@ namespace CNORXZ VPos(const PosT& a); virtual Uptr copy() const override final; + virtual const VPosBase* vget() const override final; virtual bool F() const override final; virtual SizeT vsize() const override final; virtual SizeT vval() const override final; @@ -60,6 +61,7 @@ namespace CNORXZ class VPos> : public VPosBase, public MPos { private: + VPosRef mTRef; VPosRef mNRef; public: @@ -67,6 +69,7 @@ namespace CNORXZ VPos(const MPos& a); virtual Uptr copy() const override final; + virtual const VPosBase* vget() const override final; virtual bool F() const override final; virtual SizeT vsize() const override final; virtual SizeT vval() const override final; @@ -89,6 +92,7 @@ namespace CNORXZ VPosRef(const PosT* c); virtual Uptr copy() const override final; + virtual const VPosBase* vget() const override final; virtual bool F() const override final; virtual SizeT vsize() const override final; virtual SizeT vval() const override final; @@ -106,6 +110,7 @@ namespace CNORXZ { private: const MPos* mC = nullptr; + VPosRef mTRef; VPosRef mNRef; public: @@ -113,6 +118,7 @@ namespace CNORXZ VPosRef(const MPos* c); virtual Uptr copy() const override final; + virtual const VPosBase* vget() const override final; virtual bool F() const override final; virtual SizeT vsize() const override final; virtual SizeT vval() const override final; @@ -127,6 +133,26 @@ namespace CNORXZ }; + // defined as empty since they should never instanciated + template + class VPos> + {}; + + // defined as empty since they should never instanciated + template + class VPosRef> + {}; + + // defined as empty since they should never instanciated + template + class VPos> + {}; + + // defined as empty since they should never instanciated + template + class VPosRef> + {}; + // defined as empty since they should never instanciated template <> class VPos diff --git a/src/tests/xfor_unit_test.cc b/src/tests/xfor_unit_test.cc index 8a471fe..75de91b 100644 --- a/src/tests/xfor_unit_test.cc +++ b/src/tests/xfor_unit_test.cc @@ -102,20 +102,20 @@ namespace { DPos dp01(static_cast(mS2p)); DPos dp02(mUp1); - /* - DPos dp1(mkMPos(mS2p, mUp1)); - DPos dp2(mkMPos(mUp2, mS4p)); + + DPos dp1(mkMPos(static_cast(mS2p), mUp1)); + DPos dp2(mkMPos(mUp2, static_cast(mS4p))); auto dp3a = dp1 + dp2; auto dp3b = dp2 + dp1; auto dp4 = dp1 * dp01; auto dp5 = dp2 * dp02; - */ + EXPECT_EQ(dp01.size(), 1); EXPECT_EQ(dp02.size(), 1); EXPECT_EQ(dp01.val(), mS2p.val()); EXPECT_EQ(dp02.val(), mUp1.val()); - /* + EXPECT_EQ(dp1.size(), 2); EXPECT_EQ(dp2.size(), 2); @@ -124,19 +124,19 @@ namespace EXPECT_EQ(dp4.size(), 2); EXPECT_EQ(dp5.size(), 2); - EXPECT_EQ(dp1.first().val(), mS2p.val()); + EXPECT_EQ(dp1.val(), mS2p.val()); EXPECT_EQ(dp1.next().val(), mUp1.val()); - EXPECT_EQ(dp2.first().val(), mUp2.val()); + EXPECT_EQ(dp2.val(), mUp2.val()); EXPECT_EQ(dp2.next().val(), mS4p.val()); - EXPECT_EQ(dp3a.first().val(), mS2p.val() + mUp2.val()); + EXPECT_EQ(dp3a.val(), mS2p.val() + mUp2.val()); EXPECT_EQ(dp3a.next().val(), mUp1.val() + mS4p.val()); - EXPECT_EQ(dp3b.first().val(), mS2p.val() + mUp2.val()); + EXPECT_EQ(dp3b.val(), mS2p.val() + mUp2.val()); EXPECT_EQ(dp3b.next().val(), mUp1.val() + mS4p.val()); - EXPECT_EQ(dp4.first().val(), mS2p.val() * mS2p.val()); + EXPECT_EQ(dp4.val(), mS2p.val() * mS2p.val()); EXPECT_EQ(dp4.next().val(), mUp1.val() * mS2p.val()); - EXPECT_EQ(dp5.first().val(), mUp2.val() * mUp1.val()); + EXPECT_EQ(dp5.val(), mUp2.val() * mUp1.val()); EXPECT_EQ(dp5.next().val(), mS4p.val() * mUp1.val()); - */ + } }