anonymous range should be complete now (still UNTESTED)

This commit is contained in:
Christian Zimmermann 2017-12-07 18:11:24 +01:00
parent 1347615cb3
commit 1b251e5867
5 changed files with 64 additions and 15 deletions

View file

@ -19,7 +19,13 @@ namespace MultiArrayTools
typedef AnonymousRange oType; typedef AnonymousRange oType;
AnonymousRangeFactory() = delete; AnonymousRangeFactory() = delete;
AnonymousRangeFactory(const std::shared_ptr<Ranges>... origs);
template <class... Ranges>
AnonymousRangeFactory(const std::tuple<std::shared_ptr<Ranges>...>& origs);
template <class... Ranges>
AnonymousRangeFactory(std::shared_ptr<Ranges>... origs);
std::shared_ptr<RangeBase> create(); std::shared_ptr<RangeBase> create();
}; };
@ -48,7 +54,10 @@ namespace MultiArrayTools
AnonymousRange(const AnonymousRange& in) = delete; AnonymousRange(const AnonymousRange& in) = delete;
template <class Ranges...> template <class Ranges...>
AnonymousRange(const std::shared_ptr<Ranges>... origs); AnonymousRange(const std::tuple<std::shared_ptr<Ranges>...>& origs)
template <class Ranges...>
AnonymousRange(std::shared_ptr<Ranges>... origs);
size_t mSize; size_t mSize;
@ -67,10 +76,17 @@ namespace MultiArrayTools
/*********************** /***********************
* AnonymousRange * * AnonymousRange *
***********************/ ***********************/
AnonymousRangeFactory::AnonymousRangeFactory(const std::shared_ptr<Ranges>... origs) template <class... Ranges>
AnonymousRangeFactory::AnonymousRangeFactory(const std::tuple<std::shared_ptr<Ranges>...>& origs)
{ {
mProd = std::shared_ptr<oType>( new AnonymousRange( space ) ); mProd = std::shared_ptr<oType>( new AnonymousRange( origs ) );
}
template <class... Ranges>
AnonymousRangeFactory::AnonymousRangeFactory(std::shared_ptr<Ranges>... origs)
{
mProd = std::shared_ptr<oType>( new AnonymousRange( origs... ) );
} }
std::shared_ptr<RangeBase> AnonymousRangeFactory::create() std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
@ -84,13 +100,22 @@ namespace MultiArrayTools
***********************/ ***********************/
template <class... Ranges> template <class... Ranges>
AnonymousRange::AnonymousRange(const std::shared_ptr<Ranges>... origs) : AnonymousRange::AnonymousRange(const std::tuple<std::shared_ptr<Ranges>...>& origs) :
RangeInterface<AnonymousIndex>() RangeInterface<AnonymousIndex>()
{ {
mOrig.resize(sizeof...(Ranges)); mOrig.resize(sizeof...(Ranges));
PackNum<sizeof...(Ranges)-1>::RangesToVec(); PackNum<sizeof...(Ranges)-1>::RangesToVec( origs, mOrig );
// mOrig !!!! PackNum<sizeof...(Ranges)-1>::getSize( rst );
// mSize !!! = (prod origs.size...) }
template <class... Ranges>
AnonymousRange::AnonymousRange(std::shared_ptr<Ranges>... origs) :
RangeInterface<AnonymousIndex>()
{
auto rst = std::make_tuple(origs...);
mOrig.resize(sizeof...(Ranges));
PackNum<sizeof...(Ranges)-1>::RangesToVec( rst, mOrig );
PackNum<sizeof...(Ranges)-1>::getSize( rst );
} }
size_t AnonymousRange::get(size_t pos) const size_t AnonymousRange::get(size_t pos) const

View file

@ -106,6 +106,12 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
class ContainerIndex; class ContainerIndex;
// anonymous_range.h
class AnonymousRangeFactory;
// anonymous_range.h
class AnonymousRange;
// multi_array.h // multi_array.h
template <typename T, class... SRanges> template <typename T, class... SRanges>
class MultiArrayBase; class MultiArrayBase;

View file

@ -151,8 +151,10 @@ namespace {
mrptr = std::dynamic_pointer_cast<MRange>(rfbptr->create()); mrptr = std::dynamic_pointer_cast<MRange>(rfbptr->create());
} }
const size_t vs1 = 10000; //const size_t vs1 = 10000;
const size_t vs2 = 1000; //const size_t vs2 = 1000;
const size_t vs1 = 4000;
const size_t vs2 = 2500;
std::shared_ptr<RangeFactoryBase> rfbptr; std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> sr1ptr; std::shared_ptr<SRange> sr1ptr;

View file

@ -245,12 +245,12 @@ namespace MultiArrayHelper
PackNum<N-1>::printTuple(out, tp); PackNum<N-1>::printTuple(out, tp);
} }
template <class RangeType, class... Ranges> template <class... Ranges>
static void RangesToVec(const std::shared_ptr<RangeType> r, static void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
const std::shared_ptr<Ranges>... rs,
std::vector<RangeBase> v) std::vector<RangeBase> v)
{ {
v[N] = std::get<N>(rst);
PackNum<N>::RangesToVec(rst, v);
} }
}; };
@ -433,6 +433,13 @@ namespace MultiArrayHelper
out << std::get<sizeof...(T)-1>(tp); out << std::get<sizeof...(T)-1>(tp);
} }
template <class... Ranges>
static void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
std::vector<RangeBase> v)
{
v[0] = std::get<0>(rst);
}
}; };
template <typename... T> template <typename... T>

View file

@ -1,7 +1,14 @@
#ifdef include_range_type
#define __incl_this__
#endif
#ifdef __single_range_h__ #ifdef __single_range_h__
// singel_range is template which is specialized here // singel_range is template which is specialized here
// therefore it must be defined before... // therefore it must be defined before...
#define __incl_this__
#endif
#ifdef __incl_this__
#ifndef __ranges_header__ #ifndef __ranges_header__
#define __ranges_header__ #define __ranges_header__
@ -10,3 +17,5 @@
#endif #endif
#endif #endif
#undef __incl_this__