remove most of static chains in vpos

This commit is contained in:
Christian Zimmermann 2022-10-13 14:39:40 +02:00
parent d804f5db7e
commit d555fabf40
5 changed files with 118 additions and 141 deletions

View file

@ -35,4 +35,7 @@
#define CXZ_CVAL_FALSE static constexpr bool value = false #define CXZ_CVAL_FALSE static constexpr bool value = false
#define CXZ_CVAL_TRUE static constexpr bool value = true #define CXZ_CVAL_TRUE static constexpr bool value = true
#define IS_SAME(a,b) std::is_same<a,b>::value
#define IS_NOT_SAME(a,b) (not std::is_same<a,b>::value)
#endif #endif

View file

@ -321,6 +321,10 @@ namespace CNORXZ
ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a)) ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a))
{} {}
inline DPos::DPos(const DPosRef& a) :
ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a.vpos()->copy()))
{}
template <class PosT> template <class PosT>
inline DPos::DPos(const PosT& a) : inline DPos::DPos(const PosT& a) :
ObjHandle<VPosBase> ObjHandle<VPosBase>
@ -349,11 +353,6 @@ namespace CNORXZ
return mC.get(); return mC.get();
} }
inline bool DPos::F() const
{
return mC->F();
}
inline SizeT DPos::size() const inline SizeT DPos::size() const
{ {
return mC->vsize(); return mC->vsize();
@ -428,11 +427,6 @@ namespace CNORXZ
return mP; return mP;
} }
inline bool DPosRef::F() const
{
return mP->F();
}
inline SizeT DPosRef::size() const inline SizeT DPosRef::size() const
{ {
return mP->vsize(); return mP->vsize();
@ -455,7 +449,8 @@ namespace CNORXZ
return DPos(mP->vplus( a.vpos() )); return DPos(mP->vplus( a.vpos() ));
} }
else { else {
return DPos(mP->vplus( VPosRef<PosT>(&a) )); VPosRef<PosT> b(&a);
return DPos(mP->vplus( &b ));
} }
} }
@ -466,7 +461,8 @@ namespace CNORXZ
return DPos(mP->vtimes( a.vpos() )); return DPos(mP->vtimes( a.vpos() ));
} }
else { else {
return DPos(mP->vtimes( VPosRef<PosT>(&a) )); VPosRef<PosT> b(&a);
return DPos(mP->vtimes( &b ));
} }
} }
@ -478,7 +474,8 @@ namespace CNORXZ
return DPos(mP->vexec( a.vpos() )); return DPos(mP->vexec( a.vpos() ));
} }
else { else {
return DPos(mP->vexec( VPosRef<PosT>(&a) )); VPosRef<PosT> b(&a);
return DPos(mP->vexec( &b ));
} }
} }

View file

@ -177,6 +177,7 @@ namespace CNORXZ
DEFAULT_MEMBERS(DPos); DEFAULT_MEMBERS(DPos);
inline DPos(Uptr<VPosBase>&& a); inline DPos(Uptr<VPosBase>&& a);
inline DPos(const DPosRef& a);
template <class PosT> template <class PosT>
inline explicit DPos(const PosT& a); inline explicit DPos(const PosT& a);
@ -186,7 +187,6 @@ namespace CNORXZ
inline const VPosBase* get() const; inline const VPosBase* get() const;
inline const VPosBase* vpos() const; inline const VPosBase* vpos() const;
inline bool F() const;
inline SizeT size() const; inline SizeT size() const;
inline SizeT val() const; inline SizeT val() const;
inline DPosRef next() const; inline DPosRef next() const;
@ -217,7 +217,6 @@ namespace CNORXZ
inline const VPosBase* get() const; inline const VPosBase* get() const;
inline const VPosBase* vpos() const; inline const VPosBase* vpos() const;
inline bool F() const;
inline SizeT size() const; inline SizeT size() const;
inline SizeT val() const; inline SizeT val() const;
inline DPosRef next() const; inline DPosRef next() const;

View file

@ -29,40 +29,6 @@ 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> VPosBase::vextend(const DPos& a) const
{
Uptr<VPosBase> out = nullptr;
if(a.F()){
out = this->vextend(*dynamic_cast<const FPos*>(a.get()));
}
else {
out = this->vextend(*dynamic_cast<const UPos*>(a.get()));
}
if(a.size() > 1){
return out->vextend(a.next());
}
else {
return out;
}
}
inline Uptr<VPosBase> VPosBase::vextend(const DPosRef& a) const
{
Uptr<VPosBase> out = nullptr;
if(a.F()){
out = this->vextend(*dynamic_cast<const FPos*>(a.get()));
}
else {
out = this->vextend(*dynamic_cast<const UPos*>(a.get()));
}
if(a.size() > 1){
return out->vextend(a.next());
}
else {
return out;
}
}
/************ /************
* VPos * * VPos *
************/ ************/
@ -84,17 +50,6 @@ namespace CNORXZ
return this; return this;
} }
template <class PosT>
bool VPos<PosT>::F() const
{
if constexpr(std::is_same<PosT,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT> template <class PosT>
SizeT VPos<PosT>::vsize() const SizeT VPos<PosT>::vsize() const
{ {
@ -147,18 +102,52 @@ namespace CNORXZ
typedef decltype(this->extend(a)) OPosT; typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a)); return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
// .... probably I need to define a static instanciation limit...
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPos& a) const
{
typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPosRef& a) const
{
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
}
/****************** /******************
* VPos<MPos> * * VPos<MPos> *
******************/ ******************/
template <class PosT1, class PosT2>
VPos<MPos<PosT1,PosT2>>::VPos(const VPos& a) :
MPos<PosT1,PosT2>(a),
mTRef(static_cast<const PosT1*>(this))
{
if constexpr(IS_NOT_SAME(PosT2,DPos) and IS_NOT_SAME(PosT2,DPosRef)){
mNRef = VPosRef<PosT2>(&this->next());
}
}
template <class PosT1, class PosT2>
VPos<MPos<PosT1,PosT2>>& VPos<MPos<PosT1,PosT2>>::operator=(const VPos& a)
{
MPos<PosT1,PosT2>::operator=(a);
mTRef = VPosRef<PosT1>(static_cast<const PosT1*>(this));
if constexpr(IS_NOT_SAME(PosT2,DPos) and IS_NOT_SAME(PosT2,DPosRef)){
mNRef = VPosRef<PosT2>(&this->next());
}
return *this;
}
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(static_cast<const PosT1*>(this)) mTRef(static_cast<const PosT1*>(this))
{ {
if constexpr(not std::is_same<PosT2,DPos>::value){ if constexpr(IS_NOT_SAME(PosT2,DPos) and IS_NOT_SAME(PosT2,DPosRef)){
mNRef = VPosRef<PosT2>(&this->next()); mNRef = VPosRef<PosT2>(&this->next());
} }
} }
@ -175,17 +164,6 @@ namespace CNORXZ
return &mTRef; return &mTRef;
} }
template <class PosT1, class PosT2>
bool VPos<MPos<PosT1,PosT2>>::F() const
{
if constexpr(std::is_same<PosT1,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
SizeT VPos<MPos<PosT1,PosT2>>::vsize() const SizeT VPos<MPos<PosT1,PosT2>>::vsize() const
{ {
@ -201,7 +179,7 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
const VPosBase* VPos<MPos<PosT1,PosT2>>::vnext() const const VPosBase* VPos<MPos<PosT1,PosT2>>::vnext() const
{ {
if constexpr(not std::is_same<PosT2,DPos>::value){ if constexpr(IS_NOT_SAME(PosT2,DPos) and IS_NOT_SAME(PosT2,DPosRef)){
return &mNRef; return &mNRef;
} }
else { else {
@ -233,29 +211,29 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{ {
if constexpr(pos_depth<PosT2>::value < MAX_VMPOS_DEPTH-1){ typedef decltype(this->extend(DPos(a))) OPosT;
typedef decltype(this->extend(a)) OPosT; return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
else {
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
//CXZ_ERROR("preliminary...");
//return nullptr;
}
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const FPos& a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
{ {
if constexpr(pos_depth<PosT2>::value < MAX_VMPOS_DEPTH-1){ typedef decltype(this->extend(DPos(a))) OPosT;
typedef decltype(this->extend(a)) OPosT; return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
return std::make_unique<VPos<OPosT>>(this->extend(a)); }
}
else { template <class PosT1, class PosT2>
CXZ_ERROR("preliminary..."); Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
return nullptr; {
} typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
} }
/*************** /***************
@ -279,17 +257,6 @@ namespace CNORXZ
return this; return this;
} }
template <class PosT>
bool VPosRef<PosT>::F() const
{
if constexpr(std::is_same<PosT,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT> template <class PosT>
SizeT VPosRef<PosT>::vsize() const SizeT VPosRef<PosT>::vsize() const
{ {
@ -343,6 +310,20 @@ namespace CNORXZ
return std::make_unique<VPos<OPosT>>(mC->extend(a)); return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPos& a) const
{
typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPosRef& a) const
{
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
}
/********************* /*********************
* VPosRef<MPos> * * VPosRef<MPos> *
*********************/ *********************/
@ -352,7 +333,7 @@ namespace CNORXZ
mC(c), mC(c),
mTRef(static_cast<const PosT1*>(mC)) mTRef(static_cast<const PosT1*>(mC))
{ {
if constexpr(not std::is_same<PosT2,DPos>::value){ if constexpr(IS_NOT_SAME(PosT2,DPos) and IS_NOT_SAME(PosT2,DPosRef)){
mNRef = VPosRef<PosT2>(&c->next()); mNRef = VPosRef<PosT2>(&c->next());
} }
} }
@ -369,17 +350,6 @@ namespace CNORXZ
return &mTRef; return &mTRef;
} }
template <class PosT1, class PosT2>
bool VPosRef<MPos<PosT1,PosT2>>::F() const
{
if constexpr(std::is_same<PosT1,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
SizeT VPosRef<MPos<PosT1,PosT2>>::vsize() const SizeT VPosRef<MPos<PosT1,PosT2>>::vsize() const
{ {
@ -395,7 +365,7 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vnext() const const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vnext() const
{ {
if constexpr(not std::is_same<PosT2,DPos>::value){ if constexpr(IS_NOT_SAME(PosT2,DPos) and IS_NOT_SAME(PosT2,DPosRef)){
return &mNRef; return &mNRef;
} }
else { else {
@ -427,27 +397,29 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{ {
if constexpr(pos_depth<PosT2>::value < MAX_VMPOS_DEPTH-1){ typedef decltype(mC->extend(DPos(a))) OPosT;
typedef decltype(mC->extend(a)) OPosT; return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
else {
CXZ_ERROR("preliminary...");
return nullptr;
}
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const FPos& a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
{ {
if constexpr(pos_depth<PosT2>::value < MAX_VMPOS_DEPTH-1){ typedef decltype(mC->extend(DPos(a))) OPosT;
typedef decltype(mC->extend(a)) OPosT; return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
return std::make_unique<VPos<OPosT>>(mC->extend(a)); }
}
else { template <class PosT1, class PosT2>
CXZ_ERROR("preliminary..."); Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
return nullptr; {
} typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
} }
} }

View file

@ -14,7 +14,6 @@ namespace CNORXZ
DEFAULT_MEMBERS(VPosBase); DEFAULT_MEMBERS(VPosBase);
virtual Uptr<VPosBase> copy() const = 0; virtual Uptr<VPosBase> copy() const = 0;
virtual bool F() const = 0;
virtual SizeT vsize() const = 0; virtual SizeT vsize() const = 0;
virtual SizeT vval() const = 0; virtual SizeT vval() const = 0;
virtual const VPosBase* vget() const = 0; // strip away all MPos<...> virtual const VPosBase* vget() const = 0; // strip away all MPos<...>
@ -24,6 +23,8 @@ namespace CNORXZ
virtual Uptr<VPosBase> vexec(const VPosBase* a) const = 0; virtual Uptr<VPosBase> vexec(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vextend(const UPos& a) const = 0; virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const FPos& a) const = 0; virtual Uptr<VPosBase> vextend(const FPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0;
template <SizeT N> template <SizeT N>
inline Uptr<VPosBase> vextend(const SPos<N>& a) const; inline Uptr<VPosBase> vextend(const SPos<N>& a) const;
@ -34,8 +35,6 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
inline Uptr<VPosBase> vextend(const MPos<PosT1,PosT2>& a) const; inline Uptr<VPosBase> vextend(const MPos<PosT1,PosT2>& a) const;
inline Uptr<VPosBase> vextend(const DPos& a) const;
inline Uptr<VPosBase> vextend(const DPosRef& a) const;
}; };
template <class PosT> template <class PosT>
@ -48,7 +47,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual const VPosBase* vget() const override final; virtual const VPosBase* vget() 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;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
@ -57,6 +55,8 @@ namespace CNORXZ
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final; virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final; virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
}; };
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
@ -67,12 +67,14 @@ namespace CNORXZ
VPosRef<PosT2> mNRef; VPosRef<PosT2> mNRef;
public: public:
DEFAULT_MEMBERS(VPos); DEFAULT_C(VPos);
DEFAULT_MOVE(VPos);
VPos(const VPos& a);
VPos& operator=(const VPos& a);
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 const VPosBase* vget() 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;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
@ -81,6 +83,8 @@ namespace CNORXZ
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final; virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final; virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
}; };
template <class PosT> template <class PosT>
@ -95,7 +99,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual const VPosBase* vget() const override final; virtual const VPosBase* vget() 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;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
@ -104,6 +107,8 @@ namespace CNORXZ
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final; virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final; virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
}; };
@ -122,7 +127,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual const VPosBase* vget() const override final; virtual const VPosBase* vget() 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;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
@ -131,6 +135,8 @@ namespace CNORXZ
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final; virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final; virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
}; };