2018-12-21 11:30:39 +01:00
|
|
|
|
|
|
|
#ifndef __subrange_h__
|
|
|
|
#define __subrange_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "base_def.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-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2021-07-28 20:29:56 +02:00
|
|
|
using namespace CNORXZInternal;
|
2018-12-21 11:30:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
class SubIndex : public IndexInterface<SubIndex<Index>,typename Index::MetaType>
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
2018-12-21 18:25:45 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
typedef IndexInterface<SubIndex<Index>,typename Index::MetaType> IB;
|
|
|
|
typedef typename Index::MetaType MetaType;
|
|
|
|
typedef SubRange<typename Index::RangeType> RangeType;
|
|
|
|
typedef SubIndex IType;
|
2018-12-21 11:30:39 +01:00
|
|
|
|
|
|
|
SubIndex(const std::shared_ptr<RangeType>& range);
|
|
|
|
|
2018-12-23 19:33:01 +01:00
|
|
|
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
|
|
|
static constexpr size_t totalDim() { return 1; }
|
|
|
|
static constexpr size_t sDim() { return 1; }
|
2018-12-21 11:30:39 +01:00
|
|
|
|
2018-12-21 18:25:45 +01:00
|
|
|
static constexpr SpaceType STYPE = Index::STYPE;
|
2018-12-21 11:30:39 +01:00
|
|
|
|
|
|
|
IndexType type() const;
|
|
|
|
|
|
|
|
SubIndex& operator=(size_t pos);
|
|
|
|
SubIndex& operator++();
|
|
|
|
SubIndex& operator--();
|
|
|
|
|
2018-12-21 18:25:45 +01:00
|
|
|
SubIndex& operator()(const std::shared_ptr<Index>& ind); // set full index
|
|
|
|
|
2018-12-21 11:30:39 +01:00
|
|
|
int pp(std::intptr_t idxPtrNum);
|
|
|
|
int mm(std::intptr_t idxPtrNum);
|
|
|
|
|
|
|
|
std::string stringMeta() const;
|
2018-12-21 18:25:45 +01:00
|
|
|
MetaType meta() const;
|
|
|
|
const MetaType* metaPtr() const;
|
|
|
|
SubIndex& at(const MetaType& metaPos);
|
|
|
|
size_t posAt(const MetaType& metaPos) const;
|
2018-12-21 11:30:39 +01:00
|
|
|
|
2018-12-21 18:25:45 +01:00
|
|
|
bool isMeta(const MetaType& metaPos) const;
|
2018-12-21 11:30:39 +01:00
|
|
|
|
|
|
|
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>
|
|
|
|
auto ifor(size_t step, Expr ex) const
|
|
|
|
-> For<SubIndex<Index>,SubExpr<Index,Expr>>;
|
|
|
|
|
|
|
|
template <class Expr>
|
|
|
|
auto iforh(size_t step, Expr ex) const
|
2018-12-23 13:01:13 +01:00
|
|
|
-> For<SubIndex<Index>,SubExpr<Index,Expr>,ForType::HIDDEN>;
|
|
|
|
|
2019-01-16 12:33:50 +01:00
|
|
|
template <class Expr>
|
|
|
|
auto pifor(size_t step, Expr ex) const
|
|
|
|
-> decltype(ifor(step, ex)); // no multithreading here (check!!)
|
|
|
|
|
2018-12-21 11:30:39 +01:00
|
|
|
private:
|
|
|
|
std::shared_ptr<RangeType> mExplicitRangePtr;
|
|
|
|
//const U* mMetaPtr;
|
|
|
|
std::shared_ptr<Index> mFullIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
class SubRangeFactory : public RangeFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef SubRange<Range> oType;
|
|
|
|
|
|
|
|
SubRangeFactory() = delete;
|
|
|
|
SubRangeFactory(const std::shared_ptr<Range>& fullRange,
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<size_t>& subset);
|
2018-12-21 11:30:39 +01:00
|
|
|
std::shared_ptr<RangeBase> create();
|
2018-12-21 18:25:45 +01:00
|
|
|
};
|
2018-12-21 11:30:39 +01:00
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
class SubRange : public RangeInterface<SubIndex<typename Range::IndexType>>
|
|
|
|
{
|
2019-04-02 19:39:11 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
SubRange() = delete;
|
|
|
|
SubRange(const SubRange& in) = delete;
|
|
|
|
|
|
|
|
SubRange(const std::shared_ptr<Range>& fullRange, const vector<size_t>& subset);
|
|
|
|
|
|
|
|
std::shared_ptr<Range> mFullRange;
|
|
|
|
vector<size_t> mSubSet;
|
|
|
|
|
2018-12-21 11:30:39 +01:00
|
|
|
public:
|
|
|
|
typedef RangeBase RB;
|
|
|
|
typedef SubIndex<typename Range::IndexType> IndexType;
|
|
|
|
typedef SubRange RangeType;
|
|
|
|
typedef typename IndexType::MetaType MetaType;
|
|
|
|
typedef SubRangeFactory<Range> FType;
|
|
|
|
|
|
|
|
virtual size_t size() const final;
|
|
|
|
virtual size_t dim() const final;
|
|
|
|
|
|
|
|
virtual SpaceType spaceType() const final;
|
|
|
|
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-12-21 11:30:39 +01: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-12-21 11:30:39 +01:00
|
|
|
|
2018-12-21 18:25:45 +01:00
|
|
|
bool isMeta(const MetaType& metaPos) const;
|
2018-12-21 11:30:39 +01:00
|
|
|
|
2019-04-02 19:39:11 +02:00
|
|
|
auto get(size_t pos) const
|
|
|
|
-> decltype(mFullRange->get(mSubSet[pos]));
|
2018-12-21 18:25:45 +01:00
|
|
|
size_t getMeta(const MetaType& metaPos) const;
|
2018-12-21 11:30:39 +01:00
|
|
|
|
|
|
|
virtual IndexType begin() const final;
|
|
|
|
virtual IndexType end() const final;
|
|
|
|
|
|
|
|
std::shared_ptr<Range> fullRange() const;
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<size_t>& subset() const;
|
2018-12-21 18:25:45 +01:00
|
|
|
std::shared_ptr<SingleRange<MetaType,SpaceType::ANY>> outRange() const;
|
2018-12-21 11:30:39 +01:00
|
|
|
|
|
|
|
friend SubRangeFactory<Range>;
|
|
|
|
|
|
|
|
static constexpr bool defaultable = false;
|
|
|
|
static constexpr size_t ISSTATIC = 0;
|
|
|
|
static constexpr size_t SIZE = -1;
|
|
|
|
static constexpr bool HASMETACONT = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // namespace CNORXZ
|
2018-12-21 11:30:39 +01:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
* SubIndex *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
SubIndex<Index>::SubIndex(const std::shared_ptr<RangeType>& range) :
|
2018-12-21 18:25:45 +01:00
|
|
|
IndexInterface<SubIndex<Index>,typename Index::MetaType>(range, 0),
|
|
|
|
mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr))
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
mFullIndex = std::make_shared<Index>(mExplicitRangePtr->fullRange());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
IndexType SubIndex<Index>::type() const
|
|
|
|
{
|
|
|
|
return IndexType::SINGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
SubIndex<Index>& SubIndex<Index>::operator=(size_t pos)
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
|
|
|
(*mFullIndex) = mExplicitRangePtr->subset()[IB::mPos];
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
SubIndex<Index>& SubIndex<Index>::operator++()
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
++IB::mPos;
|
|
|
|
(*mFullIndex) = mExplicitRangePtr->subset()[IB::mPos];
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
SubIndex<Index>& SubIndex<Index>::operator--()
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
--IB::mPos;
|
|
|
|
(*mFullIndex) = mExplicitRangePtr->subset()[IB::mPos];
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-21 18:25:45 +01:00
|
|
|
template <class Index>
|
|
|
|
SubIndex<Index>& SubIndex<Index>::operator()(const std::shared_ptr<Index>& ind)
|
|
|
|
{
|
|
|
|
assert(mFullIndex->range() == ind->range());
|
|
|
|
mFullIndex = ind;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:30:39 +01:00
|
|
|
template <class Index>
|
|
|
|
int SubIndex<Index>::pp(std::intptr_t idxPtrNum)
|
|
|
|
{
|
|
|
|
++(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
int SubIndex<Index>::mm(std::intptr_t idxPtrNum)
|
|
|
|
{
|
|
|
|
--(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
std::string SubIndex<Index>::stringMeta() const
|
|
|
|
{
|
2018-12-21 18:25:45 +01:00
|
|
|
return std::dynamic_pointer_cast<SingleRange<MetaType,STYPE> const>( IB::mRangePtr )->stringMeta(IB::mPos);
|
2018-12-21 11:30:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
typename SubIndex<Index>::MetaType SubIndex<Index>::meta() const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
2018-12-21 18:25:45 +01:00
|
|
|
MetaType* x = nullptr;
|
2018-12-21 11:30:39 +01:00
|
|
|
return MetaPtrHandle<SubIndex<Index>::RangeType::HASMETACONT>::getMeta
|
2018-12-21 18:25:45 +01:00
|
|
|
( x, IB::mPos, mExplicitRangePtr );
|
2018-12-21 11:30:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
const typename SubIndex<Index>::MetaType* SubIndex<Index>::metaPtr() const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
assert(0); // not sure where it is used
|
|
|
|
return mFullIndex->metaPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
SubIndex<Index>& SubIndex<Index>::at(const MetaType& metaPos)
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
(*this) = mExplicitRangePtr->getMeta( metaPos );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
size_t SubIndex<Index>::posAt(const MetaType& metaPos) const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
return mExplicitRangePtr->getMeta( metaPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
bool SubIndex<Index>::isMeta(const MetaType& metaPos) const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
return mExplicitRangePtr->isMeta( metaPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
size_t SubIndex<Index>::dim()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
bool SubIndex<Index>::last()
|
|
|
|
{
|
|
|
|
return IB::mPos == IB::mMax - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
bool SubIndex<Index>::first()
|
|
|
|
{
|
|
|
|
return IB::mPos == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
2018-12-21 18:25:45 +01:00
|
|
|
std::shared_ptr<typename SubIndex<Index>::RangeType> SubIndex<Index>::range()
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
return mExplicitRangePtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
template <size_t N>
|
|
|
|
void SubIndex<Index>::getPtr() {}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
size_t SubIndex<Index>::getStepSize(size_t n)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Index>
|
|
|
|
template <class Expr>
|
|
|
|
auto SubIndex<Index>::ifor(size_t step, Expr ex) const
|
|
|
|
-> For<SubIndex<Index>,SubExpr<Index,Expr>>
|
|
|
|
{
|
|
|
|
return For<SubIndex<Index>,SubExpr<Index,Expr>>
|
2018-12-21 23:41:14 +01:00
|
|
|
(this, step, SubExpr<Index,Expr>
|
2018-12-21 23:02:35 +01:00
|
|
|
( mFullIndex, reinterpret_cast<std::intptr_t>(this),
|
2018-12-21 23:41:14 +01:00
|
|
|
&mExplicitRangePtr->subset(), ex ) );
|
2018-12-21 11:30:39 +01:00
|
|
|
}
|
|
|
|
|
2018-12-23 13:01:13 +01:00
|
|
|
template <class Index>
|
|
|
|
template <class Expr>
|
|
|
|
auto SubIndex<Index>::iforh(size_t step, Expr ex) const
|
|
|
|
-> For<SubIndex<Index>,SubExpr<Index,Expr>,ForType::HIDDEN>
|
|
|
|
{
|
|
|
|
return For<SubIndex<Index>,SubExpr<Index,Expr>,ForType::HIDDEN>
|
|
|
|
(this, step, SubExpr<Index,Expr>
|
|
|
|
( mFullIndex, reinterpret_cast<std::intptr_t>(this),
|
|
|
|
&mExplicitRangePtr->subset(), ex ) );
|
|
|
|
}
|
|
|
|
|
2019-01-16 12:33:50 +01:00
|
|
|
template <class Index>
|
|
|
|
template <class Expr>
|
|
|
|
auto SubIndex<Index>::pifor(size_t step, Expr ex) const
|
|
|
|
-> decltype(ifor(step, ex))
|
|
|
|
{
|
|
|
|
return ifor(step, ex);
|
|
|
|
}
|
2018-12-23 13:01:13 +01:00
|
|
|
|
2018-12-21 11:30:39 +01:00
|
|
|
/************************
|
|
|
|
* SubRangeFactory *
|
|
|
|
************************/
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
SubRangeFactory<Range>::SubRangeFactory(const std::shared_ptr<Range>& fullRange,
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<size_t>& subset)
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
mProd = std::shared_ptr<oType>( new SubRange<Range>( fullRange, subset ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
std::shared_ptr<RangeBase> SubRangeFactory<Range>::create()
|
|
|
|
{
|
|
|
|
setSelf();
|
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
* SubRange *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
SubRange<Range>::SubRange(const std::shared_ptr<Range>& fullRange,
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<size_t>& subset) :
|
2018-12-21 18:25:45 +01:00
|
|
|
RangeInterface<SubIndex<typename Range::IndexType>>(),
|
2018-12-21 11:30:39 +01:00
|
|
|
mFullRange(fullRange), mSubSet(subset) {}
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
size_t SubRange<Range>::size() const
|
|
|
|
{
|
|
|
|
return mSubSet.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
size_t SubRange<Range>::dim() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
SpaceType SubRange<Range>::spaceType() const
|
|
|
|
{
|
|
|
|
return SpaceType::ANY;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
DataHeader SubRange<Range>::dataHeader() const
|
|
|
|
{
|
|
|
|
DataHeader h;
|
|
|
|
h.spaceType = static_cast<int>( SpaceType::ANY );
|
|
|
|
h.metaSize = metaSize(mSubSet);
|
2020-07-08 23:34:17 +02:00
|
|
|
h.metaType = NumTypeMap<MetaType>::num();
|
2018-12-21 11:30:39 +01:00
|
|
|
h.multiple = 0;
|
|
|
|
return h;
|
|
|
|
}
|
2018-12-21 18:25:45 +01:00
|
|
|
|
2019-03-14 14:20:38 +01:00
|
|
|
template <class Range>
|
2019-03-19 20:58:59 +01:00
|
|
|
vector<size_t> SubRange<Range>::typeNum() const
|
2019-03-14 14:20:38 +01:00
|
|
|
{
|
|
|
|
return mFullRange->typeNum();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
size_t SubRange<Range>::cmeta(char* target, size_t pos) const
|
|
|
|
{
|
|
|
|
return mFullRange->cmeta(target, mSubSet[pos]);
|
|
|
|
}
|
|
|
|
|
2019-03-19 20:58:59 +01:00
|
|
|
template <class Range>
|
|
|
|
size_t SubRange<Range>::cmetaSize() const
|
|
|
|
{
|
|
|
|
return mFullRange->cmetaSize();
|
|
|
|
}
|
|
|
|
|
2018-12-21 18:25:45 +01:00
|
|
|
template <class Range>
|
2018-12-21 11:30:39 +01:00
|
|
|
std::string SubRange<Range>::stringMeta(size_t pos) const
|
|
|
|
{
|
|
|
|
return xToString(get(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> SubRange<Range>::data() const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
DataHeader h = dataHeader();
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> out;
|
2018-12-21 11:30:39 +01:00
|
|
|
out.reserve(h.metaSize + sizeof(DataHeader));
|
|
|
|
char* hcp = reinterpret_cast<char*>(&h);
|
|
|
|
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<MetaType> subvec(mSubSet.size());
|
2018-12-21 11:30:39 +01:00
|
|
|
size_t i = 0;
|
|
|
|
for(auto& x: mSubSet){
|
|
|
|
subvec[i++] = mFullRange->get(x);
|
|
|
|
}
|
|
|
|
stringCat(out, subvec);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
2018-12-21 18:25:45 +01:00
|
|
|
bool SubRange<Range>::isMeta(const MetaType& metaPos) const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
for(size_t i = 0; i != size(); ++i){
|
|
|
|
if(get(i) == metaPos){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
2019-04-02 19:39:11 +02:00
|
|
|
auto SubRange<Range>::get(size_t pos) const
|
|
|
|
-> decltype(mFullRange->get(mSubSet[pos]))
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
return mFullRange->get( mSubSet[pos] );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
2018-12-21 18:25:45 +01:00
|
|
|
size_t SubRange<Range>::getMeta(const MetaType& metaPos) const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
for(size_t i = 0; i != size(); ++i){
|
|
|
|
if(get(i) == metaPos){
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
2018-12-21 18:25:45 +01:00
|
|
|
typename SubRange<Range>::IndexType SubRange<Range>::begin() const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
SubRange<Range>::IndexType i( std::dynamic_pointer_cast<SubRange<Range>>
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
2018-12-21 18:25:45 +01:00
|
|
|
typename SubRange<Range>::IndexType SubRange<Range>::end() const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
SubRange<Range>::IndexType i( std::dynamic_pointer_cast<SubRange<Range>>
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
std::shared_ptr<Range> SubRange<Range>::fullRange() const
|
|
|
|
{
|
|
|
|
return mFullRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Range>
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<size_t>& SubRange<Range>::subset() const
|
2018-12-21 11:30:39 +01:00
|
|
|
{
|
|
|
|
return mSubSet;
|
|
|
|
}
|
|
|
|
|
2018-12-21 18:25:45 +01:00
|
|
|
template <class Range>
|
|
|
|
std::shared_ptr<SingleRange<typename SubRange<Range>::MetaType,SpaceType::ANY>> SubRange<Range>::outRange() const
|
|
|
|
{
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<MetaType> ometa(mSubSet.size());
|
2018-12-21 18:25:45 +01:00
|
|
|
size_t i = 0;
|
|
|
|
for(auto& x: mSubSet){
|
|
|
|
ometa[i++] = mFullRange->get(x);
|
|
|
|
}
|
|
|
|
SingleRangeFactory<MetaType,SpaceType::ANY> srf(ometa);
|
|
|
|
return std::dynamic_pointer_cast<SingleRange<MetaType,SpaceType::ANY>>( srf.create() );
|
|
|
|
}
|
2018-12-21 11:30:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|