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>
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
#include "base_def.h"
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
|
|
|
|
enum class RangeType
|
|
|
|
{
|
2017-12-05 17:31:57 +01:00
|
|
|
NONE = 0,
|
2017-02-17 18:10:03 +01:00
|
|
|
ANY = 1,
|
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
|
2017-02-16 11:20:40 +01: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
|
|
|
};
|
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
class RangeBase
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
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;
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
virtual std::shared_ptr<VIWB> index() const = 0;
|
2017-07-26 18:38:11 +02:00
|
|
|
|
|
|
|
bool operator==(const RangeBase& in) const;
|
|
|
|
bool operator!=(const RangeBase& in) const;
|
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:
|
|
|
|
|
|
|
|
RangeBase() = default;
|
2017-08-04 16:19:50 +02:00
|
|
|
std::weak_ptr<RangeBase> mThis;
|
2017-05-24 19:01:02 +02:00
|
|
|
};
|
2017-07-25 17:46:59 +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
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
typedef Index IndexType;
|
2017-06-01 13:19:27 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
|
|
|
|
/*************************
|
|
|
|
* RangeFactoryBase *
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
void RangeFactoryBase::setSelf()
|
|
|
|
{
|
|
|
|
mProd->mThis = mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* RangeBase *
|
|
|
|
******************/
|
|
|
|
|
|
|
|
bool RangeBase::operator==(const RangeBase& in) const
|
|
|
|
{
|
|
|
|
return this == ∈
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RangeBase::operator!=(const RangeBase& in) const
|
|
|
|
{
|
|
|
|
return this != ∈
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
#endif
|