first scast version (UNTESTED)
This commit is contained in:
parent
0d951f892a
commit
b9e5d6a898
5 changed files with 50 additions and 32 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
//#include "base_def.h"
|
||||
#include "rbase_def.h"
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/rpheader.h"
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace MultiArrayTools
|
|||
|
||||
typedef AnonymousRange oType;
|
||||
|
||||
AnonymousRangeFactory() = delete;
|
||||
AnonymousRangeFactory() = default;
|
||||
|
||||
template <class... RangeTypes>
|
||||
AnonymousRangeFactory(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
|
||||
|
@ -121,6 +121,31 @@ namespace MultiArrayTools
|
|||
std::dynamic_pointer_cast<oType>(mProd)->mOrig.push_back(r);
|
||||
}
|
||||
|
||||
/*****************
|
||||
* Functions *
|
||||
*****************/
|
||||
|
||||
std::shared_ptr<AnonymousRange> defaultRange(size_t size = 0);
|
||||
}
|
||||
|
||||
namespace MultiArrayHelper
|
||||
{
|
||||
using namespace MultiArrayTools;
|
||||
template <>
|
||||
inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange> rp,
|
||||
std::vector<std::shared_ptr<RangeBase> > orig,
|
||||
size_t origpos, size_t size)
|
||||
{
|
||||
AnonymousRangeFactory arf;
|
||||
for(size_t op = origpos - size + 1; op != origpos + 1; ++op){
|
||||
arf.append(orig[op]);
|
||||
}
|
||||
rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
||||
}
|
||||
}
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
/***********************
|
||||
* AnonymousRange *
|
||||
***********************/
|
||||
|
@ -155,15 +180,12 @@ namespace MultiArrayTools
|
|||
{
|
||||
std::tuple<Ranges...> rtp;
|
||||
RPackNum<sizeof...(Ranges)-1>::resolveRangeType(mOrig, rtp, mOrig.size()-1, sizes...);
|
||||
MultiRangeFactory<Ranges> mrf(rtp);
|
||||
MultiRangeFactory<Ranges...> mrf(rtp);
|
||||
return std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf->create() );
|
||||
}
|
||||
|
||||
/*****************
|
||||
* Functions *
|
||||
*****************/
|
||||
|
||||
std::shared_ptr<AnonymousRange> defaultRange(size_t size = 0);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -71,6 +71,7 @@ namespace MultiArrayTools
|
|||
|
||||
// anonymous_range.h
|
||||
class AnonymousRange;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
#define __rpack_num_h__
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include "ranges/rbase_def.h"
|
||||
#include "ranges/index_base.h"
|
||||
|
||||
|
||||
namespace MultiArrayHelper
|
||||
{
|
||||
|
@ -39,6 +44,7 @@ namespace MultiArrayHelper
|
|||
template <class Index>
|
||||
inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
||||
|
||||
|
||||
template <class Range>
|
||||
void resolveSetRange(std::shared_ptr<Range> rp, std::vector<std::shared_ptr<RangeBase> > orig,
|
||||
size_t origpos, size_t size)
|
||||
|
@ -47,18 +53,6 @@ namespace MultiArrayHelper
|
|||
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
|
||||
}
|
||||
|
||||
template <>
|
||||
void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange> rp,
|
||||
std::vector<std::shared_ptr<RangeBase> > orig,
|
||||
size_t origpos, size_t size)
|
||||
{
|
||||
AnonymousRangeFactory arf;
|
||||
for(size_t op = origpos - size + 1; op != origpos + 1; ++op){
|
||||
arf.append(orig[op]);
|
||||
}
|
||||
rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
struct RPackNum
|
||||
{
|
||||
|
@ -276,11 +270,10 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
template <class RangeTuple, typename... SIZET>
|
||||
static void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> > orig,
|
||||
static inline void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> > orig,
|
||||
const RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
|
||||
{
|
||||
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||
typedef decltype(std::get<tps-N-1>(rtp)) RangeType;
|
||||
resolveSetRange(std::get<tps-N-1>(rtp), orig, off, size);
|
||||
RPackNum<N-1>::resolveRangeType(orig, rtp, off-size, sizes...);
|
||||
}
|
||||
|
@ -464,11 +457,10 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
template <class RangeTuple, typename... SIZET>
|
||||
static void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> > orig,
|
||||
static inline void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> > orig,
|
||||
const RangeTuple& rtp, size_t off, size_t size)
|
||||
{
|
||||
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||
typedef decltype(std::get<tps-1>(rtp)) RangeType;
|
||||
resolveSetRange(std::get<tps-1>(rtp), orig, off, size);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <memory>
|
||||
|
||||
//#include "base_def.h"
|
||||
//#include "ranges/rpack_num.h"
|
||||
#include "ranges/index_base.h"
|
||||
#include "ranges/range_base.h"
|
||||
|
||||
|
|
|
@ -7,15 +7,15 @@ namespace MultiArrayTools
|
|||
* AnonymousRangeFactory *
|
||||
******************************/
|
||||
|
||||
std::shared_ptr<RangeBase> checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec)
|
||||
std::shared_ptr<RangeBase> AnonymousRangeFactory::checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec)
|
||||
{
|
||||
std::shared_ptr<RangeBase> out;
|
||||
bool check = false;
|
||||
for(auto& x: mAleadyCreated){
|
||||
if(x.second.size() == pvec.size()){
|
||||
check = true;
|
||||
for(size_t i = 0; i != x.size(); ++i){
|
||||
if(x.second[i] != static_cast<std::intptr_t>( pvec[i].get() ) ){
|
||||
for(size_t i = 0; i != x.second.size(); ++i){
|
||||
if(x.second[i] != reinterpret_cast<std::intptr_t>( pvec[i].get() ) ){
|
||||
check = false;
|
||||
break;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace MultiArrayTools
|
|||
if(not check){
|
||||
std::vector<std::intptr_t> app(pvec.size());
|
||||
for(size_t i = 0; i != app.size(); ++i){
|
||||
app[i] = static_cast<std::intptr_t>( pvec[i].get() );
|
||||
app[i] = reinterpret_cast<std::intptr_t>( pvec[i].get() );
|
||||
}
|
||||
mAleadyCreated[mProd] = app;
|
||||
out = mProd;
|
||||
|
@ -40,7 +40,7 @@ namespace MultiArrayTools
|
|||
|
||||
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
|
||||
{
|
||||
mProd = checkIfCreated();
|
||||
mProd = checkIfCreated(std::dynamic_pointer_cast<AnonymousRange>(mProd)->mOrig);
|
||||
setSelf();
|
||||
return mProd;
|
||||
}
|
||||
|
@ -105,4 +105,6 @@ namespace MultiArrayTools
|
|||
return std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
|
|
Loading…
Reference in a new issue