2017-02-16 11:20:40 +01:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __range_base_h__
|
|
|
|
#define __range_base_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
2017-02-17 18:10:03 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
#include "rbase_def.h"
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
class RangeBase;
|
|
|
|
}
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2017-12-18 11:19:04 +01:00
|
|
|
|
|
|
|
size_t indexId();
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
enum class SpaceType
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
|
|
|
NONE = 0, // meta data is that of a classic range, i.e. 0,1,2,...,N-1
|
2018-07-28 15:27:11 +02:00
|
|
|
ANY = 1, // meta data is arbitrary, i.e. explicitly stored; range could be multiple
|
2017-12-05 17:31:57 +01:00
|
|
|
#define include_range_type(x,n) x = n,
|
|
|
|
#include "range_types/header.h"
|
|
|
|
#undef include_range_type
|
2018-10-22 14:27:55 +02:00
|
|
|
ANON = -1, // anonymous content
|
2018-10-27 14:58:34 +02:00
|
|
|
DYN = -3 // dynamic content
|
2018-07-21 18:05:53 +02:00
|
|
|
};
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
struct DataHeader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr size_t VERSION = 1; // fixed by version of this repository !
|
|
|
|
private:
|
|
|
|
size_t version = VERSION;
|
|
|
|
public:
|
|
|
|
int spaceType = static_cast<int>( SpaceType::NONE );
|
|
|
|
size_t metaSize = 0; // size of meta data
|
|
|
|
int multiple = 0; // = 1 if multi range
|
2018-07-22 18:32:43 +02:00
|
|
|
int metaType = 0; // type of meta data
|
|
|
|
inline size_t v() const { return version; }
|
2018-07-21 18:05:53 +02:00
|
|
|
};
|
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
class RangeFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
RangeFactoryBase() = default;
|
|
|
|
virtual ~RangeFactoryBase() = default;
|
|
|
|
|
|
|
|
// should return mProd !!
|
|
|
|
virtual std::shared_ptr<RangeBase> create() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::shared_ptr<RangeBase> mProd;
|
2017-08-04 11:27:47 +02:00
|
|
|
|
|
|
|
// call this function before returning product !!
|
|
|
|
void setSelf();
|
2017-07-26 18:38:11 +02:00
|
|
|
};
|
2018-07-22 18:32:43 +02:00
|
|
|
|
2018-07-28 20:05:58 +02:00
|
|
|
std::shared_ptr<RangeFactoryBase> createRangeFactory(const char** dp);
|
2017-07-26 18:38:11 +02:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
class RangeBase
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
static constexpr bool ISINDEX = false;
|
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
virtual ~RangeBase() = default;
|
2017-08-04 16:19:50 +02:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
virtual size_t size() const = 0;
|
|
|
|
virtual size_t dim() const = 0;
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
bool operator==(const RangeBase& in) const;
|
|
|
|
bool operator!=(const RangeBase& in) const;
|
2018-02-14 16:44:55 +01:00
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
virtual std::string stringMeta(size_t pos) const = 0;
|
|
|
|
virtual std::vector<char> data() const = 0; // usefull when writing to files, etc...
|
2018-07-28 15:27:11 +02:00
|
|
|
|
|
|
|
virtual SpaceType spaceType() const = 0;
|
2018-11-07 10:58:07 +01:00
|
|
|
virtual DataHeader dataHeader() const = 0;
|
2018-02-14 16:44:55 +01:00
|
|
|
//virtual bool regular() const = 0; // integer distance (e.g. 2,3,4,...)
|
|
|
|
//virtual bool linear() const = 0; // 1dim valuable (e.g. 2.45, 3.12, 3.56,...)
|
|
|
|
//virtual bool multi() const = 0; // mdim
|
|
|
|
//virtual bool maplike() const = 0; // meta type is ~ MultiArray<T,...>
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
friend RangeFactoryBase;
|
2017-06-01 13:19:27 +02:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
protected:
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
RangeBase() = default;
|
2017-08-04 16:19:50 +02:00
|
|
|
std::weak_ptr<RangeBase> mThis;
|
2017-05-24 19:01:02 +02:00
|
|
|
};
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
template <class Index>
|
2017-07-25 17:46:59 +02:00
|
|
|
class RangeInterface : public RangeBase
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-05-31 16:44:28 +02:00
|
|
|
|
2018-03-21 19:18:57 +01:00
|
|
|
//typedef typename Index::MetaType MetaType;
|
2017-07-25 17:46:59 +02:00
|
|
|
typedef Index IndexType;
|
2017-06-01 13:19:27 +02:00
|
|
|
|
2018-07-28 15:27:11 +02:00
|
|
|
static constexpr SpaceType STYPE = IndexType::STYPE;
|
|
|
|
|
2017-08-04 14:57:19 +02:00
|
|
|
virtual Index begin() const = 0;
|
|
|
|
virtual Index end() const = 0;
|
2017-07-26 18:38:11 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
RangeInterface() = default;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|