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 bool link(IndefinitIndexBase* toLink);
virtual void freeLinked();
virtual bool linked() const;
virtual void linkTo(IndefinitIndexBase* target) = 0;
virtual void setPos(size_t pos);
virtual size_t max() const;
virtual size_t outOfRange() const;
2017-02-21 17:41:48 +01:00
virtual bool toNull() const;
virtual void eval() = 0;
virtual void evalMajor();
virtual bool master();
virtual void subOrd(IndefinitIndexBase* major);
2017-02-16 11:20:40 +01:00
protected:
std::string mName;
size_t mPos;
2017-02-21 17:41:48 +01:00
IndefinitIndexBase* mLinked = nullptr;
IndefinitIndexBase* mMajor = nullptr;
IndefinitIndexBase* mSoftLinked = 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);
virtual void eval() override;
virtual void copyPos(const Index& in);
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