2017-02-16 11:20:40 +01:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __single_range_h__
|
|
|
|
#define __single_range_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
2017-06-01 13:19:27 +02:00
|
|
|
#include <memory>
|
2018-08-08 18:20:08 +02:00
|
|
|
#include <map>
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2018-08-20 17:50:04 +02:00
|
|
|
#include "base_def.h"
|
2018-07-16 00:12:05 +02:00
|
|
|
//#include "ranges/rpack_num.h"
|
2017-12-17 17:40:55 +01:00
|
|
|
#include "ranges/index_base.h"
|
|
|
|
#include "ranges/range_base.h"
|
2018-07-21 18:05:53 +02:00
|
|
|
#include "ranges/x_to_string.h"
|
2018-07-22 21:59:31 +02:00
|
|
|
#include "ranges/type_map.h"
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
#include "xfor/for_type.h"
|
|
|
|
//#include "xfor/xfor.h"
|
|
|
|
|
2018-01-07 22:33:34 +01:00
|
|
|
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2018-09-12 17:05:27 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace MultiArrayHelper;
|
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
class GenSingleIndex : public IndexInterface<GenSingleIndex<U,TYPE,S>,U>
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
typedef IndexInterface<GenSingleIndex<U,TYPE,S>,U> IB;
|
2017-08-04 14:57:19 +02:00
|
|
|
typedef U MetaType;
|
2019-02-12 20:26:38 +01:00
|
|
|
typedef GenSingleRange<U,TYPE,S> RangeType;
|
|
|
|
typedef GenSingleIndex IType;
|
2018-02-13 16:54:13 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
//DEFAULT_MEMBERS_X(GenSingleIndex);
|
2017-08-04 11:27:47 +02:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleIndex(const std::shared_ptr<GenSingleRange<U,TYPE,S> >& range);
|
2017-08-28 18:28:43 +02:00
|
|
|
|
2018-03-02 16:37:11 +01:00
|
|
|
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
|
|
|
static constexpr size_t totalDim() { return 1; }
|
|
|
|
static constexpr size_t sDim() { return 1; }
|
2018-07-28 15:27:11 +02:00
|
|
|
|
|
|
|
static constexpr SpaceType STYPE = TYPE;
|
2019-01-15 17:41:43 +01:00
|
|
|
static constexpr bool PARALLEL = true;
|
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
|
|
|
|
2017-12-26 15:13:50 +01:00
|
|
|
IndexType type() const;
|
2017-08-11 16:45:03 +02:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleIndex& operator=(size_t pos);
|
|
|
|
GenSingleIndex& operator++();
|
|
|
|
GenSingleIndex& operator--();
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
int pp(std::intptr_t idxPtrNum);
|
|
|
|
int mm(std::intptr_t idxPtrNum);
|
2018-07-22 16:16:24 +02:00
|
|
|
|
|
|
|
std::string stringMeta() const;
|
|
|
|
U meta() const;
|
2018-03-22 11:13:00 +01:00
|
|
|
const U* metaPtr() const;
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleIndex& at(const U& metaPos);
|
2018-08-20 17:50:04 +02:00
|
|
|
size_t posAt(const U& metaPos) const;
|
2018-10-14 16:59:27 +02:00
|
|
|
|
|
|
|
bool isMeta(const U& metaPos) const;
|
2017-03-03 17:51:42 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
size_t dim(); // = 1
|
|
|
|
bool last();
|
|
|
|
bool first();
|
2017-08-25 22:03:20 +02:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
std::shared_ptr<RangeType> range();
|
2017-12-12 11:15:39 +01:00
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
template <size_t N>
|
2017-12-17 14:23:23 +01:00
|
|
|
void getPtr();
|
2017-12-10 18:41:53 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
size_t getStepSize(size_t n);
|
2017-12-10 18:41:53 +01:00
|
|
|
|
2018-01-14 22:41:35 +01:00
|
|
|
std::string id() const;
|
2017-12-17 14:23:23 +01:00
|
|
|
void print(size_t offset);
|
2018-01-07 22:33:34 +01:00
|
|
|
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Expr>
|
2018-09-17 16:21:23 +02:00
|
|
|
auto ifor(size_t step, Expr ex) const
|
2019-02-12 20:26:38 +01:00
|
|
|
-> For<GenSingleIndex<U,TYPE,S>,Expr>;
|
2018-01-15 14:56:22 +01:00
|
|
|
|
|
|
|
template <class Expr>
|
2018-09-17 16:21:23 +02:00
|
|
|
auto iforh(size_t step, Expr ex) const
|
2019-02-12 20:26:38 +01:00
|
|
|
-> For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>;
|
2018-01-15 14:56:22 +01:00
|
|
|
|
2019-01-15 17:41:43 +01:00
|
|
|
template <class Expr>
|
|
|
|
auto pifor(size_t step, Expr ex) const
|
2019-02-12 20:26:38 +01:00
|
|
|
-> PFor<GenSingleIndex<U,TYPE,S>,Expr>;
|
2019-01-15 17:41:43 +01:00
|
|
|
|
2018-03-19 18:38:53 +01:00
|
|
|
private:
|
2018-07-29 19:17:26 +02:00
|
|
|
std::shared_ptr<RangeType> mExplicitRangePtr;
|
2018-03-21 19:18:57 +01:00
|
|
|
const U* mMetaPtr;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
class GenSingleRangeFactory : public RangeFactoryBase
|
2017-07-28 11:33:31 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
typedef GenSingleRange<U,TYPE,S> oType;
|
2017-07-28 11:33:31 +02:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleRangeFactory() = delete;
|
2019-02-13 21:59:13 +01:00
|
|
|
GenSingleRangeFactory(const vector<U>& space);
|
2019-03-14 19:10:06 +01:00
|
|
|
GenSingleRangeFactory(vector<U>&& space);
|
2017-07-28 11:33:31 +02:00
|
|
|
std::shared_ptr<RangeBase> create();
|
|
|
|
};
|
2018-09-18 01:44:11 +02:00
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
class MetaMap
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::map<U,size_t> mMap;
|
|
|
|
public:
|
|
|
|
MetaMap() = default;
|
|
|
|
MetaMap(const MetaMap& in) = default;
|
|
|
|
MetaMap(MetaMap&& in) = default;
|
|
|
|
MetaMap& operator=(const MetaMap& in) = default;
|
|
|
|
MetaMap& operator=(MetaMap&& in) = default;
|
|
|
|
|
|
|
|
//MetaMap(const std::map<U,size_t>& in) : mMap(in) {}
|
2019-02-13 21:59:13 +01:00
|
|
|
MetaMap(const vector<U>& in)
|
2018-09-18 01:44:11 +02:00
|
|
|
{
|
|
|
|
for(size_t i = 0; i != in.size(); ++i){
|
|
|
|
mMap[in[i]] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t at(const U& in) const { return mMap.at(in); }
|
2018-10-14 16:59:27 +02:00
|
|
|
size_t count(const U& in) const { return mMap.count(in); }
|
2018-09-18 01:44:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class MetaMap<std::array<int,2> >
|
|
|
|
{
|
|
|
|
private:
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<size_t> mMap;
|
2018-09-18 01:44:11 +02:00
|
|
|
int min1;
|
|
|
|
int min2;
|
|
|
|
int max1;
|
|
|
|
int max2;
|
|
|
|
size_t s1;
|
|
|
|
size_t s2;
|
|
|
|
public:
|
|
|
|
typedef std::array<int,2> U;
|
|
|
|
|
|
|
|
MetaMap() = default;
|
|
|
|
MetaMap(const MetaMap& in) = default;
|
|
|
|
MetaMap(MetaMap&& in) = default;
|
|
|
|
MetaMap& operator=(const MetaMap& in) = default;
|
|
|
|
MetaMap& operator=(MetaMap&& in) = default;
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
MetaMap(const vector<U>& in) : min1(in[0][0]),
|
2018-09-18 01:44:11 +02:00
|
|
|
min2(in[0][1]),
|
|
|
|
max1(in[0][0]),
|
|
|
|
max2(in[0][1])
|
|
|
|
{
|
|
|
|
for(auto& x: in){
|
|
|
|
if(min1 > x[0]) min1 = x[0];
|
|
|
|
if(min2 > x[1]) min2 = x[1];
|
|
|
|
if(max1 < x[0]+1) max1 = x[0]+1;
|
|
|
|
if(max2 < x[1]+1) max2 = x[1]+1;
|
|
|
|
}
|
|
|
|
s1 = max1 - min1;
|
|
|
|
s2 = max2 - min2;
|
|
|
|
mMap.resize(s1*s2,-1);
|
|
|
|
for(size_t i = 0; i != in.size(); ++i){
|
|
|
|
const size_t mpos = (in[i][0] - min1) * s2 + (in[i][1] - min2);
|
|
|
|
mMap[ mpos ] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t at(const U& in) const
|
|
|
|
{
|
|
|
|
//CHECK;
|
|
|
|
const size_t mpos = (in[0] - min1) * s2 + (in[1] - min2);
|
|
|
|
assert(mpos < mMap.size());
|
|
|
|
assert(mMap[ mpos ] != static_cast<size_t>( -1 ) );
|
|
|
|
return mMap[ mpos ];
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2019-02-12 20:26:38 +01:00
|
|
|
|
|
|
|
template <size_t S>
|
|
|
|
struct CheckStatic
|
|
|
|
{
|
|
|
|
static constexpr size_t ISSTATIC = true;
|
|
|
|
static constexpr size_t SIZE = S;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct CheckStatic<-1>
|
|
|
|
{
|
|
|
|
static constexpr size_t ISSTATIC = false;
|
|
|
|
static constexpr size_t SIZE = -1;
|
|
|
|
};
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
template <SpaceType TYPE>
|
|
|
|
struct CheckDefault
|
|
|
|
{
|
|
|
|
static constexpr size_t ISDEFAULT = false;
|
|
|
|
static constexpr size_t HASMETACONT = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct CheckDefault<SpaceType::NONE>
|
|
|
|
{
|
|
|
|
static constexpr size_t ISDEFAULT = true;
|
|
|
|
static constexpr size_t HASMETACONT = false;
|
|
|
|
};
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
class GenSingleRange : public RangeInterface<GenSingleIndex<U,TYPE,S> >
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-08-04 11:27:47 +02:00
|
|
|
typedef RangeBase RB;
|
2019-02-12 20:26:38 +01:00
|
|
|
typedef GenSingleIndex<U,TYPE,S> IndexType;
|
|
|
|
typedef GenSingleRange RangeType;
|
2018-03-21 19:18:57 +01:00
|
|
|
typedef U MetaType;
|
2019-02-12 20:26:38 +01:00
|
|
|
typedef GenSingleRangeFactory<U,TYPE,S> FType;
|
|
|
|
//typedef typename RangeInterface<GenSingleIndex<U,TYPE,S> >::IndexType IndexType;
|
2017-02-17 18:10:03 +01:00
|
|
|
|
2018-07-29 19:17:26 +02:00
|
|
|
virtual size_t size() const final;
|
|
|
|
virtual size_t dim() const final;
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2018-07-29 19:17:26 +02:00
|
|
|
virtual SpaceType spaceType() const final;
|
2018-11-07 10:58:07 +01:00
|
|
|
virtual DataHeader dataHeader() const final;
|
2019-03-13 21:51:48 +01:00
|
|
|
|
|
|
|
virtual size_t typeNum() const final;
|
2019-03-14 14:20:38 +01:00
|
|
|
virtual size_t cmeta(char* target, size_t pos) const final;
|
2018-07-29 19:17:26 +02:00
|
|
|
virtual std::string stringMeta(size_t pos) const final;
|
2019-02-13 21:59:13 +01:00
|
|
|
virtual vector<char> data() const final;
|
2017-08-04 11:27:47 +02:00
|
|
|
|
2018-10-14 16:59:27 +02:00
|
|
|
bool isMeta(const U& metaPos) const;
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
const U& get(size_t pos) const;
|
2017-03-03 17:51:42 +01:00
|
|
|
size_t getMeta(const U& metaPos) const;
|
2017-02-20 17:18:53 +01:00
|
|
|
|
2018-07-29 19:17:26 +02:00
|
|
|
virtual IndexType begin() const final;
|
|
|
|
virtual IndexType end() const final;
|
2018-02-15 16:24:54 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
friend GenSingleRangeFactory<U,TYPE,S>;
|
2017-12-15 14:47:02 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
static GenSingleRangeFactory<U,TYPE,S> factory()
|
|
|
|
{
|
|
|
|
static_assert( not CheckDefault<TYPE>::HASMETACONT,
|
|
|
|
"asked for default factory for meta data containing range" );
|
|
|
|
return GenSingleRangeFactory<U,TYPE,S>(vector<U>());
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr bool defaultable = CheckDefault<TYPE>::ISDEFAULT;
|
2019-02-12 20:26:38 +01:00
|
|
|
static constexpr size_t ISSTATIC = CheckStatic<S>::ISSTATIC;
|
|
|
|
static constexpr size_t SIZE = CheckStatic<S>::SIZE;
|
2019-02-13 21:59:13 +01:00
|
|
|
static constexpr bool HASMETACONT = CheckDefault<TYPE>::HASMETACONT;
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
protected:
|
2017-07-26 18:38:11 +02:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleRange() = delete;
|
|
|
|
GenSingleRange(const GenSingleRange& in) = delete;
|
2017-06-01 13:19:27 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
GenSingleRange(const vector<U>& space);
|
2019-03-14 19:10:06 +01:00
|
|
|
GenSingleRange(vector<U>&& space);
|
2017-06-01 13:19:27 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<U> mSpace;
|
2018-09-18 01:44:11 +02:00
|
|
|
//std::map<U,size_t> mMSpace;
|
|
|
|
MetaMap<U> mMSpace;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
using SingleRange = GenSingleRange<U,TYPE,-1>;
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
using SingleIndex = GenSingleIndex<U,TYPE,-1>;
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
using SingleRangeFactory = GenSingleRangeFactory<U,TYPE,-1>;
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-03-30 14:41:57 +02:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
/******************
|
2019-02-12 20:26:38 +01:00
|
|
|
* GenSingleIndex *
|
2017-11-20 21:35:25 +01:00
|
|
|
******************/
|
|
|
|
|
2018-03-21 16:11:05 +01:00
|
|
|
template <bool HASMETACONT>
|
2018-05-10 14:34:56 +02:00
|
|
|
struct MetaPtrHandle
|
2018-03-21 16:11:05 +01:00
|
|
|
{
|
2018-03-21 19:18:57 +01:00
|
|
|
template <class Range>
|
|
|
|
static const typename Range::MetaType* set(Range* r)
|
2018-03-21 16:11:05 +01:00
|
|
|
{
|
|
|
|
return &r->get(0);
|
|
|
|
}
|
2018-03-21 19:18:57 +01:00
|
|
|
|
2018-05-10 14:34:56 +02:00
|
|
|
template <typename U, class Range>
|
|
|
|
static inline U getMeta(U* metaPtr, size_t pos, std::shared_ptr<Range> r)
|
|
|
|
{
|
|
|
|
return metaPtr[pos];
|
|
|
|
}
|
2018-03-21 16:11:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2018-05-10 14:34:56 +02:00
|
|
|
struct MetaPtrHandle<false>
|
2018-03-21 16:11:05 +01:00
|
|
|
{
|
2018-03-21 19:18:57 +01:00
|
|
|
template <class Range>
|
|
|
|
static const typename Range::MetaType* set(Range* r)
|
2018-03-21 16:11:05 +01:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-05-10 14:34:56 +02:00
|
|
|
|
|
|
|
template <typename U, class Range>
|
|
|
|
static inline U getMeta(U* metaPtr, size_t pos, std::shared_ptr<Range> r)
|
|
|
|
{
|
|
|
|
return r->get(pos);
|
|
|
|
}
|
2018-03-21 16:11:05 +01:00
|
|
|
};
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
GenSingleIndex<U,TYPE,S>::GenSingleIndex(const std::shared_ptr<GenSingleRange<U,TYPE,S> >& range) :
|
|
|
|
IndexInterface<GenSingleIndex<U,TYPE,S>,U>(range, 0),
|
2018-07-29 19:17:26 +02:00
|
|
|
mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr)),
|
2019-02-12 20:26:38 +01:00
|
|
|
mMetaPtr(MetaPtrHandle<GenSingleIndex<U,TYPE,S>::RangeType::HASMETACONT>::set
|
2018-03-21 19:18:57 +01:00
|
|
|
( dynamic_cast<RangeType*>(IB::mRangePtr.get() ) ) ) {}
|
2017-12-17 14:23:23 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
IndexType GenSingleIndex<U,TYPE,S>::type() const
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return IndexType::SINGLE;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::operator=(size_t pos)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::operator++()
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::operator--()
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
int GenSingleIndex<U,TYPE,S>::pp(std::intptr_t idxPtrNum)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
++(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
int GenSingleIndex<U,TYPE,S>::mm(std::intptr_t idxPtrNum)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
--(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
std::string GenSingleIndex<U,TYPE,S>::stringMeta() const
|
2018-07-22 16:16:24 +02:00
|
|
|
{
|
2019-02-12 20:26:38 +01:00
|
|
|
return std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> const>( IB::mRangePtr )->stringMeta(IB::mPos);
|
2018-07-22 16:16:24 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
U GenSingleIndex<U,TYPE,S>::meta() const
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
2019-02-12 20:26:38 +01:00
|
|
|
return MetaPtrHandle<GenSingleIndex<U,TYPE,S>::RangeType::HASMETACONT>::getMeta
|
2018-07-29 19:17:26 +02:00
|
|
|
( mMetaPtr, IB::mPos, mExplicitRangePtr );
|
2017-12-17 14:23:23 +01:00
|
|
|
}
|
2019-03-13 21:51:48 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
const U* GenSingleIndex<U,TYPE,S>::metaPtr() const
|
2018-03-19 18:38:53 +01:00
|
|
|
{
|
|
|
|
return mMetaPtr;
|
|
|
|
}
|
2018-10-14 16:59:27 +02:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
bool GenSingleIndex<U,TYPE,S>::isMeta(const U& metaPos) const
|
2018-10-14 16:59:27 +02:00
|
|
|
{
|
|
|
|
return mExplicitRangePtr->isMeta(metaPos);
|
|
|
|
}
|
2018-03-19 18:38:53 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::at(const U& metaPos)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
2019-02-12 20:26:38 +01:00
|
|
|
(*this) = std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> const>( IB::mRangePtr )->getMeta( metaPos );
|
2017-12-17 14:23:23 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleIndex<U,TYPE,S>::posAt(const U& metaPos) const
|
2018-08-20 17:50:04 +02:00
|
|
|
{
|
2019-02-12 20:26:38 +01:00
|
|
|
return std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> const>( IB::mRangePtr )->getMeta( metaPos );
|
2018-08-20 17:50:04 +02:00
|
|
|
}
|
2018-10-14 16:59:27 +02:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleIndex<U,TYPE,S>::dim() // = 1
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
bool GenSingleIndex<U,TYPE,S>::last()
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return IB::mPos == IB::mMax - 1;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
bool GenSingleIndex<U,TYPE,S>::first()
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return IB::mPos == 0;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
std::shared_ptr<typename GenSingleIndex<U,TYPE,S>::RangeType> GenSingleIndex<U,TYPE,S>::range()
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
2018-11-26 18:23:38 +01:00
|
|
|
return mExplicitRangePtr;
|
2017-12-17 14:23:23 +01:00
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
2017-12-17 14:23:23 +01:00
|
|
|
template <size_t N>
|
2019-02-12 20:26:38 +01:00
|
|
|
void GenSingleIndex<U,TYPE,S>::getPtr() {}
|
2017-12-24 18:14:07 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleIndex<U,TYPE,S>::getStepSize(size_t n)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
std::string GenSingleIndex<U,TYPE,S>::id() const
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return std::string("sin") + std::to_string(IB::mId);
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
void GenSingleIndex<U,TYPE,S>::print(size_t offset)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
if(offset == 0){
|
|
|
|
std::cout << " === " << std::endl;
|
|
|
|
}
|
|
|
|
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
|
|
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
|
|
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Expr>
|
2019-02-12 20:26:38 +01:00
|
|
|
auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const
|
|
|
|
-> For<GenSingleIndex<U,TYPE,S>,Expr>
|
2018-01-07 22:33:34 +01:00
|
|
|
{
|
2018-01-13 18:07:52 +01:00
|
|
|
//static const size_t LAYER = typename Expr::LAYER;
|
2019-02-12 20:26:38 +01:00
|
|
|
return For<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex);
|
2018-01-07 22:33:34 +01:00
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
2018-01-15 14:56:22 +01:00
|
|
|
template <class Expr>
|
2019-02-12 20:26:38 +01:00
|
|
|
auto GenSingleIndex<U,TYPE,S>::iforh(size_t step, Expr ex) const
|
|
|
|
-> For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>
|
2018-01-15 14:56:22 +01:00
|
|
|
{
|
|
|
|
//static const size_t LAYER = typename Expr::LAYER;
|
2019-02-12 20:26:38 +01:00
|
|
|
return For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>(this, step, ex);
|
2018-01-15 14:56:22 +01:00
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
2019-01-15 17:41:43 +01:00
|
|
|
template <class Expr>
|
2019-02-12 20:26:38 +01:00
|
|
|
auto GenSingleIndex<U,TYPE,S>::pifor(size_t step, Expr ex) const
|
|
|
|
-> PFor<GenSingleIndex<U,TYPE,S>,Expr>
|
2019-01-15 17:41:43 +01:00
|
|
|
{
|
|
|
|
//static const size_t LAYER = typename Expr::LAYER;
|
2019-02-12 20:26:38 +01:00
|
|
|
return PFor<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex);
|
2019-01-15 17:41:43 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
|
|
|
|
/********************
|
|
|
|
* SingleRange *
|
|
|
|
********************/
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
2019-02-13 21:59:13 +01:00
|
|
|
GenSingleRangeFactory<U,TYPE,S>::GenSingleRangeFactory(const vector<U>& space)
|
2017-03-14 23:00:41 +01:00
|
|
|
{
|
2019-02-12 20:26:38 +01:00
|
|
|
mProd = std::shared_ptr<oType>( new GenSingleRange<U,TYPE,S>( space ) );
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2019-03-14 19:10:06 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
GenSingleRangeFactory<U,TYPE,S>::GenSingleRangeFactory(vector<U>&& space)
|
|
|
|
{
|
|
|
|
mProd = std::shared_ptr<oType>( new GenSingleRange<U,TYPE,S>( space ) );
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
std::shared_ptr<RangeBase> GenSingleRangeFactory<U,TYPE,S>::create()
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
setSelf();
|
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************
|
|
|
|
* SingleRange *
|
|
|
|
********************/
|
2017-03-15 22:54:48 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
2019-02-13 21:59:13 +01:00
|
|
|
GenSingleRange<U,TYPE,S>::GenSingleRange(const vector<U>& space) :
|
2019-02-12 20:26:38 +01:00
|
|
|
RangeInterface<GenSingleIndex<U,TYPE,S> >(),
|
2018-09-18 01:44:11 +02:00
|
|
|
mSpace(space), mMSpace(mSpace)
|
2018-08-08 18:20:08 +02:00
|
|
|
{
|
2018-09-18 01:44:11 +02:00
|
|
|
//for(size_t i = 0; i != mSpace.size(); ++i){
|
|
|
|
// mMSpace[mSpace[i]] = i;
|
|
|
|
//}
|
2018-08-08 18:20:08 +02:00
|
|
|
}
|
2019-03-14 19:10:06 +01:00
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
GenSingleRange<U,TYPE,S>::GenSingleRange(vector<U>&& space) :
|
|
|
|
RangeInterface<GenSingleIndex<U,TYPE,S> >(),
|
|
|
|
mSpace(space), mMSpace(mSpace) {}
|
|
|
|
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
const U& GenSingleRange<U,TYPE,S>::get(size_t pos) const
|
2017-03-14 23:00:41 +01:00
|
|
|
{
|
2017-11-20 21:35:25 +01:00
|
|
|
return mSpace[pos];
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleRange<U,TYPE,S>::getMeta(const U& metaPos) const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2018-08-08 18:20:08 +02:00
|
|
|
return mMSpace.at(metaPos);
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
template <size_t SIZE>
|
|
|
|
inline size_t getStatSizeOrDyn(size_t size)
|
|
|
|
{
|
|
|
|
return SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline size_t getStatSizeOrDyn<-1>(size_t size)
|
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleRange<U,TYPE,S>::size() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2019-02-13 21:59:13 +01:00
|
|
|
return getStatSizeOrDyn<S>(mSpace.size());
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleRange<U,TYPE,S>::dim() const
|
2017-03-14 23:00:41 +01:00
|
|
|
{
|
2017-11-20 21:35:25 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
bool GenSingleRange<U,TYPE,S>::isMeta(const U& metaPos) const
|
2018-10-14 16:59:27 +02:00
|
|
|
{
|
|
|
|
return mMSpace.count(metaPos) != 0;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
SpaceType GenSingleRange<U,TYPE,S>::spaceType() const
|
2018-07-28 15:27:11 +02:00
|
|
|
{
|
|
|
|
return TYPE;
|
|
|
|
}
|
2019-03-14 14:20:38 +01:00
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleRange<U,TYPE,S>::typeNum() const
|
|
|
|
{
|
|
|
|
return NumTypeMap<U>::num;
|
|
|
|
}
|
2018-07-28 15:27:11 +02:00
|
|
|
|
2019-03-14 14:20:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
size_t GenSingleRange<U,TYPE,S>::cmeta(char* target, size_t pos) const
|
|
|
|
{
|
|
|
|
if(target){
|
|
|
|
*reinterpret_cast<U*>(target) = mSpace[pos];
|
|
|
|
}
|
|
|
|
return sizeof(U);
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
std::string GenSingleRange<U,TYPE,S>::stringMeta(size_t pos) const
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
|
|
|
return xToString(get(pos));
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> GenSingleRange<U,TYPE,S>::data() const
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
2018-11-07 10:58:07 +01:00
|
|
|
DataHeader h = dataHeader();
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> out;
|
2018-07-21 18:05:53 +02:00
|
|
|
out.reserve(h.metaSize + sizeof(DataHeader));
|
|
|
|
char* hcp = reinterpret_cast<char*>(&h);
|
|
|
|
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
2018-07-22 18:32:43 +02:00
|
|
|
stringCat(out, mSpace);
|
|
|
|
//const char* scp = reinterpret_cast<const char*>(mSpace.data());
|
|
|
|
//out.insert(out.end(), scp, scp + h.metaSize);
|
2018-07-21 18:05:53 +02:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
DataHeader GenSingleRange<U,TYPE,S>::dataHeader() const
|
2018-11-07 10:58:07 +01:00
|
|
|
{
|
|
|
|
DataHeader h;
|
|
|
|
h.spaceType = static_cast<int>( TYPE );
|
|
|
|
h.metaSize = metaSize(mSpace);
|
|
|
|
h.metaType = NumTypeMap<U>::num;
|
|
|
|
h.multiple = 0;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
typename GenSingleRange<U,TYPE,S>::IndexType GenSingleRange<U,TYPE,S>::begin() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleIndex<U,TYPE,S> i( std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> >
|
2017-11-20 21:35:25 +01:00
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
template <typename U, SpaceType TYPE, size_t S>
|
|
|
|
typename GenSingleRange<U,TYPE,S>::IndexType GenSingleRange<U,TYPE,S>::end() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleIndex<U,TYPE,S> i( std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> >
|
2017-11-20 21:35:25 +01:00
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-04 18:29:18 +01:00
|
|
|
#include "range_types/header.h"
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
#endif
|