2018-09-12 17:05:27 +02:00
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
#ifndef __cxz_value_range_h__
|
|
|
|
#define __cxz_value_range_h__
|
2018-09-12 17:05:27 +02:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "rbase_def.h"
|
|
|
|
//#include "base_def.h"
|
|
|
|
#include "ranges/rpheader.h"
|
|
|
|
#include "ranges/index_base.h"
|
|
|
|
#include "ranges/range_base.h"
|
|
|
|
#include "ranges/x_to_string.h"
|
|
|
|
#include "ranges/type_map.h"
|
|
|
|
|
|
|
|
#include "xfor/for_type.h"
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-09-12 17:05:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2021-07-28 20:29:56 +02:00
|
|
|
using namespace CNORXZInternal;
|
2018-09-12 17:05:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
class ValueIndex : public IndexInterface<ValueIndex<U>,U>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef IndexInterface<ValueIndex<U>,U> IB;
|
|
|
|
typedef U MetaType;
|
|
|
|
typedef ValueRange<U> RangeType;
|
|
|
|
typedef ValueIndex IType;
|
|
|
|
|
2018-09-12 20:56:55 +02:00
|
|
|
ValueIndex(const std::shared_ptr<RangeType>& rptr);
|
2018-09-12 17:05:27 +02:00
|
|
|
|
|
|
|
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
|
|
|
static constexpr size_t totalDim() { return 1; }
|
|
|
|
static constexpr size_t sDim() { return 1; }
|
|
|
|
|
|
|
|
static constexpr SpaceType STYPE = SpaceType::NONE;
|
|
|
|
|
|
|
|
IndexType type() const;
|
|
|
|
|
|
|
|
ValueIndex& operator=(size_t pos);
|
|
|
|
ValueIndex& operator++();
|
|
|
|
ValueIndex& operator--();
|
|
|
|
|
|
|
|
int pp(std::intptr_t idxPtrNum);
|
|
|
|
int mm(std::intptr_t idxPtrNum);
|
|
|
|
|
|
|
|
std::string stringMeta() const;
|
|
|
|
const U& meta() const;
|
|
|
|
const U* metaPtr() const;
|
|
|
|
ValueIndex& at(const U& metaPos);
|
|
|
|
size_t posAt(const U& metaPos) const;
|
|
|
|
|
|
|
|
size_t dim(); // = 1
|
|
|
|
bool last();
|
|
|
|
bool first();
|
|
|
|
|
|
|
|
std::shared_ptr<RangeType> range();
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
void getPtr();
|
|
|
|
|
|
|
|
size_t getStepSize(size_t n);
|
|
|
|
|
|
|
|
template <class Expr>
|
2018-09-18 01:44:11 +02:00
|
|
|
auto ifor(size_t step, Expr ex) const
|
2018-09-12 17:05:27 +02:00
|
|
|
-> For<ValueIndex<U>,Expr>;
|
|
|
|
|
|
|
|
template <class Expr>
|
2018-09-18 01:44:11 +02:00
|
|
|
auto iforh(size_t step, Expr ex) const
|
2018-09-12 17:05:27 +02:00
|
|
|
-> For<ValueIndex<U>,Expr,ForType::HIDDEN>;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<RangeType> mExplicitRangePtr;
|
|
|
|
U mMeta;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
class ValueRangeFactory : public RangeFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef ValueRange<U> oType;
|
|
|
|
|
|
|
|
ValueRangeFactory();
|
|
|
|
std::shared_ptr<RangeBase> create();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
class ValueRange : public RangeInterface<ValueIndex<U> >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef RangeBase RB;
|
|
|
|
typedef ValueIndex<U> IndexType;
|
|
|
|
typedef ValueRange RangeType;
|
|
|
|
typedef U MetaType;
|
2019-03-14 19:10:06 +01:00
|
|
|
typedef ValueRangeFactory<U> FType;
|
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
virtual size_t size() const final;
|
|
|
|
virtual size_t dim() const final;
|
|
|
|
|
|
|
|
virtual SpaceType spaceType() const final;
|
2018-11-07 13:27:45 +01:00
|
|
|
virtual DataHeader dataHeader() const final;
|
|
|
|
|
2019-03-19 20:58:59 +01:00
|
|
|
virtual vector<size_t> typeNum() const final;
|
2019-03-14 19:10:06 +01:00
|
|
|
virtual size_t cmeta(char* target, size_t pos) const final;
|
2019-03-19 20:58:59 +01:00
|
|
|
virtual size_t cmetaSize() const final;
|
2018-09-12 17:05:27 +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;
|
2018-09-12 17:05:27 +02:00
|
|
|
|
2018-11-26 18:23:38 +01:00
|
|
|
U get(size_t pos) const;
|
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
virtual IndexType begin() const final;
|
|
|
|
virtual IndexType end() const final;
|
|
|
|
|
|
|
|
friend ValueRangeFactory<U>;
|
|
|
|
|
|
|
|
static constexpr bool defaultable = true;
|
|
|
|
static constexpr size_t ISSTATIC = 1;
|
|
|
|
static constexpr size_t SIZE = 1;
|
|
|
|
static constexpr bool HASMETACONT = false;
|
|
|
|
|
2018-09-12 20:56:55 +02:00
|
|
|
static std::shared_ptr<ValueRange> Default()
|
|
|
|
{
|
|
|
|
ValueRangeFactory<U> vrf;
|
|
|
|
return std::dynamic_pointer_cast<ValueRange>( vrf.create() );
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
protected:
|
2018-11-26 18:23:38 +01:00
|
|
|
mutable U const* mMeta;
|
2018-09-12 17:05:27 +02:00
|
|
|
ValueRange() = default;
|
|
|
|
};
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // namespace CNORXZ
|
2018-09-12 17:05:27 +02:00
|
|
|
|
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-09-12 17:05:27 +02:00
|
|
|
{
|
|
|
|
/*****************
|
|
|
|
* ValueIndex *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template<typename U>
|
|
|
|
std::shared_ptr<RangeBase> mkDefaultValueRange()
|
|
|
|
{
|
|
|
|
ValueRangeFactory<U> vrf;
|
2018-09-12 20:56:55 +02:00
|
|
|
return vrf.create();
|
2018-09-12 17:05:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
2018-09-12 20:56:55 +02:00
|
|
|
ValueIndex<U>::ValueIndex(const std::shared_ptr<RangeType>& rptr) :
|
|
|
|
IndexInterface<ValueIndex<U>,U>(rptr, 0),
|
|
|
|
mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr))
|
|
|
|
{}
|
2018-09-12 17:05:27 +02:00
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
IndexType ValueIndex<U>::type() const
|
|
|
|
{
|
|
|
|
return IndexType::SINGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
ValueIndex<U>& ValueIndex<U>::operator=(size_t pos)
|
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
ValueIndex<U>& ValueIndex<U>::operator++()
|
|
|
|
{
|
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
ValueIndex<U>& ValueIndex<U>::operator--()
|
|
|
|
{
|
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
int ValueIndex<U>::pp(std::intptr_t idxPtrNum)
|
|
|
|
{
|
|
|
|
++(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
int ValueIndex<U>::mm(std::intptr_t idxPtrNum)
|
|
|
|
{
|
|
|
|
--(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
std::string ValueIndex<U>::stringMeta() const
|
|
|
|
{
|
|
|
|
return xToString(mMeta);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
const U& ValueIndex<U>::meta() const
|
|
|
|
{
|
|
|
|
return mMeta;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
const U* ValueIndex<U>::metaPtr() const
|
|
|
|
{
|
|
|
|
return &mMeta;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
ValueIndex<U>& ValueIndex<U>::at(const U& metaPos)
|
|
|
|
{
|
|
|
|
mMeta = metaPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
size_t ValueIndex<U>::posAt(const U& metaPos) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
size_t ValueIndex<U>::dim() // = 1
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
bool ValueIndex<U>::last()
|
|
|
|
{
|
|
|
|
return IB::mPos == IB::mMax - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
bool ValueIndex<U>::first()
|
|
|
|
{
|
|
|
|
return IB::mPos == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
std::shared_ptr<typename ValueIndex<U>::RangeType> ValueIndex<U>::range()
|
|
|
|
{
|
2018-11-26 18:23:38 +01:00
|
|
|
return mExplicitRangePtr;
|
2018-09-12 17:05:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
template <size_t N>
|
|
|
|
void ValueIndex<U>::getPtr() {}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
size_t ValueIndex<U>::getStepSize(size_t n)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
template <class Expr>
|
2018-09-18 01:44:11 +02:00
|
|
|
auto ValueIndex<U>::ifor(size_t step, Expr ex) const
|
2018-09-12 17:05:27 +02:00
|
|
|
-> For<ValueIndex<U>,Expr>
|
|
|
|
{
|
|
|
|
//static const size_t LAYER = typename Expr::LAYER;
|
2018-09-18 01:44:11 +02:00
|
|
|
return For<ValueIndex<U>,Expr>(this, step, ex);
|
2018-09-12 17:05:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
template <class Expr>
|
2018-09-18 01:44:11 +02:00
|
|
|
auto ValueIndex<U>::iforh(size_t step, Expr ex) const
|
2018-09-12 17:05:27 +02:00
|
|
|
-> For<ValueIndex<U>,Expr,ForType::HIDDEN>
|
|
|
|
{
|
|
|
|
//static const size_t LAYER = typename Expr::LAYER;
|
2018-09-18 01:44:11 +02:00
|
|
|
return For<ValueIndex<U>,Expr,ForType::HIDDEN>(this, step, ex);
|
2018-09-12 17:05:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************
|
|
|
|
* ValueRangeFactory *
|
|
|
|
**************************/
|
|
|
|
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
ValueRangeFactory<U>::ValueRangeFactory()
|
|
|
|
{
|
|
|
|
mProd = std::shared_ptr<oType>( new ValueRange<U>() );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
std::shared_ptr<RangeBase> ValueRangeFactory<U>::create()
|
|
|
|
{
|
|
|
|
setSelf();
|
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************
|
|
|
|
* ValueRange *
|
|
|
|
*******************/
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
size_t ValueRange<U>::size() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
size_t ValueRange<U>::dim() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
SpaceType ValueRange<U>::spaceType() const
|
|
|
|
{
|
|
|
|
return SpaceType::NONE;
|
|
|
|
}
|
2019-03-14 14:20:38 +01:00
|
|
|
|
|
|
|
template <typename U>
|
2019-03-19 20:58:59 +01:00
|
|
|
vector<size_t> ValueRange<U>::typeNum() const
|
2019-03-14 14:20:38 +01:00
|
|
|
{
|
2020-07-08 23:34:17 +02:00
|
|
|
return {NumTypeMap<U>::num()};
|
2019-03-14 14:20:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
size_t ValueRange<U>::cmeta(char* target, size_t pos) const
|
|
|
|
{
|
2019-03-19 20:58:59 +01:00
|
|
|
*reinterpret_cast<U*>(target) = *mMeta;
|
|
|
|
return sizeof(U);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
size_t ValueRange<U>::cmetaSize() const
|
|
|
|
{
|
2019-03-14 14:20:38 +01:00
|
|
|
return sizeof(U);
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
template <typename U>
|
|
|
|
std::string ValueRange<U>::stringMeta(size_t pos) const
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-11-26 18:23:38 +01:00
|
|
|
template <typename U>
|
|
|
|
U ValueRange<U>::get(size_t pos) const
|
|
|
|
{
|
|
|
|
return *mMeta;
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
template <typename U>
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> ValueRange<U>::data() const
|
2018-09-12 17:05:27 +02:00
|
|
|
{
|
|
|
|
assert(0);
|
2018-11-07 13:27:45 +01:00
|
|
|
DataHeader h = dataHeader();
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> out;
|
2018-09-12 17:05:27 +02:00
|
|
|
out.reserve(h.metaSize + sizeof(DataHeader));
|
|
|
|
char* hcp = reinterpret_cast<char*>(&h);
|
|
|
|
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
|
|
|
|
|
|
|
//const char* scp = reinterpret_cast<const char*>(mSpace.data());
|
|
|
|
//out.insert(out.end(), scp, scp + h.metaSize);
|
|
|
|
return out;
|
|
|
|
}
|
2018-11-07 13:27:45 +01:00
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
DataHeader ValueRange<U>::dataHeader() const
|
|
|
|
{
|
|
|
|
DataHeader h;
|
|
|
|
h.spaceType = static_cast<int>( SpaceType::NONE );
|
|
|
|
h.metaSize = 0;
|
2020-07-08 23:34:17 +02:00
|
|
|
h.metaType = NumTypeMap<U>::num();
|
2018-11-07 13:27:45 +01:00
|
|
|
h.multiple = 0;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:05:27 +02:00
|
|
|
template <typename U>
|
|
|
|
typename ValueRange<U>::IndexType ValueRange<U>::begin() const
|
|
|
|
{
|
|
|
|
ValueIndex<U> i( std::dynamic_pointer_cast<ValueRange<U> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = 0;
|
2018-11-26 18:23:38 +01:00
|
|
|
mMeta = &i.meta();
|
2018-09-12 17:05:27 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
typename ValueRange<U>::IndexType ValueRange<U>::end() const
|
|
|
|
{
|
|
|
|
ValueIndex<U> i( std::dynamic_pointer_cast<ValueRange<U> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = size();
|
2018-11-26 18:23:38 +01:00
|
|
|
mMeta = &i.meta();
|
2018-09-12 17:05:27 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // namespace CNORXZ
|
2018-09-12 17:05:27 +02:00
|
|
|
|
|
|
|
#endif
|