more on DPos/VPos

This commit is contained in:
Christian Zimmermann 2022-10-11 23:01:31 +02:00
parent ed6c90b95c
commit 459ea690e5
5 changed files with 151 additions and 83 deletions

View file

@ -69,6 +69,12 @@ namespace CNORXZ
return MPos<SPos<N>,PosT>(*this,a);
}
template <SizeT N>
constexpr SPos<N>::operator UPos() const
{
return UPos(N);
}
/************
* UPos *
************/
@ -315,20 +321,32 @@ namespace CNORXZ
template <class PosT>
inline DPos::DPos(const PosT& a) :
ObjHandle<VPosBase>(std::make_unique<VPos<PosT>>(a))
ObjHandle<VPosBase>
(std::make_unique<VPos<typename std::remove_reference<PosT>::type>>(a))
{
static_assert(is_pos_type<PosT>::value,
static_assert(is_pos_type<typename std::remove_reference<PosT>::type>::value,
"DPos can only be constructed from pos types");
}
template <class PosT>
inline DPos::DPos(PosT&& a) :
ObjHandle<VPosBase>(std::make_unique<VPos<PosT>>(a))
ObjHandle<VPosBase>
(std::make_unique<VPos<typename std::remove_reference<PosT>::type>>(a))
{
static_assert(is_pos_type<PosT>::value,
static_assert(is_pos_type<typename std::remove_reference<PosT>::type>::value,
"DPos can only be constructed from pos types");
}
inline const VPosBase* DPos::get() const
{
return mC->get();
}
inline bool DPos::F() const
{
return mC->F();
}
inline SizeT DPos::size() const
{
return mC->vsize();
@ -376,6 +394,16 @@ namespace CNORXZ
inline DPosRef::DPosRef(const VPosBase* p) : mP(p) {}
inline const VPosBase* DPosRef::get() const
{
return mP->get();
}
inline bool DPosRef::F() const
{
return mP->F();
}
inline SizeT DPosRef::size() const
{
return mP->vsize();

View file

@ -37,6 +37,8 @@ namespace CNORXZ
template <class PosT>
constexpr auto extend(const PosT& a) const;
explicit constexpr operator UPos() const;
};
class UPos
@ -167,6 +169,8 @@ namespace CNORXZ
template <class PosT>
inline explicit DPos(PosT&& a);
inline const VPosBase* get() const;
inline bool F() const;
inline SizeT size() const;
inline SizeT val() const;
inline DPosRef next() const;
@ -195,6 +199,8 @@ namespace CNORXZ
explicit DPosRef(const VPosBase* p);
inline const VPosBase* get() const;
inline bool F() const;
inline SizeT size() const;
inline SizeT val() const;
inline DPosRef next() const;

View file

@ -11,17 +11,57 @@ namespace CNORXZ
****************/
template <SizeT N>
Uptr<VPosBase> VPosBase::vextend(const SPos<N>& a) const
inline Uptr<VPosBase> VPosBase::vextend(const SPos<N>& a) const
{
return this->vextend(UPos(N));
}
template <SizeT N, SizeT... Ms>
Uptr<VPosBase> VPosBase::vextend(const SFPos<N,Ms...>& a) const
inline Uptr<VPosBase> VPosBase::vextend(const SFPos<N,Ms...>& a) const
{
return this->vextend(static_cast<FPos>(a));
}
template <class PosT1, class PosT2>
inline Uptr<VPosBase> VPosBase::vextend(const MPos<PosT1,PosT2>& a) const
{
return this->vextend(static_cast<const PosT1&>(a))->vextend(a.next());
}
inline Uptr<VPosBase> vextend(const DPos& a) const
{
Uptr 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> vextend(const DPosRef& a) const
{
Uptr 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 *
************/
@ -37,16 +77,27 @@ namespace CNORXZ
return std::make_unique<VPos<PosT>>(*this);
}
template <class PosT>
bool VPos<PosT>::F() const
{
if constexpr(typename std::is_same<PosT,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT>
SizeT VPos<PosT>::vsize() const
{
return PosT::THIS().size();
return this->size();
}
template <class PosT>
SizeT VPos<PosT>::vval() const
{
return PosT::THIS().val();
return this->val();
}
template <class PosT>
@ -76,20 +127,6 @@ namespace CNORXZ
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
}
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(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const UPos& a) const
{
@ -111,7 +148,7 @@ namespace CNORXZ
template <class PosT1, class PosT2>
VPos<MPos<PosT1,PosT2>>::VPos(const MPos<PosT1,PosT2>& a) :
MPos<PosT1,PosT2>(a.THIS()),
MPos<PosT1,PosT2>(a),
mNRef(&this->next())
{}
@ -121,6 +158,17 @@ namespace CNORXZ
return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*this);
}
template <class PosT1, class PosT2>
bool VPos<MPos<PosT1,PosT2>>::F() const
{
if constexpr(typename std::is_same<PosT1,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT1, class PosT2>
SizeT VPos<MPos<PosT1,PosT2>>::vsize() const
{
@ -160,20 +208,6 @@ namespace CNORXZ
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{
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(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{
@ -194,7 +228,7 @@ namespace CNORXZ
template <class PosT>
VPosRef<PosT>::VPosRef(const PosT* c) :
mC(&c)
mC(c)
{}
template <class PosT>
@ -203,6 +237,17 @@ namespace CNORXZ
return std::make_unique<VPos<PosT>>(*mC);
}
template <class PosT>
bool VPosRef<PosT>::F() const
{
if constexpr(typename std::is_same<PosT,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT>
SizeT VPosRef<PosT>::vsize() const
{
@ -242,20 +287,6 @@ namespace CNORXZ
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
}
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(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const UPos& a) const
{
@ -276,7 +307,7 @@ namespace CNORXZ
template <class PosT1, class PosT2>
VPosRef<MPos<PosT1,PosT2>>::VPosRef(const MPos<PosT1,PosT2>* c) :
mC(c), mNRef(&c->next())
mC(c), mNRef(c->vnext())
{}
template <class PosT1, class PosT2>
@ -285,6 +316,17 @@ namespace CNORXZ
return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*mC);
}
template <class PosT1, class PosT2>
bool VPosRef<MPos<PosT1,PosT2>>::F() const
{
if constexpr(typename std::is_same<PosT1,FPos>::value){
return true;
}
else {
return false;
}
}
template <class PosT1, class PosT2>
SizeT VPosRef<MPos<PosT1,PosT2>>::vsize() const
{
@ -324,20 +366,6 @@ namespace CNORXZ
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{
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(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{

View file

@ -12,22 +12,28 @@ namespace CNORXZ
DEFAULT_MEMBERS(VPosBase);
virtual Uptr<VPosBase> copy() const = 0;
virtual bool F() const = 0;
virtual SizeT vsize() const = 0;
virtual SizeT vval() const = 0;
virtual const VPosBase* vget() const = 0; // strip away all MPos<...>
virtual const VPosBase* vnext() const = 0;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0;
virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const FPos& a) const = 0;
template <SizeT N>
Uptr<VPosBase> vextend(const SPos<N>& a) const;
inline Uptr<VPosBase> vextend(const SPos<N>& a) const;
template <SizeT N, SizeT... Ms>
Uptr<VPosBase> vextend(const SFPos<N,Ms...>& a) const;
inline Uptr<VPosBase> vextend(const SFPos<N,Ms...>& a) const;
template <class PosT1, class PosT2>
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>
@ -39,14 +45,13 @@ namespace CNORXZ
VPos(const PosT& a);
virtual Uptr<VPosBase> copy() const override final;
virtual bool F() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
};
@ -62,14 +67,13 @@ namespace CNORXZ
VPos(const MPos<PosT1,PosT2>& a);
virtual Uptr<VPosBase> copy() const override final;
virtual bool F() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
};
@ -85,14 +89,13 @@ namespace CNORXZ
VPosRef(const PosT* c);
virtual Uptr<VPosBase> copy() const override final;
virtual bool F() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
@ -110,6 +113,7 @@ namespace CNORXZ
VPosRef(const MPos<PosT1,PosT2>* c);
virtual Uptr<VPosBase> copy() const override final;
virtual bool F() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vnext() const override final;

View file

@ -97,24 +97,25 @@ namespace
EXPECT_EQ(mp5.val(), mUp2.val() * mUp1.val());
EXPECT_EQ(mp5.next().val(), mS4p.val() * mUp1.val());
}
/*
TEST_F(Pos_Test, Dyn)
{
DPos dp01(mS2p);
DPos dp01(static_cast<UPos>(mS2p));
DPos dp02(mUp1);
/*
DPos dp1(mkMPos(mS2p, mUp1));
DPos dp2(mkMPos(mUp2, 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);
@ -135,8 +136,9 @@ namespace
EXPECT_EQ(dp4.next().val(), mUp1.val() * mS2p.val());
EXPECT_EQ(dp5.first().val(), mUp2.val() * mUp1.val());
EXPECT_EQ(dp5.next().val(), mS4p.val() * mUp1.val());
}
*/
}
}
int main(int argc, char** argv)