index_base.cc.h

This commit is contained in:
Christian Zimmermann 2022-09-11 15:20:27 +02:00
parent 3463e6ceea
commit bc4ebf317b
2 changed files with 147 additions and 143 deletions

View file

@ -0,0 +1,115 @@
#ifndef __cxz_index_base_cc_h__
#define __cxz_index_base_cc_h__
#include "index_base.h"
namespace CNORXZ
{
/**********************
* IndexInterface *
**********************/
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface()
{
mPtrNum = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(const IndexInterface& in) :
mRangePtr(in.mRangePtr), mPos(in.mPos), mMax(in.mMax)
{
mPtrNum = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(IndexInterface&& in) :
mRangePtr(in.mRangePtr), mPos(in.mPos), mMax(in.mMax)
{
mPtrNum = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>& IndexInterface<I,MetaType>::operator=(const IndexInterface& in)
{
mRangePtr = in.mRangePtr;
mPos = in.mPos;
mMax = in.mMax;
return *this;
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>& IndexInterface<I,MetaType>::operator=(IndexInterface&& in)
{
mRangePtr = in.mRangePtr;
mPos = in.mPos;
mMax = in.mMax;
return *this;
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(const RangePtr& range, SizeT pos) :
mRangePtr(range), mPos(pos), mMax(mRangePtr->size())
{
mPtrNum = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator==(const IndexInterface& in) const
{
return in.mPos == mPos and in.mRangePtr.get() == mRangePtr.get();
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator!=(const IndexInterface& in) const
{
return in.mPos != mPos or in.mRangePtr.get() != mRangePtr.get();
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator<(const IndexInterface& in) const
{
return mPos < in.mPos;
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator>(const IndexInterface& in) const
{
return mPos > in.mPos;
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator<=(const IndexInterface& in) const
{
return mPos <= in.mPos;
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator>=(const IndexInterface& in) const
{
return mPos >= in.mPos;
}
template <class I, typename MetaType>
SizeT IndexInterface<I,MetaType>::pos() const
{
return mPos;
}
template <class I, typename MetaType>
SizeT IndexInterface<I,MetaType>::max() const
{
return mMax;
}
template <class I, typename MetaType>
PtrId IndexInterface<I,MetaType>::ptrId() const
{
// if this assert never applies, remove mPtrId (-> Defaults) !!!
assert(mPtrId == reinterpret_cast<PtrId>(this));
return mPtrId;
}
}
#endif

View file

@ -3,14 +3,8 @@
#ifndef __cxz_index_base_h__ #ifndef __cxz_index_base_h__
#define __cxz_index_base_h__ #define __cxz_index_base_h__
#include <cstdlib> #include "base/base.h"
#include <string>
#include <vector>
#include "rbase_def.h"
#include "range_base.h" #include "range_base.h"
#include "index_type.h"
#include "xfor/xfor.h" #include "xfor/xfor.h"
namespace CNORXZ namespace CNORXZ
@ -20,173 +14,68 @@ namespace CNORXZ
class IndexInterface class IndexInterface
{ {
public: public:
//typedef typename I::RangeType RangeType;
//DEFAULT_MEMBERS(IndexInterface);
I& THIS() { return static_cast<I&>(*this); }
I const& THIS() const { return static_cast<I const&>(*this); }
~IndexInterface() = default; ~IndexInterface() = default;
constexpr IndexType type() const { return THIS().type(); } I& THIS() { return static_cast<I&>(*this); }
const I& THIS() const { return static_cast<const I&>(*this); }
I& operator=(size_t pos) { return THIS() = pos; } I& operator=(SizeT pos) { return THIS() = pos; }
I& operator++() { return THIS()++; } I& operator++() { return THIS()++; }
I& operator--() { return THIS()--;} I& operator--() { return THIS()--;}
int pp(std::intptr_t idxPtrNum) { return THIS().pp(idxPtrNum); } SizeT pos() const;
int mm(std::intptr_t idxPtrNum) { return THIS().mm(idxPtrNum); } SizeT max() const;
PtrId ptrId() const;
bool operator==(const IndexInterface& in) const; bool operator==(const IndexInterface& in) const;
bool operator!=(const IndexInterface& in) const; bool operator!=(const IndexInterface& in) const;
bool operator<(const IndexInterface& in) const;
bool operator>(const IndexInterface& in) const;
bool operator<=(const IndexInterface& in) const;
bool operator>=(const IndexInterface& in) const;
auto operator*() const { return THIS().operator*(); }
auto operator->() const { return THIS().operator->(); }
size_t dim() const { return THIS().dim(); } Int pp(PtrId idxPtrNum) { return THIS().pp(idxPtrNum); }
size_t pos() const; Int mm(PtrId idxPtrNum) { return THIS().mm(idxPtrNum); }
size_t max() const;
bool last() const { return THIS().last(); } SizeT dim() const { return THIS().dim(); }
bool first() const { return THIS().first(); } RangePtr range() const { return mRangePtr; }
SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); }
std::shared_ptr<RangeBase> range() const { return mRangePtr; } String stringMeta() const { return THIS().stringMeta(); }
size_t getStepSize(size_t n) const { return THIS().getStepSize(n); }
std::string stringMeta() const { return THIS().stringMeta(); }
MetaType meta() const { return THIS().meta(); } MetaType meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); } I& at(const MetaType& meta) { return THIS().at(meta); }
// CHECK / IMPLEMENT !!!!!!
template <class Expr> template <class Expr>
auto ifor(size_t step, const Expr ex) const auto ifor(SizeT step, const Expr ex) const
-> decltype(THIS().template ifor<Expr>(step,ex))
{ return THIS().template ifor<Expr>(step,ex); } { return THIS().template ifor<Expr>(step,ex); }
template <class Expr> template <class Expr>
auto iforh(size_t step, const Expr ex) const auto iforh(SizeT step, const Expr ex) const
-> decltype(THIS().template iforh<Expr>(step,ex))
{ return THIS().template iforh<Expr>(step,ex); } { return THIS().template iforh<Expr>(step,ex); }
std::intptr_t ptrNum() const;
private: private:
friend I; friend I;
// NO DEFAULT CONSTRUCTORS/ASSIGNMENTS!
IndexInterface(); IndexInterface();
IndexInterface(const IndexInterface& in); IndexInterface(const IndexInterface& in);
IndexInterface& operator=(const IndexInterface& in); IndexInterface& operator=(const IndexInterface& in);
IndexInterface(IndexInterface&& in); IndexInterface(IndexInterface&& in);
IndexInterface& operator=(IndexInterface&& in); IndexInterface& operator=(IndexInterface&& in);
IndexInterface(const RangePtr& range, SizeT pos);
IndexInterface(const std::shared_ptr<RangeBase>& range, size_t pos); RangePtr mRangePtr = nullptr;
SizeT mPos = 0;
std::shared_ptr<RangeBase> mRangePtr; SizeT mMax = 0;
size_t mPos = 0; PtrId mPtrId = 0;
size_t mMax = 0;
std::intptr_t mPtrNum;
}; };
template <class Index>
std::shared_ptr<Index> mapResult(const std::shared_ptr<Index>& iptr)
{
return iptr;
}
template <class Index, typename MetaType> template <class Index, typename MetaType>
using IndexPtr = std::shared_ptr<IndexInterface<Index,MetaType>>; using IndexPtr = Sptr<IndexInterface<Index,MetaType>>;
} }
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
namespace CNORXZ
{
/**********************
* IndexInterface *
**********************/
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface()
{
mPtrNum = reinterpret_cast<std::intptr_t>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(const IndexInterface& in) : mRangePtr(in.mRangePtr),
mPos(in.mPos),
mMax(in.mMax)
{
mPtrNum = reinterpret_cast<std::intptr_t>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(IndexInterface&& in) : mRangePtr(in.mRangePtr),
mPos(in.mPos),
mMax(in.mMax)
{
mPtrNum = reinterpret_cast<std::intptr_t>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>& IndexInterface<I,MetaType>::operator=(const IndexInterface& in)
{
mRangePtr = in.mRangePtr;
mPos = in.mPos;
mMax = in.mMax;
return *this;
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>& IndexInterface<I,MetaType>::operator=(IndexInterface&& in)
{
mRangePtr = in.mRangePtr;
mPos = in.mPos;
mMax = in.mMax;
return *this;
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& range,
size_t pos) : mRangePtr(range),
mPos(pos),
mMax(mRangePtr->size())
{
mPtrNum = reinterpret_cast<std::intptr_t>(this);
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator==(const IndexInterface& in) const
{
return in.mPos == mPos and in.mRangePtr.get() == mRangePtr.get();
}
template <class I, typename MetaType>
bool IndexInterface<I,MetaType>::operator!=(const IndexInterface& in) const
{
return in.mPos != mPos or in.mRangePtr.get() != mRangePtr.get();
}
template <class I, typename MetaType>
size_t IndexInterface<I,MetaType>::pos() const
{
return mPos;
}
template <class I, typename MetaType>
size_t IndexInterface<I,MetaType>::max() const
{
return mMax;
}
template <class I, typename MetaType>
std::intptr_t IndexInterface<I,MetaType>::ptrNum() const
{
return mPtrNum;
}
}
#endif #endif