im com
This commit is contained in:
parent
a3acfedd9b
commit
346101b994
8 changed files with 328 additions and 233 deletions
|
@ -51,7 +51,7 @@ namespace MultiArrayTools
|
|||
***********************/
|
||||
|
||||
// range_base.h
|
||||
enum class RangeType;
|
||||
enum class SpaceType;
|
||||
|
||||
// range_base.h
|
||||
class RangeFactoryBase;
|
||||
|
@ -76,15 +76,15 @@ namespace MultiArrayTools
|
|||
class IndexInterface;
|
||||
|
||||
// single_range.h
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
class SingleRange;
|
||||
|
||||
// single_range.h
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
class SingleRangeFactory;
|
||||
|
||||
// single_range.h
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
class SingleIndex;
|
||||
|
||||
// multi_range.h
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace {
|
|||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef MultiRangeFactory<SRange,SRange,SRange> M3RF;
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace {
|
|||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
MATest_1Dim()
|
||||
|
@ -58,7 +58,7 @@ namespace {
|
|||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef MultiRangeFactory<SRange,SRange> MRF;
|
||||
|
|
|
@ -68,119 +68,34 @@ namespace MultiArrayTools
|
|||
// Do NOT share index instances between two or more MultiIndex instances
|
||||
MultiIndex& operator()(std::shared_ptr<Indices>&... indices);
|
||||
|
||||
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); }
|
||||
|
||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||
|
||||
IndexType type() { return IndexType::MULTI; }
|
||||
IndexType type();
|
||||
|
||||
MultiIndex& operator=(size_t pos)
|
||||
{
|
||||
IB::mPos = pos;
|
||||
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
||||
return *this;
|
||||
}
|
||||
MultiIndex& operator=(size_t pos);
|
||||
|
||||
MultiIndex& operator++()
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
MultiIndex& operator++();
|
||||
MultiIndex& operator--();
|
||||
|
||||
MultiIndex& operator--()
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
int pp(std::intptr_t idxPtrNum);
|
||||
int mm(std::intptr_t idxPtrNum);
|
||||
|
||||
int pp(std::intptr_t idxPtrNum)
|
||||
{
|
||||
int tmp = PackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
||||
IB::mPos += tmp;
|
||||
return tmp;
|
||||
}
|
||||
MetaType meta();
|
||||
MultiIndex& at(const MetaType& metaPos);
|
||||
|
||||
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()
|
||||
{
|
||||
return sizeof...(Indices);
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
size_t dim();
|
||||
bool first();
|
||||
bool last();
|
||||
std::shared_ptr<RangeType> range();
|
||||
|
||||
template <size_t N>
|
||||
auto getPtr() -> decltype( std::get<N>( mIPack ) )&
|
||||
{
|
||||
return std::get<N>(mIPack);
|
||||
}
|
||||
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
|
||||
|
||||
//const IndexBase& get(size_t n);
|
||||
std::shared_ptr<VIWB> getVPtr(size_t n)
|
||||
{
|
||||
if(n >= sizeof...(Indices)){
|
||||
assert(0);
|
||||
// throw !!
|
||||
}
|
||||
MultiIndex<Indices...> const* t = this;
|
||||
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
|
||||
}
|
||||
std::shared_ptr<VIWB> getVPtr(size_t n);
|
||||
size_t getStepSize(size_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); }
|
||||
|
||||
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);
|
||||
}
|
||||
std::string id();
|
||||
void print(size_t offset);
|
||||
};
|
||||
|
||||
/*************************
|
||||
|
@ -346,6 +261,140 @@ namespace MultiArrayTools
|
|||
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 *
|
||||
*************************/
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace {
|
|||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
OpTest_1Dim()
|
||||
|
@ -86,7 +86,7 @@ namespace {
|
|||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef MultiRangeFactory<SRange,SRange> MRF;
|
||||
|
@ -130,7 +130,7 @@ namespace {
|
|||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<size_t,RangeType::ANY> SRF;
|
||||
typedef SingleRangeFactory<size_t,SpaceType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef MultiRangeFactory<SRange,SRange> MRF;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
enum class RangeType
|
||||
enum class SpaceType
|
||||
{
|
||||
NONE = 0,
|
||||
ANY = 1,
|
||||
|
|
|
@ -12,14 +12,14 @@ include_range_type(SPIN,2)
|
|||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
typedef SingleIndex<size_t,RangeType::SPIN> SpinIndex;
|
||||
typedef SingleIndex<size_t,SpaceType::SPIN> SpinIndex;
|
||||
|
||||
template <>
|
||||
class SingleRangeFactory<size_t,RangeType::SPIN> : public RangeFactoryBase
|
||||
class SingleRangeFactory<size_t,SpaceType::SPIN> : public RangeFactoryBase
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SingleRange<size_t,RangeType::SPIN> oType;
|
||||
typedef SingleRange<size_t,SpaceType::SPIN> oType;
|
||||
|
||||
SingleRangeFactory();
|
||||
std::shared_ptr<RangeBase> create();
|
||||
|
@ -27,11 +27,11 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
template <>
|
||||
class SingleRange<size_t,RangeType::SPIN> : public RangeInterface<SpinIndex>
|
||||
class SingleRange<size_t,SpaceType::SPIN> : public RangeInterface<SpinIndex>
|
||||
{
|
||||
public:
|
||||
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 dim() const override;
|
||||
|
@ -43,13 +43,13 @@ namespace MultiArrayTools
|
|||
virtual IndexType end() 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 size_t mSpinNum = 4;
|
||||
|
||||
static SingleRangeFactory<size_t, RangeType::SPIN> factory()
|
||||
{ return SingleRangeFactory<size_t, RangeType::SPIN>(); }
|
||||
static SingleRangeFactory<size_t, SpaceType::SPIN> factory()
|
||||
{ return SingleRangeFactory<size_t, SpaceType::SPIN>(); }
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -59,8 +59,8 @@ namespace MultiArrayTools
|
|||
//SingleRange(size_t spinNum);
|
||||
};
|
||||
|
||||
typedef SingleRange<size_t,RangeType::SPIN> SpinRange;
|
||||
typedef SingleRangeFactory<size_t,RangeType::SPIN> SpinRF;
|
||||
typedef SingleRange<size_t,SpaceType::SPIN> SpinRange;
|
||||
typedef SingleRangeFactory<size_t,SpaceType::SPIN> SpinRF;
|
||||
}
|
||||
|
||||
/* ========================= *
|
||||
|
@ -73,16 +73,16 @@ namespace MultiArrayTools
|
|||
* SingleRange *
|
||||
********************/
|
||||
|
||||
SingleRangeFactory<size_t,RangeType::SPIN>::SingleRangeFactory()
|
||||
SingleRangeFactory<size_t,SpaceType::SPIN>::SingleRangeFactory()
|
||||
{
|
||||
// Quasi Singleton
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,RangeType::SPIN>::create()
|
||||
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,SpaceType::SPIN>::create()
|
||||
{
|
||||
return mProd;
|
||||
}
|
||||
|
@ -91,49 +91,49 @@ namespace MultiArrayTools
|
|||
* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
size_t SingleRange<size_t,RangeType::SPIN>::size() const
|
||||
size_t SingleRange<size_t,SpaceType::SPIN>::size() const
|
||||
{
|
||||
return mSpinNum;
|
||||
}
|
||||
|
||||
size_t SingleRange<size_t,RangeType::SPIN>::dim() const
|
||||
size_t SingleRange<size_t,SpaceType::SPIN>::dim() const
|
||||
{
|
||||
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 ) ) );
|
||||
i = 0;
|
||||
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 ) ) );
|
||||
i = size();
|
||||
return i;
|
||||
}
|
||||
|
||||
// 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;
|
||||
return std::make_shared<IW>
|
||||
( 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 ) ) ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
class SingleIndex : public IndexInterface<SingleIndex<U,TYPE>,U>
|
||||
{
|
||||
public:
|
||||
|
@ -27,103 +27,37 @@ namespace MultiArrayTools
|
|||
|
||||
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 <<<<< ====
|
||||
|
||||
IndexType type()
|
||||
{
|
||||
return IndexType::SINGLE;
|
||||
}
|
||||
IndexType type();
|
||||
|
||||
SingleIndex& operator=(size_t pos)
|
||||
{
|
||||
IB::mPos = pos;
|
||||
return *this;
|
||||
}
|
||||
SingleIndex& operator=(size_t pos);
|
||||
SingleIndex& operator++();
|
||||
SingleIndex& operator--();
|
||||
|
||||
SingleIndex& operator++()
|
||||
{
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
int pp(std::intptr_t idxPtrNum);
|
||||
int mm(std::intptr_t idxPtrNum);
|
||||
|
||||
SingleIndex& operator--()
|
||||
{
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
U meta();
|
||||
SingleIndex& at(const U& metaPos);
|
||||
|
||||
int pp(std::intptr_t idxPtrNum)
|
||||
{
|
||||
++(*this);
|
||||
return 1;
|
||||
}
|
||||
size_t dim(); // = 1
|
||||
bool last();
|
||||
bool first();
|
||||
|
||||
int mm(std::intptr_t idxPtrNum)
|
||||
{
|
||||
--(*this);
|
||||
return 1;
|
||||
}
|
||||
|
||||
U meta()
|
||||
{
|
||||
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
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool last()
|
||||
{
|
||||
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 );
|
||||
}
|
||||
std::shared_ptr<RangeType> range();
|
||||
|
||||
template <size_t N>
|
||||
void getPtr() {}
|
||||
void getPtr();
|
||||
|
||||
std::shared_ptr<VIWB> getVPtr(size_t n)
|
||||
{
|
||||
return std::shared_ptr<VIWB>();
|
||||
}
|
||||
std::shared_ptr<VIWB> getVPtr(size_t n);
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
size_t getStepSize(size_t n)
|
||||
{
|
||||
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;
|
||||
}
|
||||
std::string id();
|
||||
void print(size_t offset);
|
||||
};
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
class SingleRangeFactory : public RangeFactoryBase
|
||||
{
|
||||
public:
|
||||
|
@ -136,7 +70,7 @@ namespace MultiArrayTools
|
|||
|
||||
};
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
class SingleRange : public RangeInterface<SingleIndex<U,TYPE> >
|
||||
{
|
||||
public:
|
||||
|
@ -180,21 +114,133 @@ namespace MultiArrayTools
|
|||
* SingleIndex *
|
||||
******************/
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
|
||||
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 *
|
||||
********************/
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
SingleRangeFactory<U,TYPE>::SingleRangeFactory(const std::vector<U>& 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()
|
||||
{
|
||||
setSelf();
|
||||
|
@ -205,17 +251,17 @@ namespace MultiArrayTools
|
|||
* SingleRange *
|
||||
********************/
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
SingleRange<U,TYPE>::SingleRange(const std::vector<U>& space) : RangeInterface<SingleIndex<U,TYPE> >(),
|
||||
mSpace(space) {}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
const U& SingleRange<U,TYPE>::get(size_t pos) const
|
||||
{
|
||||
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 cnt = 0;
|
||||
|
@ -228,19 +274,19 @@ namespace MultiArrayTools
|
|||
return cnt;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
size_t SingleRange<U,TYPE>::size() const
|
||||
{
|
||||
return mSpace.size();
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
size_t SingleRange<U,TYPE>::dim() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const
|
||||
{
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
||||
|
@ -249,7 +295,7 @@ namespace MultiArrayTools
|
|||
return i;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
template <typename U, SpaceType TYPE>
|
||||
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::end() const
|
||||
{
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
||||
|
@ -259,7 +305,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
typedef IndexWrapper<IndexType> IW;
|
||||
|
|
Loading…
Reference in a new issue