more on pos type (not finished/checked/debugged)

This commit is contained in:
Christian Zimmermann 2022-09-27 20:32:26 +02:00
parent cc52e86526
commit 321d6cd8fa
9 changed files with 1124 additions and 438 deletions

View file

@ -81,26 +81,44 @@ namespace CNORXZ
template <typename T>
class Allocator;
// definition: ranges/xfor/exttype.h
class VPosBase;
// definition: ranges/xfor/pos_type.h
template <class PosT>
class CPosInterface;
// definition: ranges/xfor/exttype.h
// definition: ranges/xfor/pos_type.h
template <class PosT>
class PosInterface;
// definition: ranges/xfor/exttype.h
class DPos;
// definition: ranges/xfor/pos_type.h
class VPosBase;
// definition: ranges/xfor/exttype.h
// definition: ranges/xfor/pos_type.h
template <class PosT>
class VPos;
// definition: ranges/xfor/exttype.h
// definition: ranges/xfor/pos_type.h
template <class PosT>
class VPosRef;
// definition: ranges/xfor/pos_type.h
class DPos;
// definition: ranges/xfor/pos_type.h
class DPosRef;
// definition: ranges/xfor/pos_type.h
template <class PosT>
class MPos;
// definition: ranges/xfor/exttype.h
class NPos;
// definition: ranges/xfor/pos_type.h
template <class PosT>
class FMPos;
// definition: ranges/xfor/pos_type.h
class UPos;
// definition: ranges/xfor/pos_type.h
class FPos;
// definition: ranges/range_base.h
class RangeBase;
@ -172,6 +190,10 @@ namespace CNORXZ
// there should be also a static analogue
// definition: ranges/lindex.h
template <class Index>
class LIndex;
/*********************
* derived types *
*********************/

View file

@ -36,7 +36,6 @@ namespace CNORXZ
SizeT dim() const; // = 1
Sptr<RangeType> range() const;
SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const;
SizeT meta() const;

View file

@ -0,0 +1,36 @@
#include "lindex.h"
namespace CNORXZ
{
template <class Index, SizeT L>
LIndex<Index,L>::LIndex(const Index& i) :
Index(i) {}
template <class Index, SizeT L>
LIndex<Index,L>::LIndex(Index&& i) :
Index(i) {}
template <class Index, SizeT L>
template <SizeT L1>
auto LIndex<Index,L>::getStaticStepSize(PtrId iptr) const
{
if constexpr(L == 0 or L1 == 0){
return this->getStepSize(iptr);
}
else {
if constexpr(L == L1){
CXZ_ASSERT(iptr == this->ptrId(),
"got two different indices with the same static label " << L);
return SPos<1>();
}
else {
CXZ_ASSERT(iptr == this->ptrId(),
"got two equal indices with the different static label " << L
<< " and " << L1);
return SPos<0>();
}
}
}
}

View file

@ -0,0 +1,29 @@
#ifndef __cxz_lindex_h__
#define __cxz_lindex_h__
#include "base/base.h"
#include "ranges/index_base.h"
#include "ranges/range_base.h"
namespace CNORXZ
{
// static label to enforce loop unrolling
template <class Index, SizeT L>
class LIndex : public Index
{
public:
typedef Index::IB IB;
typedef Index::RangeType RangeType;
DEFAULT_MEMBERS(LIndex);
LIndex(const Index& i);
LIndex(Index&& i);
template <SizeT L1>
auto getStaticStepSize(PtrId iptr) const;
};
}
#endif

View file

@ -1,427 +0,0 @@
#ifndef __cxz_exttype_h__
#define __cxz_exttype_h__
#include "base/base.h"
namespace CNORXZ
{
// Dynamic Ext: ObjHandl<ExtBase>
// In For Expr: try to resolve until some upper limit
class VPosBase
{
public:
DEFAULT_MEMBERS(VPosBase);
virtual Uptr<VPosBase> copy() const = 0;
virtual SizeT vsize() const = 0;
virtual const SizeT& vval() const = 0;
virtual const VPosBase* vnext() const = 0;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vtimes(SizeT a) const = 0;
virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const FPos& a) const = 0;
};
template <class PosT>
class CPosInterface
{
public:
DEFAULT_MEMBERS(CPosInterface);
PosT& THIS() { return static_cast<PosT&>(*this); }
const PosT& THIS() const { return static_cast<const PosT&>(*this); }
inline SizeT size() const { return THIS().size(); }
inline const SizeT& val() const { return THIS().val(); }
inline const auto& next() const { return THIS().next(); }
inline bool operator==(const CPosInterface<PosT>& a) const { return val() == a.val() and next() == a.next(); }
inline bool operator!=(const CPosInterface<PosT>& a) const { return val() != a.val() or next() != a.next(); }
inline bool operator==(SizeT a) const { return val() == a and next() == a; }
inline bool operator!=(SizeT a) const { return val() != a or next() != a; }
inline CPosInterface<PosT> operator+(const CPosInterface<PosT>& a) const
{ return THIS() + a.THIS(); }
inline CPosInterface<PosT> operator*(SizeT a) const { return THIS() * a; }
template <class P>
inline auto extend(const CPosInterface<P>& a) const { return THIS().extend(a); }
};
template <class PosT>
class PosInterface : public CPosInterface<PosT>
{
public:
typedef CPosInterface<PosT> PI;
DEFAULT_MEMBERS(PosInterface);
template <class PosT1, class PosT2>
inline PosInterface& set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b, sizeT c)
{ return PI::THIS().set(a,b,c); }
template <class PosT1, class PosT2>
inline PosInterface& operator()(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b, sizeT c)
{ return set(a,b,c); }
};
template <class PosT>
class VPos : public VPosBase, public PosT
{
private:
VPosRef<decltype(THIS::next())> mNextRef;
public:
DEFAULT_MEMBERS(VPos);
VPos(const PosInterface<PosT>& a) : PosT(a.THIS()), mNextRef(&PosT::THIS().next()) {}
virtual Uptr<VPosBase> copy() const override final { return std::make_unique<VPos>(*this); }
virtual SizeT vsize() const override final { return PosT::THIS().size(); }
virtual const SizeT& vval() const override final { return PosT::THIS().val(); }
virtual const VPosRef& vnext() const override final
{ return mNextRef; }
virtual Uptr<VPosBase> vextend(const DPos& a) const override final
{ return std::make_unique<VPos<decltype(PosT::THIS().extend(a))>>
( PosT::THIS().extend(a) ); }
virtual Uptr<VPosBase> vextend(const UPos& a) const override final
{ return std::make_unique<VPos<decltype(PosT::THIS().extend(a))>>
( PosT::THIS().extend(a) ); } // ??? if that works it would be a miracle ???
virtual Uptr<VPosBase> vextend(const FPos& a) const override final
{ return std::make_unique<VPos<decltype(PosT::THIS().extend(a))>>
( PosT::THIS().extend(a) ); } // ??? if that works it would be a miracle ???
// .... probably I need to define a static instanciation limit...
};
template <class PosT>
class VPosRef : public VPosBase
{
private:
const PosT* mC;
public:
DEFAULT_MEMBERS(VPosRef);
VPosRef(const PosT* c) : mC(c) {}
};
// defined as empty since they should never instanciated
template <>
class VPos<DPos>
{};
// defined as empty since they should never instanciated
template <>
class VPos<DPosRef>
{};
class DPosRef : public CPosInterface<DPosRef>
{
private:
DPosRef mNextRef;
const VPosBase* mC;
public:
DEFAULT_MEMBERS(DPosRef);
DPosRef(const VPosBase* c) : mC(c), mNextRef(mC->vnext()) {}
const T& operator*() const { return *mC; }
const T* operator->() const { return mC; }
inline sizeT size() const { return mC->vsize(); }
inline const SizeT& val() const { return mC->vsize(); }
inline const DPosRef& next() const { return mNextRef; }
template <class PosT2>
inline auto operator+(const MPos<PosT2>& a) const
{ return MPos<PosT2>(val()+a.val(), next()+a.next()); }
inline auto operator+(const UPos& a) const
{ return UPos(val()+a.val()); }
inline auto operator+(const DPos& a) const
{ return DPos((*mC)+(*a)); }
inline auto operator+(const DPosRef& a) const
{ return DPos((*mC)+(*a)); }
inline auto operator*(SizeT a) const
{ return DPos((*mC)*a); }
};
class DPos : public ObjHandle<VPosBase>,
public PosInterface<DPos>
{
private:
DPosRef mNextRef;
public:
DEFAULT_MEMBERS(DPos);
DPos(Uptr<VPosBase>&& a) :
ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a)),
mNextRef(mC->next())
{}
template <class PosT>
DPos(const PosT& a) : ObjHandle<VPosBase>( std::make_unique<PosT>(a) ) {}
inline SizeT size() const { return mC->vsize(); }
inline const SizeT& val() const { return mC->vval(); }
inline const DPosRef& next() const { return mNextRef; }
template <class PosT2>
inline auto operator+(const MPos<PosT2>& a) const
{ return MPos<PosT2>(val()+a.val(), next()+a.next()); }
inline auto operator+(const UPos& a) const
{ return UPos(mC->val() + a.val()); }
inline auto operator+(const DPos& a) const
{ return DPos((*mC) + (*a)); }
inline auto operator+(const DPosRef& a) const
{ return DPos((*mC) + (*a)); }
inline auto operator*(SizeT a) const
{ return DPos((*mC)*a); }
template <class PosT1, class PosT2>
inline PosInterface& set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b, sizeT c)
{ mC->setVal( a.val() + b.val()*c ) ; mC->vnext()->set(a.next(),b.next(),c); return *this; }
};
template <class PosT>
class MPos
{
private:
SizeT mExt = 0u;
PosT mNext;
public:
//static constexpr SizeT NUM = PosT::SIZE;
//static constexpr SizeT SIZE = NUM + 1;
DEFAULT_MEMBERS(MPos);
inline MPos(SizeT ext, PosT next);
template <class PosT1>
inline MPos(SizeT y, const CPosInterface<PosT1>& z);
template <class PosT1, class PosT2>
inline MPos(const CPosInterface<PosT1>& y, const CPosInterface<PosT2>& z);
template <class PosT1>
inline MPos(const MPos<PosT1>& y);
inline const SizeT& val() const;
inline const PosT& next() const;
inline auto operator+(const MPos& in) const;
//inline MPos operator+(const UPos& in) const;
inline auto operator*(SizeT in) const;
template <class PosT1>
inline auto extend(const PosInterface<PosT1>& y) const -> MPos<decltype(mNext.extend(y))>
{ return MPos<decltype(mNext.extend(y))>(mExt, mNext.extend(y)); }
template <class PosT1, class PosT2>
inline PosInterface& set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b, sizeT c)
{ return *this = a + b*c; }
//{ mExt = a.val() + b.val()*c ; mNext.set(a.next(),b.next(),c); return *this; }
};
template <class PosT>
class FMPos : public PosInterface<FMPos<PosT>>
{
private:
SizeT mExt = 0;
const Vector<SizeT>* mMap;
PosT mNext;
public:
DEFAULT_MEMBERS(FMPos);
template <class PosT2>
inline auto operator+(const PosT2& a) const { return MPos(mExt,mNext) + a; }
inline auto operator*(SizeT a) const { return MPos(mExt*(*mMap)[a], mNext*a); }
};
class UPos : public PosInterface<UPos>
{
private:
SizeT mExt = 0;
public:
DEFAULT_MEMBERS(NPos);
template <class Y>
NPos(const Y& y) {}
//static constexpr SizeT SIZE = 0;
inline const SizeT& val() const { return mExt; }
inline SizeT size() const { return 1; }
inline const SizeT& next() { static SizeT dummy = 0; return dummy; }
inline UPos operator+(const UPos& in) const { return UPos(mExt + in.val()); }
inline UPos operator*(size_t in) const { return UPos(mExt * in); }
template <class Y>
inline auto extend(const Y& y) const
{ return MPos<Y>(mExt, y); }
};
class FPos : public PosInterface<FPos>
{
private:
SizeT mExt = 0;
const Vector<SizeT>* mMap;
public:
DEFAULT_MEMBERS(FMPos);
template <class PosT2>
inline auto operator+(const PosT2& a) const { return UPos(mExt) + a; }
inline auto operator*(SizeT a) const { return UPos(mExt*(*mMap)[a]); }
};
inline MPos<NPos> mkExt(SizeT s) { return MPos<NPos>(s); }
/*
template <size_t I, class X>
auto getX(const MPos<X>& et)
{
if constexpr(I == 0){
return et;
}
else {
return getX<I-1>(et.next());
}
}
template <size_t I, class X>
auto getX(const DVPosX<X>& et)
{
if constexpr(I == 0){
return et;
}
else {
return getX<I-1>(et.next());
}
}
template <size_t I>
auto getX(const NPos& et)
{
static_assert(I == 0);
return et;
}
template <size_t I, class X>
size_t get(const MPos<X>& et)
{
return getX<I>(et).get();
}
template <size_t I, class X>
size_t get(const DVPosX<X>& et)
{
return getX<I>(et).get();
}
template <size_t I>
size_t get(const NPos& et)
{
return getX<I>(et).get();
}
*/
} // end namespace CNORXZInternal
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
namespace CNORXZ
{
template <class X>
inline MPos<X>::MPos(size_t ext, X next) : mExt(ext), mNext(next) {}
/*
template <class X>
template <size_t N>
inline MPos<X>::MPos(const std::array<size_t,N>& arr) :
mExt(std::get<NUM>(arr)), mNext(arr) {}
*/
template <class X>
template <class Z>
inline MPos<X>::MPos(size_t y, const Z& z) :
mExt(z.val()), mNext(z.val(), z.next()) {}
template <class X>
template <class Y, class Z>
inline MPos<X>::MPos(const Y& y, const Z& z) :
mExt(y.val()), mNext(y.next(), z) {}
template <class X>
template <class Y>
inline MPos<X>::MPos(const MPos<Y>& y) :
mExt(y.val()), mNext(y.next()) {}
template <class X>
inline const size_t& MPos<X>::val() const
{
return mExt;
}
template <class X>
inline const X& MPos<X>::next() const
{
return mNext;
}
template <class X>
inline void MPos<X>::zero()
{
mExt = 0u;
mNext.zero();
}
/*
template <class X>
template <size_t N>
inline auto MPos<X>::nn() const
{
return getX<N>(*this);
}
*/
template <class X>
inline MPos<X> MPos<X>::operator+(const MPos<X>& in) const
{
return MPos<X>(mExt + in.val(), mNext + in.next());
}
template <class X>
inline MPos<X> MPos<X>::operator+(const UPos& in) const
{
return MPos<X>(mExt + in.val(), mNext);
}
template <class X>
inline MPos<X> MPos<X>::operator*(SizeT in) const
{
return MPos<X>(mExt * in, mNext * in);
}
} // end namespace CNORXZInternal
#endif

View file

@ -0,0 +1,382 @@
#ifndef __cxz_pos_type_cc_h__
#define __cxz_pos_type_cc_h__
#include "pos_type.h"
namespace CNORXZ
{
/************
* SPos *
************/
template <SizeT N>
constexpr SizeT SPos<N>::size() const
{
return 1;
}
template <SizeT N>
constexpr SizeT SPos<N>::val() const
{
return N;
}
template <SizeT N>
template <SizeT N1>
constexpr auto SPos<N>::operator+(const SPos<N1>& a) const
{
return SPos<N+N1>();
}
template <SizeT N>
template <SizeT N1>
constexpr auto SPos<N>::operator*(const SPos<N1>& a) const
{
return SPos<N*N1>();
}
template <SizeT N>
constexpr auto SPos<N>::operator+(const UPos& a) const
{
return UPos(N+a.val());
}
template <SizeT N>
constexpr auto SPos<N>::operator*(const UPos& a) const
{
return UPos(N*a.val());
}
template <SizeT N>
template <class PosT>
constexpr auto SPos<N>::extend(const CPosInterface<PosT>& a) const
{
return MPos<SPos<N>,PosT>(*this,a);
}
/************
* UPos *
************/
constexpr UPos::UPos(SizeT ext) : mExt(ext) {}
inline SizeT UPos::size() const
{
return 1;
}
inline const SizeT& UPos::val() const
{
return mExt;
}
template <class PosT>
constexpr UPos UPos::operator+(const CPosInterface<PosT>& in) const
{
return UPos(mExt + in.val());
}
template <class PosT>
constexpr UPos UPos::operator*(const CPosInterface<PosT>& in) const
{
return UPos(mExt * in.val());
}
template <class PosT>
constexpr auto UPos::extend(const CPosInterface<PosT>& p1) const
{
return MPos<UPos,PosT>(*this, p1);
}
template <class PosT1, class PosT2, class PosT3>
inline UPos& UPos::set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c)
{
(*this) = a + b*c;
return *this;
}
/************
* FPos *
************/
inline FPos::FPos(SizeT ext, const SizeT* map) : mExt(ext), mMap(map) {}
constexpr SizeT FPos::size() const
{
return 1;
}
inline const SizeT& FPos::val() const
{
return mExt;
}
template <class PosT1>
inline UPos FPos::operator+(const CPosInterface<PosT1>& a) const
{
return UPos(mExt + a.val());
}
inline UPos FPos::operator*(const CPosInterface<PosT1>& a) const
{
return UPos(mExt * mMap[a.val()]);
}
template <class PosT1>
inline auto FPos::extend(const CPosInterface<PosT1>& a) const
{
return MPos<FPos,PosT>(*this,a);
}
/*************
* SFPos *
*************/
template <SizeT N, SizeT... Ms>
constexpr SizeT SFPos<N,Ms...>::size() const
{
return 1;
}
template <SizeT N, SizeT... Ms>
constexpr SizeT SFPos<N,Ms...>::val() const
{
return N;
}
template <SizeT N, SizeT... Ms>
template <SizeT N1>
constexpr auto SFPos<N,Ms...>::operator+(const SPos<N1>& a) const
{
return SPos<N+N1>();
}
template <SizeT N, SizeT... Ms>
template <SizeT N1>
constexpr auto SFPos<N,Ms...>::operator*(const SPos<N1>& a) const
{
static constexpr Array<sizeof...(Ms)> ms({ Ms... });
return SPos<N*std::get<a.val()>(ms)>;
}
template <SizeT N, SizeT... Ms>
constexpr auto SFPos<N,Ms...>::operator+(const UPos& a) const
{
return UPos(N + a.val());
}
template <SizeT N, SizeT... Ms>
constexpr auto SFPos<N,Ms...>::operator*(const UPos& a) const
{
static constexpr Array<sizeof...(Ms)> ms({ Ms... });
return UPos(N * ms[a.val()]);
}
template <SizeT N, SizeT... Ms>
template <class PosT>
constexpr auto SFPos<N,Ms...>::extend(const CPosInterface<PosT>& a) const
{
return MPos<SFPos<N,Ms...>,PosT>(*this,a);
}
/************
* DPos *
************/
inline DPos::DPos(Uptr<VPosBase>&& a) :
ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a)),
mNextRef(mC->next())
{}
template <class PosT>
inline DPos::DPos(const PosT& a) :
ObjHandle<VPosBase>( std::make_unique<PosT>(a) )
{}
inline SizeT DPos::size() const
{
return mC->vsize();
}
inline const SizeT& DPos::val() const
{
return mC->vval();
}
inline const DPosRef& DPos::next() const
{
return mNextRef;
}
template <class PosT2>
inline auto DPos::operator+(const MPos<PosT2>& a) const
{
return MPos<PosT2>(val()+a.val(), next()+a.next());
}
inline auto DPos::operator+(const UPos& a) const
{
return UPos(mC->val() + a.val());
}
inline auto DPos::operator+(const DPos& a) const
{
return DPos((*mC) + (*a));
}
inline auto DPos::operator+(const DPosRef& a) const
{
return DPos((*mC) + (*a));
}
inline auto DPos::operator*(SizeT a) const
{
return DPos((*mC)*a);
}
template <class PosT1>
inline DPos DPos::extend(const PosT1& a) const
{
Uptr<VPosBase> out = mC->vextend()
}
template <class PosT1, class PosT2>
inline PosInterface& DPos::set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b, sizeT c)
{
mC->setVal( a.val() + b.val()*c ) ;
mC->vnext()->set(a.next(),b.next(),c);
return *this;
}
/***************
* DPosRef *
***************/
inline DPosRef::DPosRef(const VPosBase* c) :
mC(c), mNextRef(mC->vnext())
{}
inline const T& DPosRef::operator*() const
{
return *mC;
}
inline const T* DPosRef::operator->() const
{
return mC;
}
inline sizeT DPosRef::size() const
{
return mC->vsize();
}
inline const SizeT& DPosRef::val() const
{
return mC->vsize();
}
inline const DPosRef& DPosRef::next() const
{
return mNextRef;
}
template <class PosT2>
inline auto DPosRef::operator+(const MPos<PosT2>& a) const
{
return MPos<PosT2>(val()+a.val(), next()+a.next());
}
inline auto DPosRef::operator+(const UPos& a) const
{
return UPos(val()+a.val());
}
inline auto DPosRef::operator+(const DPos& a) const
{
return DPos((*mC)+(*a));
}
inline auto DPosRef::operator+(const DPosRef& a) const
{
return DPos((*mC)+(*a));
}
inline auto DPosRef::operator*(SizeT a) const
{
return DPos((*mC)*a);
}
/************
* MPos *
************/
template <class PosT>
inline MPos<PosT>::MPos(SizeT ext, PosT next) : mExt(ext), mNext(next) {}
template <class PosT>
template <class PosT1>
inline MPos<PosT>::MPos(SizeT y, const PosT1& z) :
mExt(z.val()), mNext(z.val(), z.next()) {}
template <class PosT>
template <class PosT1, class PosT2>
inline MPos<PosT>::MPos(const PosT1& y, const PosT2& z) :
mExt(y.val()), mNext(y.next(), z) {}
template <class PosT>
template <class PosT1>
inline MPos<PosT>::MPos(const MPos<PosT1>& y) :
mExt(y.val()), mNext(y.next()) {}
template <class PosT>
inline const SizeT& MPos<PosT>::val() const
{
return mExt;
}
template <class PosT>
inline const PosT& MPos<PosT>::next() const
{
return mNext;
}
template <class PosT>
inline MPos<PosT> MPos<PosT>::operator+(const MPos<PosT>& in) const
{
return MPos<PosT>(mExt + in.val(), mNext + in.next());
}
template <class PosT>
inline MPos<PosT> MPos<PosT>::operator+(const UPos& in) const
{
return MPos<PosT>(mExt + in.val(), mNext);
}
template <class PosT>
inline MPos<PosT> MPos<PosT>::operator*(SizeT in) const
{
return MPos<PosT>(mExt * in, mNext * in);
}
template <class PosT>
template <class PosT1>
inline auto MPos<PosT>::extend(const PosInterface<PosT1>& y) const
{ return MPos<decltype(mNext.extend(y))>(mExt, mNext.extend(y)); }
template <class PosT>
template <class PosT1, class PosT2>
inline PosInterface& MPos<PosT>::set(const CPosInterface<PosT1>& a,
const CPosInterface<PosT2>& b, sizeT c)
{ return *this = a + b*c; }
//{ mExt = a.val() + b.val()*c ; mNext.set(a.next(),b.next(),c); return *this; }
}
#endif

View file

@ -0,0 +1,238 @@
#ifndef __cxz_pos_type_h__
#define __cxz_pos_type_h__
#include "base/base.h"
namespace CNORXZ
{
template <class PosT>
class CPosInterface
{
public:
DEFAULT_MEMBERS(CPosInterface);
PosT& THIS() { return static_cast<PosT&>(*this); }
const PosT& THIS() const { return static_cast<const PosT&>(*this); }
inline SizeT size() const { return THIS().size(); }
inline auto val() const { return THIS().val(); }
inline CPosInterface<PosT> operator+(const CPosInterface<PosT>& a) const
{ return THIS() + a.THIS(); }
inline CPosInterface<PosT> operator*(const CPosInterface<PosT>& a) const
{ return THIS() * a.THIS(); }
template <class P>
inline auto extend(const CPosInterface<P>& a) const { return THIS().extend(a); }
};
template <class PosT>
class PosInterface : public CPosInterface<PosT>
{
public:
typedef CPosInterface<PosT> PI;
DEFAULT_MEMBERS(PosInterface);
template <class PosT1, class PosT2>
inline PosInterface& set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c)
{ return PI::THIS().set(a,b,c); }
template <class PosT1, class PosT2>
inline PosInterface& operator()(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c)
{ return set(a,b,c); }
};
template <SizeT N>
class SPos : public CPosInterface<SPos>
{
public:
constexpr SPos() = default;
constexpr SizeT size() const;
constexpr SizeT val() const;
template <SizeT N1>
constexpr auto operator+(const SPos<N1>& a) const;
template <SizeT N1>
constexpr auto operator*(const SPos<N1>& a) const;
constexpr auto operator+(const UPos& a) const;
constexpr auto operator*(const UPos& a) const;
template <class PosT>
constexpr auto extend(const CPosInterface<PosT>& a) const;
};
class UPos : public PosInterface<UPos>
{
private:
SizeT mExt = 0;
public:
DEFAULT_MEMBERS(UPos);
constexpr UPos(SizeT ext);
inline SizeT size() const;
inline const SizeT& val() const;
template <class PosT>
constexpr UPos operator+(const CPosInterface<PosT>& a) const;
template <class PosT>
constexpr UPos operator*(const CPosInterface<PosT>& a) const;
template <class PosT>
constexpr auto extend(const CPosInterface<PosT>& y) const;
template <class PosT1, class PosT2, class PosT3>
inline UPos& set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c);
};
class FPos : public CPosInterface<FPos>
{
private:
SizeT mExt = 0;
const SizeT* mMap = nullptr;
public:
DEFAULT_MEMBERS(FPos);
inline FPos(SizeT ext, const SizeT* map);
constexpr SizeT size() const;
inline const SizeT& val() const;
template <class PosT1>
inline UPos operator+(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline UPos operator*(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline auto extend(const CPosInterface<PosT1>& a) const;
};
template <SizeT N, SizeT... Ms>
class SFPos : public CPosInterface<SFPos>
{
public:
constexpr SFPos() = default;
constexpr SizeT size() const;
constexpr SizeT val() const;
template <SizeT N1>
constexpr auto operator+(const SPos<N1>& a) const;
template <SizeT N1>
constexpr auto operator*(const SPos<N1>& a) const;
constexpr auto operator+(const UPos& a) const;
constexpr auto operator*(const UPos& a) const;
template <class PosT>
constexpr auto extend(const CPosInterface<PosT>& a) const;
};
class DPos : public ObjHandle<VPosBase>,
public PosInterface<DPos>
{
private:
DPosRef mNextRef;
public:
DEFAULT_MEMBERS(DPos);
inline DPos(Uptr<VPosBase>&& a);
template <class PosT>
inline DPos(const PosT& a);
inline SizeT size() const;
inline const SizeT& val() const;
inline const DPosRef& next() const;
template <class PosT2>
inline auto operator+(const MPos<PosT2>& a) const;
inline auto operator+(const UPos& a) const;
inline auto operator+(const DPos& a) const;
inline auto operator+(const DPosRef& a) const;
inline auto operator*(SizeT a) const;
template <class PosT1>
inline DPos extend(const PosT1& a) const;
template <class PosT1, class PosT2>
inline PosInterface& set(const CPosInterface<PosT1>& a,
const CPosInterface<PosT2>& b, sizeT c);
};
class DPosRef : public CPosInterface<DPosRef>
{
private:
DPosRef mNextRef;
const VPosBase* mC;
public:
DEFAULT_MEMBERS(DPosRef);
inline DPosRef(const VPosBase* c);
inline const T& operator*() const;
inline const T* operator->() const;
inline sizeT size() const;
inline const SizeT& val() const;
inline const DPosRef& next() const;
template <class PosT2>
inline auto operator+(const MPos<PosT2>& a) const;
inline auto operator+(const UPos& a) const;
inline auto operator+(const DPos& a) const;
inline auto operator+(const DPosRef& a) const;
inline auto operator*(SizeT a) const;
template <class PosT1>
inline DPos extend(const PosT1& a) const;
};
template <class PosT1, class PosT2>
class MPos : public PosInterface<MPos<PosT1,PosT2>>
{
private:
PosT1 mFirst;
PosT2 mNext;
public:
//static constexpr SizeT NUM = PosT::SIZE;
//static constexpr SizeT SIZE = NUM + 1;
DEFAULT_MEMBERS(MPos);
constexpr MPos(const CPosInterface<PosT1>& first,
const CPosInterface<PosT2>& next);
inline const SizeT& val() const;
inline const PosT& next() const;
inline auto operator+(const MPos& in) const;
inline auto operator*(SizeT in) const;
template <class PosT3>
inline auto extend(const PosInterface<PosT3>& y) const;
template <class PosT3, class PosT4>
inline PosInterface& set(const CPosInterface<PosT3>& a,
const CPosInterface<PosT4>& b, sizeT c);
};
} // end namespace CNORXZInternal
#endif

View file

@ -0,0 +1,262 @@
#ifndef __cxz_vpos_type_cc_h__
#define __cxz_vpos_type_cc_h__
#include "vpos_type.h"
namespace CNORXZ
{
/****************
* VPosBase *
****************/
template <SizeT N>
UPtr<VPosBase> VPosBase::vextend(const SPos<N>& a) const
{
return this->vextend(UPos(N));
}
/************
* VPos *
************/
template <class PosT>
VPos<PosT>::VPos(const PosInterface<PosT>& a) :
PosT(a.THIS()),
{}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::copy() const
{
return std::make_unique<VPos>(*this);
}
template <class PosT>
SizeT VPos<PosT>::vsize() const
{
return PosT::THIS().size();
}
template <class PosT>
const SizeT& VPos<PosT>::vval() const
{
return PosT::THIS().val();
}
template <class PosT>
const VPosBase* VPos<PosT>::vget() const
{
return this;
}
template <class PosT>
const VPosBase* VPos<PosT>::vnext() const
{
return nullptr;
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPos& a) const
{
return std::make_unique<MPos<PosT,DPos>>(*this,a);
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const UPos& a) const
{
return std::make_unique<MPos<PosT,UPos>>(*this,a);
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const FPos& a) const
{
return std::make_unique<MPos<PosT,FPos>>(*this,a);
}
// .... probably I need to define a static instanciation limit...
/******************
* VPos<MPos> *
******************/
template <class PosT1, class PosT2>
VPos<MPos<PosT1,PosT2>>::VPos(const PosInterface<MPos<PosT1,PosT2>>& a) :
MPos<PosT1,PosT2>(a.THIS()),
mFRef(&mFirst), mNRef(&mNext)
{}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::copy() const
{
return std::make_unique<MPos<PosT1,PosT2>>(*this);
}
template <class PosT1, class PosT2>
SizeT VPos<MPos<PosT1,PosT2>>::vsize() const
{
return this->size();
}
template <class PosT1, class PosT2>
SizeT VPos<MPos<PosT1,PosT2>>::vval() const
{
return this->val();
}
template <class PosT1, class PosT2>
const VPosBase* VPos<MPos<PosT1,PosT2>>::vget() const
{
return mFRef;
}
template <class PosT1, class PosT2>
const VPosBase* VPos<MPos<PosT1,PosT2>>::vnext() const
{
return mNRef;
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{
return std::make_unique<MPos<MPosT,DPos>>(*this,a);
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{
return std::make_unique<MPos<MPosT,DPosRef>>(*this,a);
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{
return std::make_unique<MPos<MPosT,UPos>>(*this,a);
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
{
return std::make_unique<MPos<MPosT,FPos>>(*this,a);
}
/***************
* VPosRef *
***************/
template <class PosT>
VPosRef<PosT>::VPosRef(const PosT* c) :
mC(c), mNextRef(&mC->next())
{}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::copy() const
{
return std::make_unique<VPos<PosT>>(*mC);
}
template <class PosT>
SizeT VPosRef<PosT>::vsize() const
{
return mC->size();
}
template <class PosT>
const SizeT& VPosRef<PosT>::vval() const
{
return mC->val();
}
template <class PosT>
const VPosBase& VPosRef<PosT>::vget() const
{
return this;
}
template <class PosT>
const VPosBase& VPosRef<PosT>::vnext() const
{
return nullptr;
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPos& a) const
{
return std::make_unique<MPos<PosT,DPos>>(*mC,a);
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const UPos& a) const
{
return std::make_unique<MPos<PosT,UPos>>(*mC,a);
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const FPos& a) const
{
return std::make_unique<MPos<PosT,FPos>>(*mC,a);
}
/*********************
* VPosRef<MPos> *
*********************/
template <class PosT1, class PosT2>
VPosRef<MPos<PosT1,PosT2>>::VPosRef(const PosT* c) :
mC(c), mFRef(&c->get()), mNRef(&c->next())
{}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::copy() const
{
return std::make_unique<MPos<PosT1,PosT2>>(*mFRef,*mNRef);
}
template <class PosT1, class PosT2>
SizeT VPosRef<MPos<PosT1,PosT2>>::vsize() const
{
return mC->size();
}
template <class PosT1, class PosT2>
SizeT VPosRef<MPos<PosT1,PosT2>>::vval() const
{
return mC->val();
}
template <class PosT1, class PosT2>
const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vget() const
{
return mFRef;
}
template <class PosT1, class PosT2>
const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vnext() const
{
return mNRef;
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{
return std::make_unique<MPos<MPosT,DPos>>(*mC,a);
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{
return std::make_unique<MPos<MPosT,DPosRef>>(*mC,a);
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{
return std::make_unique<MPos<MPosT,UPos>>(*mC,a);
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
{
return std::make_unique<MPos<MPosT,FPos>>(*mC,a);
}
}
#endif

View file

@ -0,0 +1,145 @@
#ifndef __cxz_vpos_type_h__
#define __cxz_vpos_type_h__
#include "base/base.h"
namespace CNORXZ
{
class VPosBase
{
public:
DEFAULT_MEMBERS(VPosBase);
virtual Uptr<VPosBase> copy() const = 0;
virtual SizeT vsize() const = 0;
virtual const SizeT& vval() const = 0;
virtual const VPosBase* vget() const = 0;
virtual const VPosBase* vnext() const = 0;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vtimes(SizeT 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
{
return this->vextend(UPos(N));
}
};
template <class PosT>
class VPos : public VPosBase, public PosT
{
public:
DEFAULT_MEMBERS(VPos);
VPos(const PosInterface<PosT>& a);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() 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;
};
template <class PosT1, class PosT2>
class VPos<MPos<PosT1,PosT2>> : public VPosBase, public MPos<PosT1,PosT2>
{
private:
VPosRef<PosT1> mFRef;
VPosRef<PosT2> mNRef;
public:
typedef MPos<PosT1,PosT2> MPosT;
DEFAULT_MEMBERS(VPos);
VPos(const PosInterface<MPos<PosT1,PosT2>>& a);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() 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;
};
template <class PosT>
class VPosRef : public VPosBase
{
private:
const PosT* mC = nullptr;
public:
DEFAULT_MEMBERS(VPosRef);
VPosRef(const PosT* c);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() 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;
};
template <class PosT1, class PosT2>
class VPosRef<MPos<PosT1,PosT2>> : public VPosBase
{
private:
const MPos<PosT1,PosT2>* mC = nullptr;
VPosRef<PosT1> mFRef;
VPosRef<PosT2> mNRef;
public:
typedef MPos<PosT1,PosT2> MPosT;
DEFAULT_MEMBERS(VPosRef);
VPosRef(const PosT* c);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() 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;
};
// defined as empty since they should never instanciated
template <>
class VPos<DPos>
{};
// defined as empty since they should never instanciated
template <>
class VPosRef<DPos>
{};
// defined as empty since they should never instanciated
template <>
class VPos<DPosRef>
{};
// defined as empty since they should never instanciated
template <>
class VPosRef<DPosRef>
{};
}
#endif