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
|
|
|
|
|
|
|
#include "base_def.h"
|
|
|
|
#include "range_base.h"
|
2017-10-30 18:00:07 +01:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2017-08-25 22:03:20 +02:00
|
|
|
size_t indexId()
|
|
|
|
{
|
|
|
|
static size_t id = 0;
|
|
|
|
++id;
|
|
|
|
return id;
|
|
|
|
}
|
2017-08-28 18:28:43 +02:00
|
|
|
|
|
|
|
enum class IndexType{
|
|
|
|
SINGLE = 0,
|
|
|
|
MULTI = 1,
|
|
|
|
CONT = 2
|
|
|
|
};
|
2017-05-22 18:21:14 +02:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
class IndexBase
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-08-25 22:03:20 +02:00
|
|
|
//DEFAULT_MEMBERS(IndexBase);
|
|
|
|
|
|
|
|
IndexBase() { mId = indexId(); }
|
|
|
|
IndexBase(IndexBase&& in) = default;
|
|
|
|
IndexBase& operator=(IndexBase&& in) = default;
|
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
IndexBase(const std::shared_ptr<RangeBase>& range, size_t pos);
|
2017-07-25 17:46:59 +02:00
|
|
|
virtual ~IndexBase() = default;
|
2017-08-28 18:28:43 +02:00
|
|
|
|
|
|
|
virtual IndexType type() const = 0;
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
virtual IndexBase& operator=(size_t pos) = 0;
|
|
|
|
virtual IndexBase& operator++() = 0;
|
|
|
|
virtual IndexBase& operator--() = 0;
|
2017-08-30 17:56:38 +02:00
|
|
|
|
2017-09-12 18:36:05 +02:00
|
|
|
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) = 0;
|
|
|
|
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) = 0;
|
2017-07-26 18:38:11 +02:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
bool operator==(const IndexBase& in) const;
|
|
|
|
bool operator!=(const IndexBase& in) const;
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
virtual size_t dim() const = 0;
|
2017-02-21 17:41:48 +01:00
|
|
|
virtual size_t pos() const;
|
2017-07-25 17:46:59 +02:00
|
|
|
virtual size_t max() const;
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
virtual bool last() const = 0;
|
|
|
|
virtual bool first() const = 0;
|
2017-09-12 18:36:05 +02:00
|
|
|
|
2017-08-30 17:56:38 +02:00
|
|
|
//virtual bool locked() const;
|
2017-08-30 19:41:49 +02:00
|
|
|
//virtual IndexBase& lock(std::shared_ptr<IndexBase>& idx);
|
|
|
|
|
|
|
|
virtual std::shared_ptr<RangeBase> rangePtr() const;
|
|
|
|
virtual std::shared_ptr<IndexBase> getPtr(size_t n) const = 0;
|
|
|
|
|
|
|
|
virtual size_t getStepSize(size_t n) const = 0;
|
2017-05-22 18:21:14 +02:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
virtual operator size_t() const;
|
2017-08-25 22:03:20 +02:00
|
|
|
|
|
|
|
virtual std::string id() const { return std::to_string( mId ); }
|
2017-02-16 11:20:40 +01:00
|
|
|
protected:
|
|
|
|
|
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-08-30 17:56:38 +02:00
|
|
|
//bool mLocked = false;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
2017-07-25 17:46:59 +02:00
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
class IndexInterface : public IndexBase
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-02-22 00:43:38 +01:00
|
|
|
|
2017-08-04 14:57:19 +02:00
|
|
|
DEFAULT_MEMBERS(IndexInterface);
|
2017-02-28 11:27:23 +01:00
|
|
|
|
2017-08-04 14:57:19 +02:00
|
|
|
IndexInterface(const std::shared_ptr<RangeBase>& rangePtr, size_t pos);
|
|
|
|
virtual MetaType meta() const = 0;
|
|
|
|
virtual IndexInterface& at(const MetaType& meta) = 0;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
2017-07-25 17:46:59 +02:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
/*****************
|
|
|
|
* IndexBase *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
IndexBase::IndexBase(const std::shared_ptr<RangeBase>& range,
|
|
|
|
size_t pos) : mRangePtr(range),
|
|
|
|
mPos(pos)
|
|
|
|
{
|
|
|
|
mId = indexId();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexBase::operator==(const IndexBase& in) const
|
|
|
|
{
|
|
|
|
return in.mPos == mPos and in.mRangePtr.get() == mRangePtr.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexBase::operator!=(const IndexBase& in) const
|
|
|
|
{
|
|
|
|
return in.mPos != mPos or in.mRangePtr.get() != mRangePtr.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t IndexBase::pos() const
|
|
|
|
{
|
|
|
|
return mPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t IndexBase::max() const
|
|
|
|
{
|
|
|
|
return mRangePtr->size();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
bool IndexBase::locked() const
|
|
|
|
{
|
|
|
|
return mLocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexBase& IndexBase::lock(std::shared_ptr<IndexBase>& idx)
|
|
|
|
{
|
|
|
|
mLocked = (idx.get() == this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::shared_ptr<RangeBase> IndexBase::rangePtr() const
|
|
|
|
{
|
|
|
|
return mRangePtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexBase::operator size_t() const
|
|
|
|
{
|
|
|
|
return pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* IndexInterface *
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
IndexInterface<MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& rangePtr, size_t pos) :
|
|
|
|
IndexBase(rangePtr, pos) {}
|
|
|
|
|
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
#endif
|