cnorxz/orig/include/ranges/dynamic_range.h

251 lines
6.2 KiB
C
Raw Normal View History

2018-10-22 14:27:55 +02:00
#ifndef __cxz_dynamic_range_h__
#define __cxz_dynamic_range_h__
2018-10-22 14:27:55 +02:00
#include <cassert>
2020-08-27 12:00:47 +02:00
#include <map>
2018-10-22 14:27:55 +02:00
#include "ranges/rbase_def.h"
#include "ranges/range_base.h"
#include "ranges/index_base.h"
2018-10-29 14:19:42 +01:00
#include "xfor/xfor.h"
2018-10-22 14:27:55 +02:00
2018-10-29 14:19:42 +01:00
#include "ranges/x_to_string.h"
#include "ranges/type_map.h"
#include "ranges/dynamic_meta.h"
2018-10-22 14:27:55 +02:00
2020-08-27 12:00:47 +02:00
#include "index_wrapper.h"
2021-07-28 20:29:56 +02:00
namespace CNORXZ
2018-10-29 14:19:42 +01:00
{
namespace
{
2021-07-28 20:29:56 +02:00
using namespace CNORXZInternal;
}
class DynamicIndex : public IndexInterface<DynamicIndex,vector<char>>
2018-10-22 14:27:55 +02:00
{
private:
typedef vector<std::pair<std::shared_ptr<IndexW>,size_t>> IVecT;
2020-08-26 23:24:10 +02:00
typedef std::map<std::string,std::shared_ptr<IndexW>> IMapT;
static IMapT sIMap;
2018-10-29 14:19:42 +01:00
IVecT mIVec;
bool mIvecInit = false;
2018-10-22 14:27:55 +02:00
public:
typedef IndexInterface<DynamicIndex,vector<char>> IB;
2019-03-14 19:10:06 +01:00
typedef vector<char> MetaType;
typedef DynamicRange RangeType;
2018-10-22 14:27:55 +02:00
typedef DynamicIndex IType;
DynamicIndex(const std::shared_ptr<RangeType>& range);
2018-10-22 14:27:55 +02:00
2020-08-26 23:24:10 +02:00
static void clearIMap() { sIMap.clear(); }
template <class Index>
static std::shared_ptr<Index> getIndexFromMap(const std::string& name)
{
auto tmp = std::dynamic_pointer_cast<IndexWrapper<Index>>(sIMap.at(name));
assert(tmp);
return tmp->getIndex();
}
2020-09-15 17:11:54 +02:00
static const std::shared_ptr<IndexW>& getIndexWFromMap(const std::string& name)
{
return sIMap.at(name);
}
static bool checkIndexMap(const std::string& name)
{
return sIMap.count(name) != 0;
}
2018-10-22 14:27:55 +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::DYN;
IndexType type() const;
DynamicIndex& operator=(size_t pos);
DynamicIndex& operator++();
DynamicIndex& operator--();
2018-10-29 14:19:42 +01:00
DynamicIndex& operator()(const IVecT& ivec);
DynamicIndex& operator()(const vector<std::shared_ptr<IndexW>>& ivec);
2020-08-26 23:24:10 +02:00
DynamicIndex& operator()(const vector<std::string>& inames);
template <class... Indices>
DynamicIndex& operator()(const std::shared_ptr<Indices>&... is);
DynamicIndex& sync();
2018-10-22 14:27:55 +02:00
int pp(std::intptr_t idxPtrNum);
int mm(std::intptr_t idxPtrNum);
std::string stringMeta() const;
MetaType meta() const;
const MetaType* metaPtr() const;
DynamicIndex& at(const MetaType& metaPos);
size_t posAt(const MetaType& metaPos) const;
//bool isMeta(const MetaType& metaPos) const;
2018-10-29 14:19:42 +01:00
size_t dim() const;
bool last() const;
bool first() const;
const IndexW& get(size_t n) const;
2020-09-10 22:50:26 +02:00
const std::shared_ptr<IndexW>& getP(size_t n) const;
2018-10-22 14:27:55 +02:00
std::shared_ptr<RangeType> range();
template <size_t N>
void getPtr();
2018-10-29 14:19:42 +01:00
size_t getStepSize(size_t n) const;
2018-10-22 14:27:55 +02:00
template <class Expr>
2020-07-09 17:37:28 +02:00
DynamicExpression ifor(size_t step, Expr ex) const;
2018-10-22 14:27:55 +02:00
template <class Expr>
2020-07-09 17:37:28 +02:00
DynamicExpression iforh(size_t step, Expr ex) const;
2018-10-22 14:27:55 +02:00
2019-01-15 17:41:43 +01:00
template <class Expr>
2020-07-09 17:37:28 +02:00
DynamicExpression pifor(size_t step, Expr ex) const;
2019-01-15 17:41:43 +01:00
2018-10-22 14:27:55 +02:00
};
2018-10-27 14:58:34 +02:00
2018-10-22 14:27:55 +02:00
// NOT THREAD SAVE!!
class DynamicRangeFactory : public RangeFactoryBase
{
public:
typedef DynamicRange oType;
2018-10-22 14:27:55 +02:00
DynamicRangeFactory();
template <class... RangeTypes>
DynamicRangeFactory(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
template <class... RangeTypes>
DynamicRangeFactory(std::shared_ptr<RangeTypes>... origs);
2019-02-13 21:59:13 +01:00
DynamicRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs);
2018-10-22 14:27:55 +02:00
template <class Range>
void append(std::shared_ptr<Range> r);
2020-08-27 14:02:18 +02:00
std::shared_ptr<RangeBase> create();
2018-10-22 14:27:55 +02:00
private:
2019-02-13 21:59:13 +01:00
std::shared_ptr<RangeBase> checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec);
2018-10-22 14:27:55 +02:00
2019-02-13 21:59:13 +01:00
static std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > mAleadyCreated;
2018-10-22 14:27:55 +02:00
bool mProductCreated = false;
};
2018-10-27 14:58:34 +02:00
class DynamicRange : public RangeInterface<DynamicIndex>
2018-10-22 14:27:55 +02:00
{
public:
static constexpr bool defaultable = true;
static constexpr size_t ISSTATIC = 0;
static constexpr size_t SIZE = -1;
static constexpr bool HASMETACONT = false;
typedef RangeBase RB;
typedef DynamicIndex IndexType;
2018-10-22 14:27:55 +02:00
typedef DynamicRange RangeType;
2019-03-14 19:10:06 +01:00
typedef vector<char> MetaType;
typedef DynamicRangeFactory FType;
2019-03-14 19:10:06 +01:00
2018-10-22 14:27:55 +02:00
private:
DynamicRange() = default;
DynamicRange(const DynamicRange& in) = default;
2018-10-22 14:27:55 +02:00
template <class... RangeTypes>
DynamicRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
2018-10-22 14:27:55 +02:00
template <class... RangeTypes>
DynamicRange(std::shared_ptr<RangeTypes>... origs);
2018-10-22 14:27:55 +02:00
2019-02-13 21:59:13 +01:00
DynamicRange(const vector<std::shared_ptr<RangeBase>>& origs);
2018-10-22 14:27:55 +02:00
size_t mSize = 1;
bool mEmpty = true;
2019-02-13 21:59:13 +01:00
vector<std::shared_ptr<RangeBase> > mOrig;
2018-10-22 14:27:55 +02:00
public:
virtual size_t size() const final;
virtual size_t dim() const final;
MetaType get(size_t pos) const;
size_t getMeta(const MetaType& metaPos) const;
virtual IndexType begin() const final;
virtual IndexType end() const final;
virtual SpaceType spaceType() const final;
2018-11-07 10:58:07 +01:00
virtual DataHeader dataHeader() const final;
virtual vector<size_t> typeNum() const final;
2019-03-14 14:20:38 +01:00
virtual size_t cmeta(char* target, size_t pos) const final;
virtual size_t cmetaSize() const final;
2018-10-22 14:27:55 +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-10-22 14:27:55 +02:00
std::shared_ptr<RangeBase> sub(size_t num) const;
template <class Range>
std::shared_ptr<Range> fullsub(size_t num) const;
template <class... Ranges>
std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast
2019-02-13 21:59:13 +01:00
const vector<std::shared_ptr<RangeBase> >& orig() const;
2018-10-22 14:27:55 +02:00
void sreplace(const std::shared_ptr<RangeBase> in, size_t num);
bool isEmpty() const;
friend DynamicRangeFactory;
2018-10-22 14:27:55 +02:00
static DynamicRangeFactory factory()
{ return DynamicRangeFactory(); }
2018-10-22 14:27:55 +02:00
};
2021-07-28 20:29:56 +02:00
} // namespace CNORXZ
2018-10-22 14:27:55 +02:00
2021-07-28 20:29:56 +02:00
namespace CNORXZ
2018-10-22 14:27:55 +02:00
{
2021-05-27 23:29:04 +02:00
namespace RangeHelper
2018-10-22 14:27:55 +02:00
{
2021-05-27 23:29:04 +02:00
template <>
inline void resolveSetRange<DynamicRange>(std::shared_ptr<DynamicRange>& rp,
const vector<std::shared_ptr<RangeBase> >& orig,
size_t origpos, size_t size);
2018-10-22 14:27:55 +02:00
2021-05-27 23:29:04 +02:00
template <>
inline void setRangeToVec<DynamicRange>(vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<DynamicRange> r);
2018-10-29 14:19:42 +01:00
2021-05-27 23:29:04 +02:00
template <>
inline size_t getStepSize<DynamicIndex>(const DynamicIndex& ii, std::intptr_t j);
}
2018-10-22 14:27:55 +02:00
}
//#include "dynamic_range.cc.h"
2018-10-22 14:27:55 +02:00
#endif