2017-02-16 11:20:40 +01:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __index_base_h__
|
|
|
|
#define __index_base_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
2017-02-16 16:06:23 +01:00
|
|
|
#include <vector>
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
#include "rbase_def.h"
|
2017-02-16 11:20:40 +01:00
|
|
|
#include "range_base.h"
|
2017-12-17 17:40:55 +01:00
|
|
|
#include "index_type.h"
|
|
|
|
#include "vindex_wrapper.h"
|
2017-12-24 18:14:07 +01:00
|
|
|
#include "index_info.h"
|
2017-10-30 18:00:07 +01:00
|
|
|
|
2018-01-05 13:56:16 +01:00
|
|
|
#include "xfor/xfor.h"
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
template <class I, typename MetaType>
|
|
|
|
class IndexInterface
|
|
|
|
{
|
|
|
|
public:
|
2017-12-12 11:15:39 +01:00
|
|
|
//typedef typename I::RangeType RangeType;
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
//DEFAULT_MEMBERS(IndexInterface);
|
2017-08-30 17:56:38 +02:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
I& THIS() { return static_cast<I&>(*this); }
|
|
|
|
I const& THIS() const { return static_cast<I const&>(*this); }
|
2017-07-26 18:38:11 +02:00
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
~IndexInterface() = default;
|
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
IndexType type() const { return THIS().type(); }
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
I& operator=(size_t pos) { return THIS() = pos; }
|
|
|
|
I& operator++() { return THIS()++; }
|
|
|
|
I& operator--() { return THIS()--;}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
int pp(std::intptr_t idxPtrNum) { return THIS().pp(idxPtrNum); }
|
|
|
|
int mm(std::intptr_t idxPtrNum) { return THIS().mm(idxPtrNum); }
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
bool operator==(const IndexInterface& in) const;
|
|
|
|
bool operator!=(const IndexInterface& in) const;
|
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
size_t dim() const { return THIS().dim(); }
|
2017-12-10 18:41:53 +01:00
|
|
|
size_t pos() const;
|
|
|
|
size_t max() const;
|
2017-09-12 18:36:05 +02:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
bool last() const { return THIS().last(); }
|
|
|
|
bool first() const { return THIS().first(); }
|
2017-08-30 19:41:49 +02:00
|
|
|
|
2017-12-12 11:15:39 +01:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
std::shared_ptr<RangeBase> vrange() const { return mRangePtr; }
|
2017-12-12 11:15:39 +01:00
|
|
|
/*auto range() const -> decltype( I::S_range(THIS()) ) { return I::S_range(THIS()); }
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
template <size_t N>
|
2017-12-12 11:15:39 +01:00
|
|
|
auto getPtr() const -> decltype(I::template S_get<N>(THIS()))
|
|
|
|
{ return I::template S_get<N>(THIS()); }
|
|
|
|
*/
|
2017-12-17 14:16:37 +01:00
|
|
|
std::shared_ptr<VIWB> getVPtr(size_t n) const { return THIS().getVPtr(n); }
|
2017-12-24 18:14:07 +01:00
|
|
|
|
|
|
|
std::vector<IndexInfo> infoVec() const { return THIS().infoVec(); }
|
2017-05-22 18:21:14 +02:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
size_t getStepSize(size_t n) const { return THIS().getStepSize(n); }
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
operator size_t() const;
|
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
std::string id() const { return THIS().id(); }
|
2017-08-25 22:03:20 +02:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
MetaType meta() const { return THIS().meta(); }
|
|
|
|
I& at(const MetaType& meta) { return THIS().at(meta); }
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
void print(size_t offset = 0) const { THIS().print(offset); }
|
2018-01-05 13:56:16 +01:00
|
|
|
|
2018-02-13 21:36:41 +01:00
|
|
|
IndexInfo info() const { return IndexInfo(THIS()); }
|
|
|
|
|
2018-01-05 13:56:16 +01:00
|
|
|
// CHECK / IMPLEMENT !!!!!!
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Expr>
|
2018-02-13 21:36:41 +01:00
|
|
|
auto ifor(const Expr ex) const -> decltype(THIS().template ifor<Expr>(ex))
|
2018-01-13 18:07:52 +01:00
|
|
|
{ return THIS().template ifor<Expr>(ex); }
|
2018-01-15 14:56:22 +01:00
|
|
|
|
|
|
|
template <class Expr>
|
2018-02-13 21:36:41 +01:00
|
|
|
auto iforh(const Expr ex) const -> decltype(THIS().template iforh<Expr>(ex))
|
2018-01-15 14:56:22 +01:00
|
|
|
{ return THIS().template iforh<Expr>(ex); }
|
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
private:
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
friend I;
|
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
IndexInterface() { mId = indexId(); }
|
2017-12-12 16:16:09 +01:00
|
|
|
IndexInterface(const IndexInterface& in) = default;
|
|
|
|
IndexInterface& operator=(const IndexInterface& in) = default;
|
2017-12-10 18:41:53 +01:00
|
|
|
IndexInterface(IndexInterface&& in) = default;
|
|
|
|
IndexInterface& operator=(IndexInterface&& in) = default;
|
|
|
|
|
|
|
|
IndexInterface(const std::shared_ptr<RangeBase>& range, size_t pos);
|
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
std::shared_ptr<RangeBase> mRangePtr;
|
|
|
|
size_t mPos;
|
2017-08-25 22:03:20 +02:00
|
|
|
size_t mId;
|
2017-12-11 18:49:43 +01:00
|
|
|
size_t mMax;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
2017-12-10 18:41:53 +01:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2017-12-11 18:49:43 +01:00
|
|
|
/**********************
|
2017-12-10 18:41:53 +01:00
|
|
|
* IndexInterface *
|
2017-12-11 18:49:43 +01:00
|
|
|
**********************/
|
2017-11-20 21:35:25 +01:00
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
template <class I, typename MetaType>
|
|
|
|
IndexInterface<I,MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& range,
|
2017-12-12 16:16:09 +01:00
|
|
|
size_t pos) : mRangePtr(range),
|
|
|
|
mPos(pos),
|
|
|
|
mMax(mRangePtr->size())
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
mId = indexId();
|
|
|
|
}
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
template <class I, typename MetaType>
|
|
|
|
bool IndexInterface<I,MetaType>::operator==(const IndexInterface& in) const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return in.mPos == mPos and in.mRangePtr.get() == mRangePtr.get();
|
|
|
|
}
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
template <class I, typename MetaType>
|
|
|
|
bool IndexInterface<I,MetaType>::operator!=(const IndexInterface& in) const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return in.mPos != mPos or in.mRangePtr.get() != mRangePtr.get();
|
|
|
|
}
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
template <class I, typename MetaType>
|
|
|
|
size_t IndexInterface<I,MetaType>::pos() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return mPos;
|
|
|
|
}
|
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
template <class I, typename MetaType>
|
|
|
|
size_t IndexInterface<I,MetaType>::max() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2017-12-11 18:49:43 +01:00
|
|
|
return mMax;
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-12-10 18:41:53 +01:00
|
|
|
|
|
|
|
template <class I, typename MetaType>
|
|
|
|
IndexInterface<I,MetaType>::operator size_t() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return pos();
|
|
|
|
}
|
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
#endif
|