cnorxz/src/index_base.h

102 lines
2.2 KiB
C
Raw Normal View History

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-02-16 16:06:23 +01:00
#include "name.h"
2017-02-16 11:20:40 +01:00
namespace MultiArrayTools
{
class IndefinitIndexBase
{
public:
2017-02-22 00:43:38 +01:00
DEFAULT_MEMBERS(IndefinitIndexBase);
virtual ~IndefinitIndexBase();
2017-02-16 11:20:40 +01:00
virtual IndefinitIndexBase& operator=(size_t pos) = 0;
virtual IndefinitIndexBase& operator++() = 0;
virtual IndefinitIndexBase& operator--() = 0;
virtual IndefinitIndexBase& operator+=(int n) = 0;
virtual IndefinitIndexBase& operator-=(int n) = 0;
// Make this somehow better... !!!
//virtual bool operator==(const IndefinitIndexBase& i) = 0;
//virtual bool operator!=(const IndefinitIndexBase& i) = 0;
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-02-20 19:14:22 +01:00
2017-02-16 16:06:23 +01:00
virtual const std::string& name() const;
virtual void name(const std::string& str);
virtual void name(const Name& nm);
virtual MultiRangeType rangeType() const = 0;
2017-02-16 11:20:40 +01:00
virtual void setPos(size_t pos);
virtual void setPosRel(int relPos);
2017-03-13 11:06:44 +01:00
2017-03-08 20:10:11 +01:00
virtual size_t max() const = 0;
virtual int outOfRange() const;
2017-02-21 17:41:48 +01:00
virtual bool toNull() const;
virtual void eval() = 0;
virtual void evalMajor();
virtual void evalMajor(int num);
virtual bool master();
virtual void subOrd(IndefinitIndexBase* major);
2017-03-13 11:06:44 +01:00
virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) = 0;
virtual size_t majorStep() const;
2017-03-13 11:06:44 +01:00
2017-03-01 10:41:29 +01:00
//virtual bool virt() const { return true; }
2017-02-16 11:20:40 +01:00
protected:
std::string mName;
int mPos;
2017-03-13 11:06:44 +01:00
size_t mMajorStep;
IndefinitIndexBase* mMajor = nullptr;
2017-02-16 11:20:40 +01:00
};
template <class Index>
class IndexBase : public IndefinitIndexBase
{
public:
2017-02-22 00:43:38 +01:00
typedef IndefinitIndexBase IIB;
2017-02-22 00:43:38 +01:00
DEFAULT_MEMBERS(IndexBase);
IndexBase(RangeBase<Index> const* range);
2017-02-16 11:20:40 +01:00
//virtual size_t pos() const override; // = mPos; implement !!!
virtual size_t max() const override;
2017-02-21 17:41:48 +01:00
virtual bool toNull() const override;
virtual void assignRange(RangeBase<Index> const* range);
2017-03-01 10:41:29 +01:00
virtual void eval() override;
2017-02-28 19:29:52 +01:00
virtual void copyPos(const Index& in) = 0;
2017-02-16 11:20:40 +01:00
protected:
// translate index into position
virtual size_t evaluate(const Index& in) const = 0;
2017-02-21 17:41:48 +01:00
RangeBase<Index> const* mRange;
2017-02-16 11:20:40 +01:00
};
}
#include "index_base.cc"
#endif