This commit is contained in:
Christian Zimmermann 2017-12-17 14:23:23 +01:00
parent a3acfedd9b
commit 346101b994
8 changed files with 328 additions and 233 deletions

View file

@ -51,7 +51,7 @@ namespace MultiArrayTools
***********************/ ***********************/
// range_base.h // range_base.h
enum class RangeType; enum class SpaceType;
// range_base.h // range_base.h
class RangeFactoryBase; class RangeFactoryBase;
@ -76,15 +76,15 @@ namespace MultiArrayTools
class IndexInterface; class IndexInterface;
// single_range.h // single_range.h
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
class SingleRange; class SingleRange;
// single_range.h // single_range.h
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
class SingleRangeFactory; class SingleRangeFactory;
// single_range.h // single_range.h
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
class SingleIndex; class SingleIndex;
// multi_range.h // multi_range.h

View file

@ -37,7 +37,7 @@ namespace {
{ {
protected: protected:
typedef SingleRangeFactory<char,RangeType::ANY> SRF; typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange; typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange,SRange> M3RF; typedef MultiRangeFactory<SRange,SRange,SRange> M3RF;

View file

@ -38,7 +38,7 @@ namespace {
{ {
protected: protected:
typedef SingleRangeFactory<char,RangeType::ANY> SRF; typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange; typedef SRF::oType SRange;
MATest_1Dim() MATest_1Dim()
@ -58,7 +58,7 @@ namespace {
{ {
protected: protected:
typedef SingleRangeFactory<char,RangeType::ANY> SRF; typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange; typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange> MRF; typedef MultiRangeFactory<SRange,SRange> MRF;

View file

@ -68,119 +68,34 @@ namespace MultiArrayTools
// Do NOT share index instances between two or more MultiIndex instances // Do NOT share index instances between two or more MultiIndex instances
MultiIndex& operator()(std::shared_ptr<Indices>&... indices); MultiIndex& operator()(std::shared_ptr<Indices>&... indices);
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
// ==== >>>>> STATIC POLYMORPHISM <<<<< ==== // ==== >>>>> STATIC POLYMORPHISM <<<<< ====
IndexType type() { return IndexType::MULTI; } IndexType type();
MultiIndex& operator=(size_t pos) MultiIndex& operator=(size_t pos);
{
IB::mPos = pos;
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
return *this;
}
MultiIndex& operator++() MultiIndex& operator++();
{ MultiIndex& operator--();
PackNum<sizeof...(Indices)-1>::pp( mIPack );
++IB::mPos;
return *this;
}
MultiIndex& operator--() int pp(std::intptr_t idxPtrNum);
{ int mm(std::intptr_t idxPtrNum);
PackNum<sizeof...(Indices)-1>::mm( mIPack );
--IB::mPos;
return *this;
}
int pp(std::intptr_t idxPtrNum) MetaType meta();
{ MultiIndex& at(const MetaType& metaPos);
int tmp = PackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
IB::mPos += tmp;
return tmp;
}
int mm(std::intptr_t idxPtrNum)
{
int tmp = PackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
IB::mPos -= tmp;
return tmp;
}
MetaType meta()
{
MetaType metaTuple;
PackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
return metaTuple;
}
MultiIndex& at(const MetaType& metaPos)
{
PackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this;
}
size_t dim() size_t dim();
{ bool first();
return sizeof...(Indices); bool last();
} std::shared_ptr<RangeType> range();
bool first()
{
return IB::mPos == 0;
}
bool last()
{
return IB::mPos == IB::mMax - 1;
}
std::shared_ptr<RangeType> range()
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
}
template <size_t N> template <size_t N>
auto getPtr() -> decltype( std::get<N>( mIPack ) )& auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
{
return std::get<N>(mIPack);
}
//const IndexBase& get(size_t n); std::shared_ptr<VIWB> getVPtr(size_t n);
std::shared_ptr<VIWB> getVPtr(size_t n) size_t getStepSize(size_t n);
{
if(n >= sizeof...(Indices)){
assert(0);
// throw !!
}
MultiIndex<Indices...> const* t = this;
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
}
size_t getStepSize(size_t n)
{
if(n >= sizeof...(Indices)){
assert(0);
// throw !!
}
return mBlockSizes[n+1];
}
std::string id() { return std::string("mul") + std::to_string(IB::mId); } std::string id();
void print(size_t offset);
void print(size_t offset)
{
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;
PackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
}
}; };
/************************* /*************************
@ -345,6 +260,140 @@ namespace MultiArrayTools
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos); PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
return *this; return *this;
} }
template <class... Indices>
IndexType MultiIndex<Indices...>::type()
{
return IndexType::MULTI;
}
template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
{
IB::mPos = pos;
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
return *this;
}
template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
{
PackNum<sizeof...(Indices)-1>::pp( mIPack );
++IB::mPos;
return *this;
}
template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
{
PackNum<sizeof...(Indices)-1>::mm( mIPack );
--IB::mPos;
return *this;
}
template <class... Indices>
int MultiIndex<Indices...>::pp(std::intptr_t idxPtrNum)
{
int tmp = PackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
IB::mPos += tmp;
return tmp;
}
template <class... Indices>
int MultiIndex<Indices...>::mm(std::intptr_t idxPtrNum)
{
int tmp = PackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
IB::mPos -= tmp;
return tmp;
}
template <class... Indices>
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta()
{
MetaType metaTuple;
PackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
return metaTuple;
}
template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
{
PackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this;
}
template <class... Indices>
size_t MultiIndex<Indices...>::dim()
{
return sizeof...(Indices);
}
template <class... Indices>
bool MultiIndex<Indices...>::first()
{
return IB::mPos == 0;
}
template <class... Indices>
bool MultiIndex<Indices...>::last()
{
return IB::mPos == IB::mMax - 1;
}
template <class... Indices>
std::shared_ptr<typename MultiIndex<Indices...>::RangeType>
MultiIndex<Indices...>::range()
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
}
template <class... Indices>
template <size_t N>
auto MultiIndex<Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>(mIPack);
}
template <class... Indices>
std::shared_ptr<VIWB> MultiIndex<Indices...>::getVPtr(size_t n)
{
if(n >= sizeof...(Indices)){
assert(0);
// throw !!
}
MultiIndex<Indices...> const* t = this;
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
}
template <class... Indices>
size_t MultiIndex<Indices...>::getStepSize(size_t n)
{
if(n >= sizeof...(Indices)){
assert(0);
// throw !!
}
return mBlockSizes[n+1];
}
template <class... Indices>
std::string MultiIndex<Indices...>::id()
{
return std::string("mul") + std::to_string(IB::mId);
}
template <class... Indices>
void MultiIndex<Indices...>::print(size_t offset)
{
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;
PackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
}
/************************* /*************************
* MultiRangeFactory * * MultiRangeFactory *

View file

@ -67,7 +67,7 @@ namespace {
{ {
protected: protected:
typedef SingleRangeFactory<char,RangeType::ANY> SRF; typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange; typedef SRF::oType SRange;
OpTest_1Dim() OpTest_1Dim()
@ -86,7 +86,7 @@ namespace {
{ {
protected: protected:
typedef SingleRangeFactory<char,RangeType::ANY> SRF; typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange; typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange> MRF; typedef MultiRangeFactory<SRange,SRange> MRF;
@ -130,7 +130,7 @@ namespace {
{ {
protected: protected:
typedef SingleRangeFactory<size_t,RangeType::ANY> SRF; typedef SingleRangeFactory<size_t,SpaceType::ANY> SRF;
typedef SRF::oType SRange; typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange> MRF; typedef MultiRangeFactory<SRange,SRange> MRF;

View file

@ -12,7 +12,7 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
enum class RangeType enum class SpaceType
{ {
NONE = 0, NONE = 0,
ANY = 1, ANY = 1,

View file

@ -12,14 +12,14 @@ include_range_type(SPIN,2)
namespace MultiArrayTools namespace MultiArrayTools
{ {
typedef SingleIndex<size_t,RangeType::SPIN> SpinIndex; typedef SingleIndex<size_t,SpaceType::SPIN> SpinIndex;
template <> template <>
class SingleRangeFactory<size_t,RangeType::SPIN> : public RangeFactoryBase class SingleRangeFactory<size_t,SpaceType::SPIN> : public RangeFactoryBase
{ {
public: public:
typedef SingleRange<size_t,RangeType::SPIN> oType; typedef SingleRange<size_t,SpaceType::SPIN> oType;
SingleRangeFactory(); SingleRangeFactory();
std::shared_ptr<RangeBase> create(); std::shared_ptr<RangeBase> create();
@ -27,11 +27,11 @@ namespace MultiArrayTools
}; };
template <> template <>
class SingleRange<size_t,RangeType::SPIN> : public RangeInterface<SpinIndex> class SingleRange<size_t,SpaceType::SPIN> : public RangeInterface<SpinIndex>
{ {
public: public:
typedef RangeBase RB; typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<size_t,RangeType::SPIN> >::IndexType IndexType; typedef typename RangeInterface<SingleIndex<size_t,SpaceType::SPIN> >::IndexType IndexType;
virtual size_t size() const override; virtual size_t size() const override;
virtual size_t dim() const override; virtual size_t dim() const override;
@ -43,13 +43,13 @@ namespace MultiArrayTools
virtual IndexType end() const override; virtual IndexType end() const override;
virtual std::shared_ptr<VIWB> index() const override; virtual std::shared_ptr<VIWB> index() const override;
friend SingleRangeFactory<size_t,RangeType::SPIN>; friend SingleRangeFactory<size_t,SpaceType::SPIN>;
static const bool defaultable = true; static const bool defaultable = true;
static const size_t mSpinNum = 4; static const size_t mSpinNum = 4;
static SingleRangeFactory<size_t, RangeType::SPIN> factory() static SingleRangeFactory<size_t, SpaceType::SPIN> factory()
{ return SingleRangeFactory<size_t, RangeType::SPIN>(); } { return SingleRangeFactory<size_t, SpaceType::SPIN>(); }
protected: protected:
@ -59,8 +59,8 @@ namespace MultiArrayTools
//SingleRange(size_t spinNum); //SingleRange(size_t spinNum);
}; };
typedef SingleRange<size_t,RangeType::SPIN> SpinRange; typedef SingleRange<size_t,SpaceType::SPIN> SpinRange;
typedef SingleRangeFactory<size_t,RangeType::SPIN> SpinRF; typedef SingleRangeFactory<size_t,SpaceType::SPIN> SpinRF;
} }
/* ========================= * /* ========================= *
@ -73,16 +73,16 @@ namespace MultiArrayTools
* SingleRange * * SingleRange *
********************/ ********************/
SingleRangeFactory<size_t,RangeType::SPIN>::SingleRangeFactory() SingleRangeFactory<size_t,SpaceType::SPIN>::SingleRangeFactory()
{ {
// Quasi Singleton // Quasi Singleton
if(not mProd){ if(not mProd){
mProd = std::shared_ptr<oType>( new SingleRange<size_t,RangeType::SPIN>() ); mProd = std::shared_ptr<oType>( new SingleRange<size_t,SpaceType::SPIN>() );
setSelf(); setSelf();
} }
} }
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,RangeType::SPIN>::create() std::shared_ptr<RangeBase> SingleRangeFactory<size_t,SpaceType::SPIN>::create()
{ {
return mProd; return mProd;
} }
@ -91,49 +91,49 @@ namespace MultiArrayTools
* SingleRange * * SingleRange *
********************/ ********************/
size_t SingleRange<size_t,RangeType::SPIN>::get(size_t pos) const size_t SingleRange<size_t,SpaceType::SPIN>::get(size_t pos) const
{ {
return pos; return pos;
} }
size_t SingleRange<size_t,RangeType::SPIN>::getMeta(size_t metaPos) const size_t SingleRange<size_t,SpaceType::SPIN>::getMeta(size_t metaPos) const
{ {
return metaPos; return metaPos;
} }
size_t SingleRange<size_t,RangeType::SPIN>::size() const size_t SingleRange<size_t,SpaceType::SPIN>::size() const
{ {
return mSpinNum; return mSpinNum;
} }
size_t SingleRange<size_t,RangeType::SPIN>::dim() const size_t SingleRange<size_t,SpaceType::SPIN>::dim() const
{ {
return 1; return 1;
} }
typename SingleRange<size_t,RangeType::SPIN>::IndexType SingleRange<size_t,RangeType::SPIN>::begin() const typename SingleRange<size_t,SpaceType::SPIN>::IndexType SingleRange<size_t,SpaceType::SPIN>::begin() const
{ {
SingleIndex<size_t,RangeType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,RangeType::SPIN> > SingleIndex<size_t,SpaceType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0; i = 0;
return i; return i;
} }
typename SingleRange<size_t,RangeType::SPIN>::IndexType SingleRange<size_t,RangeType::SPIN>::end() const typename SingleRange<size_t,SpaceType::SPIN>::IndexType SingleRange<size_t,SpaceType::SPIN>::end() const
{ {
SingleIndex<size_t,RangeType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,RangeType::SPIN> > SingleIndex<size_t,SpaceType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size(); i = size();
return i; return i;
} }
// put this in the interface class !!! // put this in the interface class !!!
std::shared_ptr<VIWB> SingleRange<size_t,RangeType::SPIN>::index() const std::shared_ptr<VIWB> SingleRange<size_t,SpaceType::SPIN>::index() const
{ {
typedef IndexWrapper<IndexType> IW; typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW> return std::make_shared<IW>
( std::make_shared<IndexType> ( std::make_shared<IndexType>
( std::dynamic_pointer_cast<SingleRange<size_t,RangeType::SPIN> > ( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
} }

View file

@ -14,7 +14,7 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
class SingleIndex : public IndexInterface<SingleIndex<U,TYPE>,U> class SingleIndex : public IndexInterface<SingleIndex<U,TYPE>,U>
{ {
public: public:
@ -27,103 +27,37 @@ namespace MultiArrayTools
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range); SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
// ==== >>>>> STATIC POLYMORPHISM <<<<< ==== // ==== >>>>> STATIC POLYMORPHISM <<<<< ====
IndexType type() IndexType type();
{
return IndexType::SINGLE;
}
SingleIndex& operator=(size_t pos) SingleIndex& operator=(size_t pos);
{ SingleIndex& operator++();
IB::mPos = pos; SingleIndex& operator--();
return *this;
}
SingleIndex& operator++() int pp(std::intptr_t idxPtrNum);
{ int mm(std::intptr_t idxPtrNum);
++IB::mPos;
return *this;
}
SingleIndex& operator--()
{
--IB::mPos;
return *this;
}
int pp(std::intptr_t idxPtrNum)
{
++(*this);
return 1;
}
int mm(std::intptr_t idxPtrNum)
{
--(*this);
return 1;
}
U meta() U meta();
{ SingleIndex& at(const U& metaPos);
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->get( IB::pos() );
}
SingleIndex& at(const U& metaPos)
{
(*this) = std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos );
return *this;
}
size_t dim() // = 1 size_t dim(); // = 1
{ bool last();
return 1; bool first();
}
bool last() std::shared_ptr<RangeType> range();
{
return IB::mPos == IB::mMax - 1;
}
bool first()
{
return IB::mPos == 0;
}
std::shared_ptr<RangeType> range()
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
}
template <size_t N> template <size_t N>
void getPtr() {} void getPtr();
std::shared_ptr<VIWB> getVPtr(size_t n) std::shared_ptr<VIWB> getVPtr(size_t n);
{ size_t getStepSize(size_t n);
return std::shared_ptr<VIWB>();
}
size_t getStepSize(size_t n) std::string id();
{ void print(size_t offset);
return 1;
}
std::string id() { return std::string("sin") + std::to_string(IB::mId); }
void print(size_t offset)
{
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;
}
}; };
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
class SingleRangeFactory : public RangeFactoryBase class SingleRangeFactory : public RangeFactoryBase
{ {
public: public:
@ -136,7 +70,7 @@ namespace MultiArrayTools
}; };
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
class SingleRange : public RangeInterface<SingleIndex<U,TYPE> > class SingleRange : public RangeInterface<SingleIndex<U,TYPE> >
{ {
public: public:
@ -180,21 +114,133 @@ namespace MultiArrayTools
* SingleIndex * * SingleIndex *
******************/ ******************/
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) : SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
IndexInterface<SingleIndex<U,TYPE>,U>(range, 0) {} IndexInterface<SingleIndex<U,TYPE>,U>(range, 0) {}
template <typename U, SpaceType TYPE>
IndexType SingleIndex<U,TYPE>::type()
{
return IndexType::SINGLE;
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
{
IB::mPos = pos;
return *this;
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
{
++IB::mPos;
return *this;
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
{
--IB::mPos;
return *this;
}
template <typename U, SpaceType TYPE>
int SingleIndex<U,TYPE>::pp(std::intptr_t idxPtrNum)
{
++(*this);
return 1;
}
template <typename U, SpaceType TYPE>
int SingleIndex<U,TYPE>::mm(std::intptr_t idxPtrNum)
{
--(*this);
return 1;
}
template <typename U, SpaceType TYPE>
U SingleIndex<U,TYPE>::meta()
{
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->get( IB::pos() );
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos)
{
(*this) = std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos );
return *this;
}
template <typename U, SpaceType TYPE>
size_t SingleIndex<U,TYPE>::dim() // = 1
{
return 1;
}
template <typename U, SpaceType TYPE>
bool SingleIndex<U,TYPE>::last()
{
return IB::mPos == IB::mMax - 1;
}
template <typename U, SpaceType TYPE>
bool SingleIndex<U,TYPE>::first()
{
return IB::mPos == 0;
}
template <typename U, SpaceType TYPE>
std::shared_ptr<typename SingleIndex<U,TYPE>::RangeType> SingleIndex<U,TYPE>::range()
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
}
template <typename U, SpaceType TYPE>
template <size_t N>
void SingleIndex<U,TYPE>::getPtr() {}
template <typename U, SpaceType TYPE>
std::shared_ptr<VIWB> SingleIndex<U,TYPE>::getVPtr(size_t n)
{
return std::shared_ptr<VIWB>();
}
template <typename U, SpaceType TYPE>
size_t SingleIndex<U,TYPE>::getStepSize(size_t n)
{
return 1;
}
template <typename U, SpaceType TYPE>
std::string SingleIndex<U,TYPE>::id()
{
return std::string("sin") + std::to_string(IB::mId);
}
template <typename U, SpaceType TYPE>
void SingleIndex<U,TYPE>::print(size_t offset)
{
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;
}
/******************** /********************
* SingleRange * * SingleRange *
********************/ ********************/
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
SingleRangeFactory<U,TYPE>::SingleRangeFactory(const std::vector<U>& space) SingleRangeFactory<U,TYPE>::SingleRangeFactory(const std::vector<U>& space)
{ {
mProd = std::shared_ptr<oType>( new SingleRange<U,TYPE>( space ) ); mProd = std::shared_ptr<oType>( new SingleRange<U,TYPE>( space ) );
} }
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
std::shared_ptr<RangeBase> SingleRangeFactory<U,TYPE>::create() std::shared_ptr<RangeBase> SingleRangeFactory<U,TYPE>::create()
{ {
setSelf(); setSelf();
@ -205,17 +251,17 @@ namespace MultiArrayTools
* SingleRange * * SingleRange *
********************/ ********************/
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
SingleRange<U,TYPE>::SingleRange(const std::vector<U>& space) : RangeInterface<SingleIndex<U,TYPE> >(), SingleRange<U,TYPE>::SingleRange(const std::vector<U>& space) : RangeInterface<SingleIndex<U,TYPE> >(),
mSpace(space) {} mSpace(space) {}
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
const U& SingleRange<U,TYPE>::get(size_t pos) const const U& SingleRange<U,TYPE>::get(size_t pos) const
{ {
return mSpace[pos]; return mSpace[pos];
} }
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
size_t SingleRange<U,TYPE>::getMeta(const U& metaPos) const size_t SingleRange<U,TYPE>::getMeta(const U& metaPos) const
{ {
size_t cnt = 0; size_t cnt = 0;
@ -228,19 +274,19 @@ namespace MultiArrayTools
return cnt; return cnt;
} }
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
size_t SingleRange<U,TYPE>::size() const size_t SingleRange<U,TYPE>::size() const
{ {
return mSpace.size(); return mSpace.size();
} }
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
size_t SingleRange<U,TYPE>::dim() const size_t SingleRange<U,TYPE>::dim() const
{ {
return 1; return 1;
} }
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const
{ {
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> > SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
@ -249,7 +295,7 @@ namespace MultiArrayTools
return i; return i;
} }
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::end() const typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::end() const
{ {
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> > SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
@ -259,7 +305,7 @@ namespace MultiArrayTools
} }
// put this in the interface class !!! // put this in the interface class !!!
template <typename U, RangeType TYPE> template <typename U, SpaceType TYPE>
std::shared_ptr<VIWB> SingleRange<U,TYPE>::index() const std::shared_ptr<VIWB> SingleRange<U,TYPE>::index() const
{ {
typedef IndexWrapper<IndexType> IW; typedef IndexWrapper<IndexType> IW;