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__
#define __cxz_index_base_h__
#include <cstdlib>
#include <string>
#include <vector>
#include "rbase_def.h"
#include "base/base.h"
#include "range_base.h"
#include "index_type.h"
#include "xfor/xfor.h"
namespace CNORXZ
@ -20,173 +14,68 @@ namespace CNORXZ
class IndexInterface
{
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;
constexpr IndexType type() const { return THIS().type(); }
I& operator=(size_t pos) { return THIS() = pos; }
I& THIS() { return static_cast<I&>(*this); }
const I& THIS() const { return static_cast<const I&>(*this); }
I& operator=(SizeT pos) { return THIS() = pos; }
I& operator++() { return THIS()++; }
I& operator--() { return THIS()--;}
int pp(std::intptr_t idxPtrNum) { return THIS().pp(idxPtrNum); }
int mm(std::intptr_t idxPtrNum) { return THIS().mm(idxPtrNum); }
SizeT pos() const;
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;
auto operator*() const { return THIS().operator*(); }
auto operator->() const { return THIS().operator->(); }
Int pp(PtrId idxPtrNum) { return THIS().pp(idxPtrNum); }
Int mm(PtrId idxPtrNum) { return THIS().mm(idxPtrNum); }
size_t dim() const { return THIS().dim(); }
size_t pos() const;
size_t max() const;
SizeT dim() const { return THIS().dim(); }
RangePtr range() const { return mRangePtr; }
SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); }
bool last() const { return THIS().last(); }
bool first() const { return THIS().first(); }
std::shared_ptr<RangeBase> range() const { return mRangePtr; }
size_t getStepSize(size_t n) const { return THIS().getStepSize(n); }
std::string stringMeta() const { return THIS().stringMeta(); }
String stringMeta() const { return THIS().stringMeta(); }
MetaType meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); }
// CHECK / IMPLEMENT !!!!!!
template <class Expr>
auto ifor(size_t step, const Expr ex) const
-> decltype(THIS().template ifor<Expr>(step,ex))
auto ifor(SizeT step, const Expr ex) const
{ return THIS().template ifor<Expr>(step,ex); }
template <class Expr>
auto iforh(size_t step, const Expr ex) const
-> decltype(THIS().template iforh<Expr>(step,ex))
auto iforh(SizeT step, const Expr ex) const
{ return THIS().template iforh<Expr>(step,ex); }
std::intptr_t ptrNum() const;
private:
friend I;
// NO DEFAULT CONSTRUCTORS/ASSIGNMENTS!
IndexInterface();
IndexInterface(const IndexInterface& in);
IndexInterface& operator=(const IndexInterface& in);
IndexInterface(IndexInterface&& in);
IndexInterface& operator=(IndexInterface&& in);
IndexInterface(const RangePtr& range, SizeT pos);
IndexInterface(const std::shared_ptr<RangeBase>& range, size_t pos);
std::shared_ptr<RangeBase> mRangePtr;
size_t mPos = 0;
size_t mMax = 0;
std::intptr_t mPtrNum;
RangePtr mRangePtr = nullptr;
SizeT mPos = 0;
SizeT mMax = 0;
PtrId mPtrId = 0;
};
template <class Index>
std::shared_ptr<Index> mapResult(const std::shared_ptr<Index>& iptr)
{
return iptr;
}
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