range stream parsing works
This commit is contained in:
parent
a3ac073975
commit
11a53de452
18 changed files with 213 additions and 31 deletions
|
@ -75,6 +75,8 @@ namespace MultiArrayTools
|
|||
virtual IndexType begin() const final;
|
||||
virtual IndexType end() const final;
|
||||
|
||||
virtual SpaceType spaceType() const final;
|
||||
|
||||
virtual std::string stringMeta(size_t pos) const final;
|
||||
virtual std::vector<char> data() const final;
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace MultiArrayTools
|
|||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
||||
|
||||
static constexpr SpaceType STYPE = SpaceType::ANY;
|
||||
|
||||
private:
|
||||
|
||||
ContainerIndex() = default;
|
||||
|
|
|
@ -41,6 +41,8 @@ namespace MultiArrayTools
|
|||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
||||
|
||||
static constexpr SpaceType STYPE = SpaceType::ANY;
|
||||
|
||||
private:
|
||||
|
||||
IndexPack mIPack;
|
||||
|
@ -182,6 +184,8 @@ namespace MultiArrayTools
|
|||
virtual size_t dim() const final;
|
||||
virtual size_t size() const final;
|
||||
|
||||
virtual SpaceType spaceType() const final;
|
||||
|
||||
virtual std::string stringMeta(size_t pos) const final;
|
||||
virtual std::vector<char> data() const final;
|
||||
|
||||
|
@ -215,6 +219,9 @@ namespace MultiArrayTools
|
|||
using namespace MultiArrayHelper;
|
||||
}
|
||||
|
||||
// -> define in range_base.cc
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp);
|
||||
|
||||
/******************
|
||||
* MultiIndex *
|
||||
******************/
|
||||
|
@ -533,6 +540,12 @@ namespace MultiArrayTools
|
|||
return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
SpaceType MultiRange<Ranges...>::spaceType() const
|
||||
{
|
||||
return SpaceType::ANY;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
const typename MultiRange<Ranges...>::Space& MultiRange<Ranges...>::space() const
|
||||
{
|
||||
|
|
9
src/include/ranges/multi_range_register.h
Normal file
9
src/include/ranges/multi_range_register.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
#ifdef register_multi3
|
||||
|
||||
typedef SingleRange<char,SpaceType::ANY> SCRange;
|
||||
|
||||
register_multi3(PSpaceRange,PSpaceRange,PSpaceRange)
|
||||
register_multi3(SCRange,SCRange,SCRange)
|
||||
|
||||
#endif
|
|
@ -22,7 +22,7 @@ namespace MultiArrayTools
|
|||
enum class SpaceType
|
||||
{
|
||||
NONE = 0, // meta data is that of a classic range, i.e. 0,1,2,...,N-1
|
||||
ANY = 1, // meta data is arbitrary, i.e. explicitly stored
|
||||
ANY = 1, // meta data is arbitrary, i.e. explicitly stored; range could be multiple
|
||||
#define include_range_type(x,n) x = n,
|
||||
#include "range_types/header.h"
|
||||
#undef include_range_type
|
||||
|
@ -80,6 +80,8 @@ namespace MultiArrayTools
|
|||
virtual std::string stringMeta(size_t pos) const = 0;
|
||||
virtual std::vector<char> data() const = 0; // usefull when writing to files, etc...
|
||||
|
||||
virtual SpaceType spaceType() const = 0;
|
||||
|
||||
//virtual bool regular() const = 0; // integer distance (e.g. 2,3,4,...)
|
||||
//virtual bool linear() const = 0; // 1dim valuable (e.g. 2.45, 3.12, 3.56,...)
|
||||
//virtual bool multi() const = 0; // mdim
|
||||
|
@ -101,6 +103,8 @@ namespace MultiArrayTools
|
|||
//typedef typename Index::MetaType MetaType;
|
||||
typedef Index IndexType;
|
||||
|
||||
static constexpr SpaceType STYPE = IndexType::STYPE;
|
||||
|
||||
virtual Index begin() const = 0;
|
||||
virtual Index end() const = 0;
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ namespace MultiArrayTools
|
|||
virtual size_t size() const override;
|
||||
virtual size_t dim() const override;
|
||||
|
||||
virtual SpaceType spaceType() const override;
|
||||
|
||||
virtual std::string stringMeta(size_t pos) const override;
|
||||
virtual std::vector<char> data() const override;
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ namespace MultiArrayTools
|
|||
virtual std::string stringMeta(size_t pos) const override;
|
||||
virtual std::vector<char> data() const override;
|
||||
|
||||
virtual SpaceType spaceType() const override;
|
||||
|
||||
size_t get(size_t pos) const;
|
||||
size_t getMeta(size_t metapos) const;
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ namespace MultiArrayTools
|
|||
virtual std::string stringMeta(size_t pos) const override;
|
||||
virtual std::vector<char> data() const override;
|
||||
|
||||
virtual SpaceType spaceType() const override;
|
||||
|
||||
int get(size_t pos) const;
|
||||
size_t getMeta(int metaPos) const;
|
||||
|
||||
|
@ -75,10 +77,12 @@ namespace MultiArrayTools
|
|||
struct PromoteMSpaceRange
|
||||
{
|
||||
template <class... SpaceRanges>
|
||||
static auto mk(MultiRange<SpaceRanges...>) -> MultiRange<SpaceRange,SpaceRanges...>;
|
||||
static auto mk(const MultiRange<SpaceRanges...>&)
|
||||
-> MultiRange<SpaceRange,SpaceRanges...>;
|
||||
|
||||
template <class... SpaceRanges>
|
||||
static auto mkf(MultiRangeFactory<SpaceRanges...>) -> MultiRangeFactory<SpaceRange,SpaceRanges...>;
|
||||
static auto mkf(const MultiRangeFactory<SpaceRanges...>&)
|
||||
-> MultiRangeFactory<SpaceRange,SpaceRanges...>;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ namespace MultiArrayTools
|
|||
virtual std::string stringMeta(size_t pos) const override;
|
||||
virtual std::vector<char> data() const override;
|
||||
|
||||
virtual SpaceType spaceType() const override;
|
||||
|
||||
size_t get(size_t pos) const;
|
||||
size_t getMeta(size_t metaPos) const;
|
||||
|
||||
|
|
|
@ -314,6 +314,21 @@ namespace MultiArrayHelper
|
|||
out.insert(out.end(), part.begin(), part.end());
|
||||
RPackNum<N-1>::fillRangeDataVec(out, tp);
|
||||
}
|
||||
|
||||
template <size_t SIZE, class Range, class... Ranges>
|
||||
static inline bool compareSpaceTypes(const std::vector<std::shared_ptr<RangeBase> >& rbvec)
|
||||
{
|
||||
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and RPackNum<N-1>::template compareSpaceTypes<SIZE,Ranges...>(rbvec);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
static inline void setSpace(const std::vector<std::shared_ptr<RangeBase> >& rbvec,
|
||||
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||
{
|
||||
typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType;
|
||||
std::get<N>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[N] );
|
||||
RPackNum<N-1>::setSpace(rbvec, stp);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -527,6 +542,20 @@ namespace MultiArrayHelper
|
|||
out.insert(out.end(), part.begin(), part.end());
|
||||
}
|
||||
|
||||
template <size_t SIZE, class Range>
|
||||
static inline bool compareSpaceTypes(const std::vector<std::shared_ptr<RangeBase> >& rbvec)
|
||||
{
|
||||
return rbvec[SIZE-1]->spaceType() == Range::STYPE;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
static inline void setSpace(const std::vector<std::shared_ptr<RangeBase> >& rbvec,
|
||||
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||
{
|
||||
typedef typename std::remove_reference<decltype(*std::get<0>( stp ))>::type RType;
|
||||
std::get<0>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[0] );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <IndexType IT>
|
||||
|
|
|
@ -39,6 +39,8 @@ namespace MultiArrayTools
|
|||
static constexpr size_t totalDim() { return 1; }
|
||||
static constexpr size_t sDim() { return 1; }
|
||||
|
||||
static constexpr SpaceType STYPE = TYPE;
|
||||
|
||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||
|
||||
IndexType type() const;
|
||||
|
@ -107,6 +109,8 @@ namespace MultiArrayTools
|
|||
virtual size_t size() const override;
|
||||
virtual size_t dim() const override;
|
||||
|
||||
virtual SpaceType spaceType() const override;
|
||||
|
||||
virtual std::string stringMeta(size_t pos) const override;
|
||||
virtual std::vector<char> data() const override;
|
||||
|
||||
|
@ -377,6 +381,12 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <typename U, SpaceType TYPE>
|
||||
SpaceType SingleRange<U,TYPE>::spaceType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
template <typename U, SpaceType TYPE>
|
||||
std::string SingleRange<U,TYPE>::stringMeta(size_t pos) const
|
||||
{
|
||||
|
|
|
@ -77,6 +77,11 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
SpaceType AnonymousRange::spaceType() const
|
||||
{
|
||||
return SpaceType::ANON;
|
||||
}
|
||||
|
||||
std::string AnonymousRange::stringMeta(size_t pos) const
|
||||
{
|
||||
std::string out = "[ ";
|
||||
|
|
|
@ -12,6 +12,32 @@ namespace MultiArrayTools
|
|||
|
||||
//using namespace MultiArrayHelpers;
|
||||
|
||||
template <class... Ranges>
|
||||
using STP = std::tuple<std::shared_ptr<Ranges>...>;
|
||||
|
||||
typedef std::vector<std::shared_ptr<RangeBase> > RVEC;
|
||||
|
||||
template <class... Ranges>
|
||||
inline bool compareSpaceTypes(const RVEC& rvec)
|
||||
{
|
||||
return RPackNum<sizeof...(Ranges)-1>::
|
||||
template compareSpaceTypes<sizeof...(Ranges),Ranges...>(rvec);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
inline bool setFactory(const RVEC& rvec, std::shared_ptr<RangeFactoryBase>& fptr)
|
||||
{
|
||||
if(compareSpaceTypes<Ranges...>(rvec)) {
|
||||
STP<Ranges...> stp;
|
||||
RPackNum<sizeof...(Ranges)-1>::setSpace(rvec, stp);
|
||||
fptr = std::make_shared<MultiRangeFactory<Ranges...> >(stp);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size_t indexId()
|
||||
{
|
||||
static size_t id = 0;
|
||||
|
@ -19,16 +45,59 @@ namespace MultiArrayTools
|
|||
return id;
|
||||
}
|
||||
|
||||
// !!!!!
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp)
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp, size_t metaSize)
|
||||
{
|
||||
return nullptr;
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
RVEC rvec(metaSize);
|
||||
for(size_t i = 0; i != metaSize; ++i){
|
||||
auto ff = createRangeFactory(dp);
|
||||
rvec[i] = ff->create();
|
||||
}
|
||||
|
||||
if(metaSize == 0){
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 1) {
|
||||
#define register_multi1(TT0) if(setFactory<TT0>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi1
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 2) {
|
||||
#define register_multi2(TT0,TT1) if(setFactory<TT0,TT1>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi2
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 3) {
|
||||
#define register_multi3(TT0,TT1,TT2) if(setFactory<TT0,TT1,TT2>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi3
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 4) {
|
||||
#define register_multi4(TT0,TT1,TT2,TT3) if(setFactory<TT0,TT1,TT2,TT3>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi4
|
||||
assert(0);
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// !!!!!
|
||||
std::shared_ptr<RangeFactoryBase> mkANONYMOUS(char** dp)
|
||||
std::shared_ptr<RangeFactoryBase> mkANONYMOUS(char** dp, size_t metaSize)
|
||||
{
|
||||
return nullptr;
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
auto arf = std::make_shared<AnonymousRangeFactory>();
|
||||
for(size_t i = 0; i != metaSize; ++i){
|
||||
auto ff = createRangeFactory(dp);
|
||||
arf->append( ff->create() );
|
||||
}
|
||||
out = arf;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> createRangeFactory(char** dp)
|
||||
|
@ -41,26 +110,23 @@ namespace MultiArrayTools
|
|||
if(h.multiple != 0){
|
||||
if(h.spaceType == static_cast<int>( SpaceType::ANY )) {
|
||||
// multi range
|
||||
out = mkMULTI(dp);
|
||||
out = mkMULTI(dp, h.metaSize);
|
||||
}
|
||||
else if(h.spaceType == static_cast<int>( SpaceType::ANON ) ) {
|
||||
// anonymous range
|
||||
out = mkANONYMOUS(dp);
|
||||
out = mkANONYMOUS(dp, h.metaSize);
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
VCHECK(h.spaceType);
|
||||
if(h.spaceType == static_cast<int>( SpaceType::ANY ) ) {
|
||||
VCHECK(h.metaType)
|
||||
// generic single range
|
||||
if(h.metaType == -1){
|
||||
assert(0);
|
||||
}
|
||||
#define register_type(x) else if(x == h.metaType) {\
|
||||
VCHECK(x);\
|
||||
std::vector<TypeMap<x>::type> vd;\
|
||||
metaCat(vd, *dp, h.metaSize); \
|
||||
out = std::make_shared<SingleRangeFactory<TypeMap<x>::type, \
|
||||
|
|
|
@ -48,6 +48,11 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
SpaceType SingleRange<size_t,SpaceType::NONE>::spaceType() const
|
||||
{
|
||||
return SpaceType::NONE;
|
||||
}
|
||||
|
||||
std::string SingleRange<size_t,SpaceType::NONE>::stringMeta(size_t pos) const
|
||||
{
|
||||
return std::to_string(get(pos));
|
||||
|
|
|
@ -68,6 +68,11 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
SpaceType SingleRange<size_t,SpaceType::NUL>::spaceType() const
|
||||
{
|
||||
return SpaceType::NUL;
|
||||
}
|
||||
|
||||
std::string SingleRange<size_t,SpaceType::NUL>::stringMeta(size_t pos) const
|
||||
{
|
||||
return std::to_string(get(pos));
|
||||
|
|
|
@ -54,6 +54,11 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
SpaceType SingleRange<int,SpaceType::PSPACE>::spaceType() const
|
||||
{
|
||||
return SpaceType::PSPACE;
|
||||
}
|
||||
|
||||
std::string SingleRange<int,SpaceType::PSPACE>::stringMeta(size_t pos) const
|
||||
{
|
||||
return std::to_string(get(pos));
|
||||
|
|
|
@ -51,6 +51,11 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
SpaceType SingleRange<size_t,SpaceType::SPIN>::spaceType() const
|
||||
{
|
||||
return SpaceType::SPIN;
|
||||
}
|
||||
|
||||
std::string SingleRange<size_t,SpaceType::SPIN>::stringMeta(size_t pos) const
|
||||
{
|
||||
return std::to_string(get(pos));
|
||||
|
|
|
@ -127,7 +127,6 @@ namespace {
|
|||
{
|
||||
std::vector<char> vv = sr1ptr->data();
|
||||
char* dp = vv.data();
|
||||
VCHECK(vv.size());
|
||||
auto ff = createRangeFactory(&dp);
|
||||
auto ss = std::dynamic_pointer_cast<SRange>( ff->create() );
|
||||
|
||||
|
@ -145,10 +144,6 @@ namespace {
|
|||
SpinRF srf;
|
||||
NameRF nrf({"ab", "cdef", "gh", "ijklmno"});
|
||||
|
||||
VCHECK(sizeof(DataHeader));
|
||||
VCHECK(sizeof(char));
|
||||
VCHECK(sizeof(size_t));
|
||||
|
||||
auto cr = std::dynamic_pointer_cast<ClassicRange>( crf.create() );
|
||||
auto sr = std::dynamic_pointer_cast<SpinRange>( srf.create() );
|
||||
auto nr = std::dynamic_pointer_cast<NameRange>( nrf.create() );
|
||||
|
@ -160,10 +155,6 @@ namespace {
|
|||
char* sp = sv.data();
|
||||
char* np = nv.data();
|
||||
|
||||
VCHECK(cv.size());
|
||||
VCHECK(sv.size());
|
||||
VCHECK(nv.size());
|
||||
|
||||
auto crf2 = createRangeFactory(&cp);
|
||||
auto cr2 = std::dynamic_pointer_cast<ClassicRange>( crf2->create() );
|
||||
|
||||
|
@ -183,20 +174,41 @@ namespace {
|
|||
EXPECT_EQ(nr2->get(3), nr->get(3));
|
||||
}
|
||||
|
||||
/*
|
||||
TEST_F(AnonymousTest, ToString3)
|
||||
|
||||
TEST_F(AnonymousTest, ToStringMulti)
|
||||
{
|
||||
std::vector<char> vv = m3rptr->data();
|
||||
char* dp = vv.data();
|
||||
|
||||
auto ff2 = std::dynamic_pointer_cast<M3RF>( createRangeFactory(&dp) );
|
||||
auto mr2 = std::dynamic_pointer_cast<M3Range>( ff2->create() );
|
||||
|
||||
EXPECT_EQ(mr2->size(), m3rptr->size());
|
||||
EXPECT_EQ(mr2->template getPtr<0>()->size(),
|
||||
m3rptr->template getPtr<0>()->size());
|
||||
EXPECT_EQ(mr2->template getPtr<1>()->size(),
|
||||
m3rptr->template getPtr<1>()->size());
|
||||
EXPECT_EQ(mr2->template getPtr<2>()->size(),
|
||||
m3rptr->template getPtr<2>()->size());
|
||||
auto jj = m3rptr->begin();
|
||||
for(auto ii = mr2->begin(); ii.pos() != ii.max(); ++ii, jj = ii.pos()){
|
||||
EXPECT_EQ(ii.meta(), jj.meta());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AnonymousTest, ToStringAnonymous)
|
||||
{
|
||||
AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
|
||||
auto ar = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() );
|
||||
|
||||
std::vector<char> vv = ar->data();
|
||||
char* dp = vv.data();
|
||||
|
||||
auto ff2 = std::dynamic_pointer_cast<AnonymousRangeFactory>( createRangeFactory(vv) );
|
||||
auto ar2 = createExplicit( ff2 );
|
||||
auto ff2 = std::dynamic_pointer_cast<AnonymousRangeFactory>( createRangeFactory(&dp) );
|
||||
auto ar2 = std::dynamic_pointer_cast<AnonymousRange>( ff2->create() );
|
||||
|
||||
EXPECT_EQ(ar2->size(), ar->size());
|
||||
EXPECT_EQ(ar2->anonymousDim(), ar->anonymousDim());
|
||||
}*/
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
|
Loading…
Reference in a new issue