2017-05-31 16:44:28 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
#ifndef __cxz_anonymous_range_h__
|
|
|
|
#define __cxz_anonymous_range_h__
|
2017-05-31 16:44:28 +02:00
|
|
|
|
|
|
|
#include <cstdlib>
|
2018-07-15 15:22:15 +02:00
|
|
|
#include <map>
|
2018-07-16 00:12:05 +02:00
|
|
|
#include "rbase_def.h"
|
2017-12-17 17:40:55 +01:00
|
|
|
#include "ranges/range_base.h"
|
2018-02-14 21:37:18 +01:00
|
|
|
#include "ranges/rpheader.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-05-31 16:44:28 +02:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2017-05-31 16:44:28 +02:00
|
|
|
{
|
|
|
|
|
2019-07-05 17:40:26 +02:00
|
|
|
typedef GenSingleIndex<size_t,SpaceType::ANON,MUI> AnonymousIndex;
|
2017-12-04 18:29:18 +01:00
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
//template <class R>
|
|
|
|
//using SIZET = size_t;
|
2018-07-15 15:22:15 +02:00
|
|
|
|
2019-07-05 17:40:26 +02:00
|
|
|
typedef GenSingleRange<size_t,SpaceType::ANON,MUI> AnonymousRange;
|
2018-07-16 15:55:55 +02:00
|
|
|
|
2018-07-15 15:22:15 +02:00
|
|
|
// NOT THREAD SAVE!!
|
2017-12-04 18:29:18 +01:00
|
|
|
class AnonymousRangeFactory : public RangeFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-12-05 17:31:57 +01:00
|
|
|
typedef AnonymousRange oType;
|
2017-12-04 18:29:18 +01:00
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
AnonymousRangeFactory();
|
2017-12-07 18:11:24 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
|
|
|
AnonymousRangeFactory(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
|
2017-12-07 18:11:24 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
|
|
|
AnonymousRangeFactory(std::shared_ptr<RangeTypes>... origs);
|
2017-12-07 18:11:24 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
AnonymousRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs);
|
2018-11-03 22:03:35 +01:00
|
|
|
|
2018-05-20 20:03:44 +02:00
|
|
|
template <class Range>
|
|
|
|
void append(std::shared_ptr<Range> r);
|
|
|
|
|
2017-12-04 18:29:18 +01:00
|
|
|
std::shared_ptr<RangeBase> create();
|
2018-07-15 15:22:15 +02:00
|
|
|
|
|
|
|
private:
|
2018-07-16 14:44:55 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
std::shared_ptr<RangeBase> checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec);
|
2017-12-04 18:29:18 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
static std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > mAleadyCreated;
|
2018-07-16 14:44:55 +02:00
|
|
|
|
|
|
|
bool mProductCreated = false;
|
2017-12-04 18:29:18 +01:00
|
|
|
};
|
2018-07-16 14:44:55 +02:00
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
template <>
|
2019-07-05 17:40:26 +02:00
|
|
|
class GenSingleRange<size_t,SpaceType::ANON,MUI> : public RangeInterface<AnonymousIndex>
|
2017-05-31 16:44:28 +02:00
|
|
|
{
|
2018-03-21 19:18:57 +01:00
|
|
|
public:
|
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
static constexpr bool defaultable = true;
|
|
|
|
static constexpr size_t ISSTATIC = 0;
|
2019-07-05 17:40:26 +02:00
|
|
|
static constexpr size_t SIZE = MUI;
|
2018-07-16 15:55:55 +02:00
|
|
|
static constexpr bool HASMETACONT = false;
|
2018-03-21 19:18:57 +01:00
|
|
|
|
2017-12-04 18:29:18 +01:00
|
|
|
typedef RangeBase RB;
|
|
|
|
typedef typename RangeInterface<AnonymousIndex>::IndexType IndexType;
|
2019-07-05 17:40:26 +02:00
|
|
|
typedef GenSingleRange<size_t,SpaceType::ANON,MUI> RangeType;
|
2018-07-16 15:55:55 +02:00
|
|
|
typedef size_t MetaType;
|
2019-05-15 20:37:00 +02:00
|
|
|
typedef AnonymousRangeFactory FType;
|
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
virtual size_t size() const final;
|
|
|
|
virtual size_t dim() const final;
|
2018-07-19 21:27:09 +02:00
|
|
|
|
|
|
|
size_t anonymousDim() const;
|
2017-12-05 17:31:57 +01:00
|
|
|
size_t get(size_t pos) const;
|
|
|
|
size_t getMeta(size_t metaPos) const;
|
2017-12-04 18:29:18 +01:00
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
virtual IndexType begin() const final;
|
|
|
|
virtual IndexType end() const final;
|
2018-04-28 17:33:57 +02:00
|
|
|
|
2018-07-28 15:27:11 +02:00
|
|
|
virtual SpaceType spaceType() const final;
|
2018-11-07 10:58:07 +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 14:20:38 +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-07-21 18:05:53 +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-07-21 18:05:53 +02:00
|
|
|
|
2018-04-28 17:33:57 +02:00
|
|
|
std::shared_ptr<RangeBase> sub(size_t num) const;
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
std::shared_ptr<Range> fullsub(size_t num) const;
|
2018-05-20 20:03:44 +02:00
|
|
|
|
|
|
|
template <class... Ranges>
|
2018-07-16 15:55:55 +02:00
|
|
|
std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast
|
2018-08-06 19:20:57 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<std::shared_ptr<RangeBase> >& orig() const;
|
2018-11-02 18:58:58 +01:00
|
|
|
|
2019-01-18 17:49:58 +01:00
|
|
|
std::shared_ptr<AnonymousRange> sreplace(const std::shared_ptr<RangeBase> in, size_t num) const;
|
2019-02-13 21:59:13 +01:00
|
|
|
std::shared_ptr<AnonymousRange> sreplace(const vector<std::shared_ptr<RangeBase>>& in, size_t num) const;
|
2019-03-19 10:33:07 +01:00
|
|
|
std::shared_ptr<AnonymousRange> sreplace(const std::shared_ptr<RangeBase>& in,
|
|
|
|
const vector<size_t>& num) const;
|
2018-09-14 17:50:19 +02:00
|
|
|
|
2018-08-06 19:20:57 +02:00
|
|
|
bool isEmpty() const;
|
2018-04-28 17:33:57 +02:00
|
|
|
|
2017-12-04 18:29:18 +01:00
|
|
|
friend AnonymousRangeFactory;
|
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
static AnonymousRangeFactory factory()
|
|
|
|
{ return AnonymousRangeFactory(); }
|
|
|
|
|
2017-12-04 18:29:18 +01:00
|
|
|
protected:
|
|
|
|
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleRange() = default;
|
|
|
|
GenSingleRange(const AnonymousRange& in) = default;
|
2017-12-04 18:29:18 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
|
2017-12-07 18:11:24 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
2019-02-12 20:26:38 +01:00
|
|
|
GenSingleRange(std::shared_ptr<RangeTypes>... origs);
|
2017-05-31 16:44:28 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
GenSingleRange(const vector<std::shared_ptr<RangeBase>>& origs);
|
2018-11-03 22:03:35 +01:00
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
size_t mSize = 1;
|
2018-08-06 19:20:57 +02:00
|
|
|
bool mEmpty = true;
|
2017-12-04 18:29:18 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<std::shared_ptr<RangeBase> > mOrig;
|
2017-05-31 16:44:28 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2017-12-04 18:29:18 +01:00
|
|
|
{
|
|
|
|
|
2017-12-05 17:31:57 +01:00
|
|
|
/***********************
|
2017-12-04 18:29:18 +01:00
|
|
|
* AnonymousRange *
|
2017-12-05 17:31:57 +01:00
|
|
|
***********************/
|
2018-07-16 15:55:55 +02:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
|
|
|
AnonymousRangeFactory::AnonymousRangeFactory(const std::tuple<std::shared_ptr<RangeTypes>...>& origs)
|
2017-12-07 18:11:24 +01:00
|
|
|
{
|
|
|
|
mProd = std::shared_ptr<oType>( new AnonymousRange( origs ) );
|
|
|
|
}
|
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
|
|
|
AnonymousRangeFactory::AnonymousRangeFactory(std::shared_ptr<RangeTypes>... origs)
|
2017-12-04 18:29:18 +01:00
|
|
|
{
|
2017-12-07 18:11:24 +01:00
|
|
|
mProd = std::shared_ptr<oType>( new AnonymousRange( origs... ) );
|
2017-12-04 18:29:18 +01:00
|
|
|
}
|
2018-05-20 20:03:44 +02:00
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
void AnonymousRangeFactory::append(std::shared_ptr<Range> r)
|
|
|
|
{
|
2018-07-16 14:44:55 +02:00
|
|
|
if(mProductCreated){
|
2018-07-19 21:27:09 +02:00
|
|
|
|
2018-07-16 14:44:55 +02:00
|
|
|
mProd = std::shared_ptr<oType>( new AnonymousRange( *std::dynamic_pointer_cast<oType>(mProd) ) );
|
|
|
|
mProductCreated = false;
|
|
|
|
}
|
2018-05-20 20:03:44 +02:00
|
|
|
std::dynamic_pointer_cast<oType>(mProd)->mOrig.push_back(r);
|
2018-07-16 14:44:55 +02:00
|
|
|
std::dynamic_pointer_cast<oType>(mProd)->mSize *= r->size();
|
2018-08-06 19:20:57 +02:00
|
|
|
std::dynamic_pointer_cast<oType>(mProd)->mEmpty = false;
|
2018-07-15 15:22:15 +02:00
|
|
|
}
|
2018-07-16 00:12:05 +02:00
|
|
|
|
|
|
|
/*****************
|
|
|
|
* Functions *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
std::shared_ptr<AnonymousRange> defaultRange(size_t size = 0);
|
|
|
|
}
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-07-16 00:12:05 +02:00
|
|
|
{
|
2021-05-27 18:37:15 +02:00
|
|
|
namespace RangeHelper
|
2018-07-16 00:12:05 +02:00
|
|
|
{
|
2021-05-27 18:37:15 +02:00
|
|
|
template <>
|
|
|
|
inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange>& rp,
|
|
|
|
const vector<std::shared_ptr<RangeBase> >& orig,
|
|
|
|
size_t origpos, size_t size)
|
|
|
|
{
|
|
|
|
AnonymousRangeFactory arf;
|
|
|
|
for(size_t op = origpos; op != origpos + size; ++op){
|
|
|
|
//VCHECK(op);
|
|
|
|
arf.append(orig[op]);
|
|
|
|
}
|
|
|
|
rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
2018-07-16 00:12:05 +02:00
|
|
|
}
|
2021-05-27 18:37:15 +02:00
|
|
|
|
2018-07-16 12:58:06 +02:00
|
|
|
|
2021-05-27 23:29:04 +02:00
|
|
|
template <>
|
|
|
|
inline void setRangeToVec<AnonymousRange>(vector<std::shared_ptr<RangeBase> >& v,
|
|
|
|
std::shared_ptr<AnonymousRange> r)
|
|
|
|
{
|
|
|
|
if(not r->isEmpty()){
|
|
|
|
for(size_t i = r->anonymousDim(); i != 0; --i){
|
|
|
|
v.insert(v.begin(), r->sub(i-1));
|
|
|
|
}
|
2018-08-06 19:20:57 +02:00
|
|
|
}
|
2018-07-16 12:58:06 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-16 00:12:05 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-07-16 00:12:05 +02:00
|
|
|
{
|
2017-12-05 17:31:57 +01:00
|
|
|
/***********************
|
2017-12-04 18:29:18 +01:00
|
|
|
* AnonymousRange *
|
2017-12-05 17:31:57 +01:00
|
|
|
***********************/
|
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
2019-07-05 17:40:26 +02:00
|
|
|
GenSingleRange<size_t,SpaceType::ANON,MUI>::GenSingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
2017-12-07 18:11:24 +01:00
|
|
|
RangeInterface<AnonymousIndex>()
|
|
|
|
{
|
2021-05-27 18:37:15 +02:00
|
|
|
mOrig.resize(sizeof...(RangeTypes));
|
|
|
|
sfor_pn<0,sizeof...(RangeTypes)>
|
|
|
|
( [&](auto i) { mOrig[i] = std::get<i>(origs); return 0; } );
|
2021-05-27 11:02:36 +02:00
|
|
|
mSize = sfor_p<0,sizeof...(RangeTypes)>
|
|
|
|
( [&](auto i) { return std::get<i>(origs)->size(); },
|
|
|
|
[&](auto a, auto b) { return a * b; } );
|
2018-08-06 19:20:57 +02:00
|
|
|
if(sizeof...(RangeTypes)){
|
|
|
|
mEmpty = false;
|
|
|
|
}
|
2017-12-07 18:11:24 +01:00
|
|
|
}
|
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
template <class... RangeTypes>
|
2019-07-05 17:40:26 +02:00
|
|
|
GenSingleRange<size_t,SpaceType::ANON,MUI>::GenSingleRange(std::shared_ptr<RangeTypes>... origs) :
|
2017-12-04 18:29:18 +01:00
|
|
|
RangeInterface<AnonymousIndex>()
|
|
|
|
{
|
2017-12-07 18:11:24 +01:00
|
|
|
auto rst = std::make_tuple(origs...);
|
2021-05-27 18:37:15 +02:00
|
|
|
mOrig.resize(sizeof...(RangeTypes));
|
|
|
|
sfor_pn<0,sizeof...(RangeTypes)>
|
|
|
|
( [&](auto i) { mOrig[i] = std::get<i>(rst); return 0; } );
|
2021-05-27 11:02:36 +02:00
|
|
|
mSize = sfor_p<0,sizeof...(RangeTypes)>
|
|
|
|
( [&](auto i) { return std::get<i>(rst)->size(); },
|
|
|
|
[&](auto a, auto b) { return a * b; } );
|
2018-08-06 19:20:57 +02:00
|
|
|
if(sizeof...(RangeTypes)){
|
|
|
|
mEmpty = false;
|
|
|
|
}
|
2017-12-04 18:29:18 +01:00
|
|
|
}
|
2018-11-03 22:03:35 +01:00
|
|
|
|
2018-04-28 17:33:57 +02:00
|
|
|
template <class Range>
|
2019-07-05 17:40:26 +02:00
|
|
|
std::shared_ptr<Range> GenSingleRange<size_t,SpaceType::ANON,MUI>::fullsub(size_t num) const
|
2018-04-28 17:33:57 +02:00
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<Range>( mOrig.at(num) );
|
|
|
|
}
|
2018-05-20 20:03:44 +02:00
|
|
|
|
|
|
|
template <class... Ranges>
|
2019-07-05 17:40:26 +02:00
|
|
|
std::shared_ptr<MultiRange<Ranges...> > GenSingleRange<size_t,SpaceType::ANON,MUI>::scast(SIZET<Ranges>... sizes) const
|
2018-05-20 20:03:44 +02:00
|
|
|
{
|
2018-07-16 15:55:55 +02:00
|
|
|
std::tuple<std::shared_ptr<Ranges>...> rtp;
|
2021-05-27 18:37:15 +02:00
|
|
|
RangeHelper::resolveRangeType<0>(mOrig, rtp, 0, sizes...);
|
2018-07-16 00:12:05 +02:00
|
|
|
MultiRangeFactory<Ranges...> mrf(rtp);
|
2018-07-16 15:55:55 +02:00
|
|
|
return std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
2018-05-20 20:03:44 +02:00
|
|
|
}
|
2018-04-28 17:33:57 +02:00
|
|
|
|
2018-02-14 21:37:18 +01:00
|
|
|
|
2018-07-16 00:12:05 +02:00
|
|
|
|
2017-12-04 18:29:18 +01:00
|
|
|
}
|
2017-05-31 16:44:28 +02:00
|
|
|
|
|
|
|
#endif
|