first DPos test works

This commit is contained in:
Christian Zimmermann 2022-10-12 15:28:35 +02:00
parent 459ea690e5
commit 4dc6846845
5 changed files with 134 additions and 35 deletions

View file

@ -3,6 +3,7 @@
#define __cxz_pos_type_cc_h__ #define __cxz_pos_type_cc_h__
#include "pos_type.h" #include "pos_type.h"
#include "vpos_type.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -339,7 +340,12 @@ namespace CNORXZ
inline const VPosBase* DPos::get() const 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 inline bool DPos::F() const
@ -365,21 +371,35 @@ namespace CNORXZ
template <class PosT> template <class PosT>
inline DPos DPos::operator+(const PosT& a) const inline DPos DPos::operator+(const PosT& a) const
{ {
return DPos(mC->vplus( VPosRef<PosT>(&a) )); if constexpr(std::is_same<PosT,DPos>::value or std::is_same<PosT,DPosRef>::value){
return DPos(mC->vplus( a.vpos() ));
}
else {
return DPos(mC->vplus( VPosRef<PosT>(&a) ));
}
} }
template <class PosT> template <class PosT>
inline DPos DPos::operator*(const PosT& a) const inline DPos DPos::operator*(const PosT& a) const
{ {
if constexpr(std::is_same<PosT,DPos>::value or std::is_same<PosT,DPosRef>::value){
return DPos(mC->vtimes( VPosRef<PosT>(&a) )); return DPos(mC->vtimes( a.vpos() ));
}
else {
return DPos(mC->vtimes( VPosRef<PosT>(&a) ));
}
} }
// same as operator*, except for FPos/SFPos, where map is executed // same as operator*, except for FPos/SFPos, where map is executed
template <class PosT> template <class PosT>
inline DPos DPos::operator()(const PosT& a) const inline DPos DPos::operator()(const PosT& a) const
{ {
return DPos(mC->vexec( VPosRef<PosT>(&a) )); if constexpr(std::is_same<PosT,DPos>::value or std::is_same<PosT,DPosRef>::value){
return DPos(mC->vexec( a.vpos() ));
}
else {
return DPos(mC->vexec( VPosRef<PosT>(&a) ));
}
} }
template <class PosT> template <class PosT>
@ -396,7 +416,12 @@ namespace CNORXZ
inline const VPosBase* DPosRef::get() const 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 inline bool DPosRef::F() const
@ -422,20 +447,35 @@ namespace CNORXZ
template <class PosT> template <class PosT>
inline DPos DPosRef::operator+(const PosT& a) const inline DPos DPosRef::operator+(const PosT& a) const
{ {
return DPos(mP->vplus( VPosRef<PosT>(&a) )); if constexpr(std::is_same<PosT,DPos>::value or std::is_same<PosT,DPosRef>::value){
return DPos(mP->vplus( a.vpos() ));
}
else {
return DPos(mP->vplus( VPosRef<PosT>(&a) ));
}
} }
template <class PosT> template <class PosT>
inline DPos DPosRef::operator*(const PosT& a) const inline DPos DPosRef::operator*(const PosT& a) const
{ {
return DPos(mP->vtimes( VPosRef<PosT>(&a) )); if constexpr(std::is_same<PosT,DPos>::value or std::is_same<PosT,DPosRef>::value){
return DPos(mP->vtimes( a.vpos() ));
}
else {
return DPos(mP->vtimes( VPosRef<PosT>(&a) ));
}
} }
// same as operator*, except for FPos/SFPos, where map is executed // same as operator*, except for FPos/SFPos, where map is executed
template <class PosT> template <class PosT>
inline DPos DPosRef::operator()(const PosT& a) const inline DPos DPosRef::operator()(const PosT& a) const
{ {
return DPos(mP->vexec( VPosRef<PosT>(&a) )); if constexpr(std::is_same<PosT,DPos>::value or std::is_same<PosT,DPosRef>::value){
return DPos(mP->vexec( a.vpos() ));
}
else {
return DPos(mP->vexec( VPosRef<PosT>(&a) ));
}
} }
template <class PosT> template <class PosT>

View file

@ -12,7 +12,10 @@ namespace CNORXZ
template <class T> template <class T>
struct is_scalar_pos_type { CXZ_CVAL_FALSE; }; struct is_scalar_pos_type { CXZ_CVAL_FALSE; };
template <class T>
struct is_static_pos_type { CXZ_CVAL_FALSE; };
template <SizeT N> template <SizeT N>
class SPos class SPos
{ {
@ -170,6 +173,7 @@ namespace CNORXZ
inline explicit DPos(PosT&& a); inline explicit DPos(PosT&& a);
inline const VPosBase* get() const; inline const VPosBase* get() const;
inline const VPosBase* vpos() const;
inline bool F() const; inline bool F() const;
inline SizeT size() const; inline SizeT size() const;
inline SizeT val() const; inline SizeT val() const;
@ -200,6 +204,7 @@ namespace CNORXZ
explicit DPosRef(const VPosBase* p); explicit DPosRef(const VPosBase* p);
inline const VPosBase* get() const; inline const VPosBase* get() const;
inline const VPosBase* vpos() const;
inline bool F() const; inline bool F() const;
inline SizeT size() const; inline SizeT size() const;
inline SizeT val() const; inline SizeT val() const;
@ -221,12 +226,14 @@ namespace CNORXZ
template <SizeT N> struct is_pos_type<SPos<N>> { CXZ_CVAL_TRUE; }; template <SizeT N> struct is_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
template <SizeT N> struct is_scalar_pos_type<SPos<N>> { CXZ_CVAL_TRUE; }; template <SizeT N> struct is_scalar_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
template <SizeT N> struct is_static_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<UPos> { CXZ_CVAL_TRUE; }; template <> struct is_pos_type<UPos> { CXZ_CVAL_TRUE; };
template <> struct is_scalar_pos_type<UPos> { CXZ_CVAL_TRUE; }; template <> struct is_scalar_pos_type<UPos> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<FPos> { CXZ_CVAL_TRUE; }; template <> struct is_pos_type<FPos> { CXZ_CVAL_TRUE; };
template <> struct is_scalar_pos_type<FPos> { CXZ_CVAL_TRUE; }; template <> struct is_scalar_pos_type<FPos> { CXZ_CVAL_TRUE; };
template <SizeT N, SizeT... Ms> struct is_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; }; template <SizeT N, SizeT... Ms> struct is_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
template <SizeT N, SizeT... Ms> struct is_scalar_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; }; template <SizeT N, SizeT... Ms> struct is_scalar_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
template <SizeT N, SizeT... Ms> struct is_static_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
template <class BPosT, class NPosT> struct is_pos_type<MPos<BPosT,NPosT>> { CXZ_CVAL_TRUE; }; template <class BPosT, class NPosT> struct is_pos_type<MPos<BPosT,NPosT>> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<DPos> { CXZ_CVAL_TRUE; }; template <> struct is_pos_type<DPos> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<DPosRef> { CXZ_CVAL_TRUE; }; template <> struct is_pos_type<DPosRef> { CXZ_CVAL_TRUE; };

View file

@ -3,6 +3,7 @@
#define __cxz_vpos_type_cc_h__ #define __cxz_vpos_type_cc_h__
#include "vpos_type.h" #include "vpos_type.h"
#include "pos_type.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -28,14 +29,14 @@ namespace CNORXZ
return this->vextend(static_cast<const PosT1&>(a))->vextend(a.next()); return this->vextend(static_cast<const PosT1&>(a))->vextend(a.next());
} }
inline Uptr<VPosBase> vextend(const DPos& a) const inline Uptr<VPosBase> VPosBase::vextend(const DPos& a) const
{ {
Uptr out = nullptr; Uptr<VPosBase> out = nullptr;
if(a.F()){ if(a.F()){
out = this->vextend(dynamic_cast<const FPos*>(a.get())); out = this->vextend(*dynamic_cast<const FPos*>(a.get()));
} }
else { else {
out = this->vextend(dynamic_cast<const UPos*>(a.get())); out = this->vextend(*dynamic_cast<const UPos*>(a.get()));
} }
if(a.size() > 1){ if(a.size() > 1){
return out->vextend(a.next()); return out->vextend(a.next());
@ -45,14 +46,14 @@ namespace CNORXZ
} }
} }
inline Uptr<VPosBase> vextend(const DPosRef& a) const inline Uptr<VPosBase> VPosBase::vextend(const DPosRef& a) const
{ {
Uptr out = nullptr; Uptr<VPosBase> out = nullptr;
if(a.F()){ if(a.F()){
out = this->vextend(dynamic_cast<const FPos*>(a.get())); out = this->vextend(*dynamic_cast<const FPos*>(a.get()));
} }
else { else {
out = this->vextend(dynamic_cast<const UPos*>(a.get())); out = this->vextend(*dynamic_cast<const UPos*>(a.get()));
} }
if(a.size() > 1){ if(a.size() > 1){
return out->vextend(a.next()); return out->vextend(a.next());
@ -77,10 +78,16 @@ namespace CNORXZ
return std::make_unique<VPos<PosT>>(*this); return std::make_unique<VPos<PosT>>(*this);
} }
template <class PosT>
const VPosBase* VPos<PosT>::vget() const
{
return this;
}
template <class PosT> template <class PosT>
bool VPos<PosT>::F() const bool VPos<PosT>::F() const
{ {
if constexpr(typename std::is_same<PosT,FPos>::value){ if constexpr(std::is_same<PosT,FPos>::value){
return true; return true;
} }
else { else {
@ -149,6 +156,7 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
VPos<MPos<PosT1,PosT2>>::VPos(const MPos<PosT1,PosT2>& a) : VPos<MPos<PosT1,PosT2>>::VPos(const MPos<PosT1,PosT2>& a) :
MPos<PosT1,PosT2>(a), MPos<PosT1,PosT2>(a),
mTRef(this),
mNRef(&this->next()) mNRef(&this->next())
{} {}
@ -158,10 +166,16 @@ namespace CNORXZ
return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*this); return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*this);
} }
template <class PosT1, class PosT2>
const VPosBase* VPos<MPos<PosT1,PosT2>>::vget() const
{
return &mTRef;
}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
bool VPos<MPos<PosT1,PosT2>>::F() const bool VPos<MPos<PosT1,PosT2>>::F() const
{ {
if constexpr(typename std::is_same<PosT1,FPos>::value){ if constexpr(std::is_same<PosT1,FPos>::value){
return true; return true;
} }
else { else {
@ -237,10 +251,16 @@ namespace CNORXZ
return std::make_unique<VPos<PosT>>(*mC); return std::make_unique<VPos<PosT>>(*mC);
} }
template <class PosT>
const VPosBase* VPosRef<PosT>::vget() const
{
return this;
}
template <class PosT> template <class PosT>
bool VPosRef<PosT>::F() const bool VPosRef<PosT>::F() const
{ {
if constexpr(typename std::is_same<PosT,FPos>::value){ if constexpr(std::is_same<PosT,FPos>::value){
return true; return true;
} }
else { else {
@ -307,7 +327,7 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
VPosRef<MPos<PosT1,PosT2>>::VPosRef(const MPos<PosT1,PosT2>* c) : VPosRef<MPos<PosT1,PosT2>>::VPosRef(const MPos<PosT1,PosT2>* c) :
mC(c), mNRef(c->vnext()) mC(c), mTRef(this), mNRef(c->vnext())
{} {}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
@ -316,10 +336,16 @@ namespace CNORXZ
return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*mC); return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*mC);
} }
template <class PosT1, class PosT2>
const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vget() const
{
return &mTRef;
}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
bool VPosRef<MPos<PosT1,PosT2>>::F() const bool VPosRef<MPos<PosT1,PosT2>>::F() const
{ {
if constexpr(typename std::is_same<PosT1,FPos>::value){ if constexpr(std::is_same<PosT1,FPos>::value){
return true; return true;
} }
else { else {

View file

@ -45,6 +45,7 @@ namespace CNORXZ
VPos(const PosT& a); VPos(const PosT& a);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual const VPosBase* vget() const override final;
virtual bool F() const override final; virtual bool F() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
@ -60,6 +61,7 @@ namespace CNORXZ
class VPos<MPos<PosT1,PosT2>> : public VPosBase, public MPos<PosT1,PosT2> class VPos<MPos<PosT1,PosT2>> : public VPosBase, public MPos<PosT1,PosT2>
{ {
private: private:
VPosRef<PosT1> mTRef;
VPosRef<PosT2> mNRef; VPosRef<PosT2> mNRef;
public: public:
@ -67,6 +69,7 @@ namespace CNORXZ
VPos(const MPos<PosT1,PosT2>& a); VPos(const MPos<PosT1,PosT2>& a);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual const VPosBase* vget() const override final;
virtual bool F() const override final; virtual bool F() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
@ -89,6 +92,7 @@ namespace CNORXZ
VPosRef(const PosT* c); VPosRef(const PosT* c);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual const VPosBase* vget() const override final;
virtual bool F() const override final; virtual bool F() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
@ -106,6 +110,7 @@ namespace CNORXZ
{ {
private: private:
const MPos<PosT1,PosT2>* mC = nullptr; const MPos<PosT1,PosT2>* mC = nullptr;
VPosRef<PosT1> mTRef;
VPosRef<PosT2> mNRef; VPosRef<PosT2> mNRef;
public: public:
@ -113,6 +118,7 @@ namespace CNORXZ
VPosRef(const MPos<PosT1,PosT2>* c); VPosRef(const MPos<PosT1,PosT2>* c);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual const VPosBase* vget() const override final;
virtual bool F() const override final; virtual bool F() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
@ -127,6 +133,26 @@ namespace CNORXZ
}; };
// defined as empty since they should never instanciated
template <SizeT N>
class VPos<SPos<N>>
{};
// defined as empty since they should never instanciated
template <SizeT N>
class VPosRef<SPos<N>>
{};
// defined as empty since they should never instanciated
template <SizeT N, SizeT... Ms>
class VPos<SFPos<N,Ms...>>
{};
// defined as empty since they should never instanciated
template <SizeT N, SizeT... Ms>
class VPosRef<SFPos<N,Ms...>>
{};
// defined as empty since they should never instanciated // defined as empty since they should never instanciated
template <> template <>
class VPos<DPos> class VPos<DPos>

View file

@ -102,20 +102,20 @@ namespace
{ {
DPos dp01(static_cast<UPos>(mS2p)); DPos dp01(static_cast<UPos>(mS2p));
DPos dp02(mUp1); DPos dp02(mUp1);
/*
DPos dp1(mkMPos(mS2p, mUp1)); DPos dp1(mkMPos(static_cast<UPos>(mS2p), mUp1));
DPos dp2(mkMPos(mUp2, mS4p)); DPos dp2(mkMPos(mUp2, static_cast<UPos>(mS4p)));
auto dp3a = dp1 + dp2; auto dp3a = dp1 + dp2;
auto dp3b = dp2 + dp1; auto dp3b = dp2 + dp1;
auto dp4 = dp1 * dp01; auto dp4 = dp1 * dp01;
auto dp5 = dp2 * dp02; auto dp5 = dp2 * dp02;
*/
EXPECT_EQ(dp01.size(), 1); EXPECT_EQ(dp01.size(), 1);
EXPECT_EQ(dp02.size(), 1); EXPECT_EQ(dp02.size(), 1);
EXPECT_EQ(dp01.val(), mS2p.val()); EXPECT_EQ(dp01.val(), mS2p.val());
EXPECT_EQ(dp02.val(), mUp1.val()); EXPECT_EQ(dp02.val(), mUp1.val());
/*
EXPECT_EQ(dp1.size(), 2); EXPECT_EQ(dp1.size(), 2);
EXPECT_EQ(dp2.size(), 2); EXPECT_EQ(dp2.size(), 2);
@ -124,19 +124,19 @@ namespace
EXPECT_EQ(dp4.size(), 2); EXPECT_EQ(dp4.size(), 2);
EXPECT_EQ(dp5.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(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(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(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(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(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()); EXPECT_EQ(dp5.next().val(), mS4p.val() * mUp1.val());
*/
} }
} }