From 56cc0bf05c8d53715b70f0e7dce012cdc4d5de11 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sat, 28 Jul 2018 15:27:11 +0200 Subject: [PATCH] first draft of multi/anonymous range meta stream parsing + spaceType() in Ranges --- src/include/ranges/anonymous_range.h | 2 + src/include/ranges/multi_range.h | 11 +++++ src/include/ranges/range_base.h | 4 +- .../ranges/range_types/classic_range.h | 2 + src/include/ranges/range_types/null_range.h | 2 + src/include/ranges/range_types/space_range.h | 8 +++- src/include/ranges/range_types/spin_range.h | 2 + src/include/ranges/single_range.h | 8 ++++ src/lib/ranges/anonymous_range.cc | 5 +++ src/lib/ranges/range_base.cc | 42 +++++++++++++++---- src/lib/ranges/range_types/classic_range.cc | 5 +++ src/lib/ranges/range_types/null_range.cc | 5 +++ src/lib/ranges/range_types/space_range.cc | 5 +++ src/lib/ranges/range_types/spin_range.cc | 5 +++ 14 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index 1213bd8..6adab6d 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -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 data() const final; diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index 6a47265..25fa1e2 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -182,6 +182,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 data() const final; @@ -215,6 +217,9 @@ namespace MultiArrayTools using namespace MultiArrayHelper; } + // -> define in range_base.cc + std::shared_ptr mkMULTI(char** dp); + /****************** * MultiIndex * ******************/ @@ -533,6 +538,12 @@ namespace MultiArrayTools return RPackNum::getSize(mSpace); } + template + SpaceType MultiRange::spaceType() const + { + return SpaceType::ANY; + } + template const typename MultiRange::Space& MultiRange::space() const { diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index 6785b1c..21dbe01 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -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 @@ -79,6 +79,8 @@ namespace MultiArrayTools virtual std::string stringMeta(size_t pos) const = 0; virtual std::vector 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,...) diff --git a/src/include/ranges/range_types/classic_range.h b/src/include/ranges/range_types/classic_range.h index 8415aae..9b8cb55 100644 --- a/src/include/ranges/range_types/classic_range.h +++ b/src/include/ranges/range_types/classic_range.h @@ -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 data() const override; diff --git a/src/include/ranges/range_types/null_range.h b/src/include/ranges/range_types/null_range.h index db3f885..d875d54 100644 --- a/src/include/ranges/range_types/null_range.h +++ b/src/include/ranges/range_types/null_range.h @@ -47,6 +47,8 @@ namespace MultiArrayTools virtual std::string stringMeta(size_t pos) const override; virtual std::vector data() const override; + + virtual SpaceType spaceType() const override; size_t get(size_t pos) const; size_t getMeta(size_t metapos) const; diff --git a/src/include/ranges/range_types/space_range.h b/src/include/ranges/range_types/space_range.h index 9558c25..18c5595 100644 --- a/src/include/ranges/range_types/space_range.h +++ b/src/include/ranges/range_types/space_range.h @@ -40,6 +40,8 @@ namespace MultiArrayTools virtual std::string stringMeta(size_t pos) const override; virtual std::vector 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 - static auto mk(MultiRange) -> MultiRange; + static auto mk(const MultiRange&) + -> MultiRange; template - static auto mkf(MultiRangeFactory) -> MultiRangeFactory; + static auto mkf(const MultiRangeFactory&) + -> MultiRangeFactory; }; diff --git a/src/include/ranges/range_types/spin_range.h b/src/include/ranges/range_types/spin_range.h index 91010b5..05e8025 100644 --- a/src/include/ranges/range_types/spin_range.h +++ b/src/include/ranges/range_types/spin_range.h @@ -40,6 +40,8 @@ namespace MultiArrayTools virtual std::string stringMeta(size_t pos) const override; virtual std::vector data() const override; + + virtual SpaceType spaceType() const override; size_t get(size_t pos) const; size_t getMeta(size_t metaPos) const; diff --git a/src/include/ranges/single_range.h b/src/include/ranges/single_range.h index 8ce4b23..e223360 100644 --- a/src/include/ranges/single_range.h +++ b/src/include/ranges/single_range.h @@ -107,6 +107,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 data() const override; @@ -377,6 +379,12 @@ namespace MultiArrayTools return 1; } + template + SpaceType SingleRange::spaceType() const + { + return TYPE; + } + template std::string SingleRange::stringMeta(size_t pos) const { diff --git a/src/lib/ranges/anonymous_range.cc b/src/lib/ranges/anonymous_range.cc index 694ab14..cc5c42e 100644 --- a/src/lib/ranges/anonymous_range.cc +++ b/src/lib/ranges/anonymous_range.cc @@ -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 = "[ "; diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index 55915ac..8b2a950 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -19,16 +19,42 @@ namespace MultiArrayTools return id; } - // !!!!! - std::shared_ptr mkMULTI(char** dp) + std::shared_ptr mkMULTI(char** dp, size_t metaSize) { - return nullptr; + std::shared_ptr out = nullptr; + std::vector > rvec(metaSize); + for(size_t i = 0; i != metaSize; ++i){ + auto ff = createRangeFactory(dp); + rvec[i] = ff->create(); + } + + if(metaSize == 3){ + if(rvec[0]->spaceType() == SpaceType::PSPACE and + rvec[1]->spaceType() == SpaceType::PSPACE and + rvec[2]->spaceType() == SpaceType::PSPACE) { + std::shared_ptr r0 = std::dynamic_pointer_cast( rvec[0] ); + std::shared_ptr r1 = std::dynamic_pointer_cast( rvec[1] ); + std::shared_ptr r2 = std::dynamic_pointer_cast( rvec[2] ); + out = std::make_shared >(r0,r1,r2); + } + } + else { + assert(0); + } + + return out; } - // !!!!! - std::shared_ptr mkANONYMOUS(char** dp) + std::shared_ptr mkANONYMOUS(char** dp, size_t metaSize) { - return nullptr; + std::shared_ptr out = nullptr; + auto arf = std::make_shared(); + for(size_t i = 0; i != metaSize; ++i){ + auto ff = createRangeFactory(dp); + arf->append( ff->create() ); + } + out = arf; + return out; } std::shared_ptr createRangeFactory(char** dp) @@ -41,11 +67,11 @@ namespace MultiArrayTools if(h.multiple != 0){ if(h.spaceType == static_cast( SpaceType::ANY )) { // multi range - out = mkMULTI(dp); + out = mkMULTI(dp, h.metaSize); } else if(h.spaceType == static_cast( SpaceType::ANON ) ) { // anonymous range - out = mkANONYMOUS(dp); + out = mkANONYMOUS(dp, h.metaSize); } else { assert(0); diff --git a/src/lib/ranges/range_types/classic_range.cc b/src/lib/ranges/range_types/classic_range.cc index 6432e0c..d942fa9 100644 --- a/src/lib/ranges/range_types/classic_range.cc +++ b/src/lib/ranges/range_types/classic_range.cc @@ -48,6 +48,11 @@ namespace MultiArrayTools return 1; } + SpaceType SingleRange::spaceType() const + { + return SpaceType::NONE; + } + std::string SingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos)); diff --git a/src/lib/ranges/range_types/null_range.cc b/src/lib/ranges/range_types/null_range.cc index 7653806..86beaaf 100644 --- a/src/lib/ranges/range_types/null_range.cc +++ b/src/lib/ranges/range_types/null_range.cc @@ -68,6 +68,11 @@ namespace MultiArrayTools return 1; } + SpaceType SingleRange::spaceType() const + { + return SpaceType::NUL; + } + std::string SingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos)); diff --git a/src/lib/ranges/range_types/space_range.cc b/src/lib/ranges/range_types/space_range.cc index 8248b38..d28b7cf 100644 --- a/src/lib/ranges/range_types/space_range.cc +++ b/src/lib/ranges/range_types/space_range.cc @@ -54,6 +54,11 @@ namespace MultiArrayTools return 1; } + SpaceType SingleRange::spaceType() const + { + return SpaceType::PSPACE; + } + std::string SingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos)); diff --git a/src/lib/ranges/range_types/spin_range.cc b/src/lib/ranges/range_types/spin_range.cc index 137cc6c..501283e 100644 --- a/src/lib/ranges/range_types/spin_range.cc +++ b/src/lib/ranges/range_types/spin_range.cc @@ -51,6 +51,11 @@ namespace MultiArrayTools return 1; } + SpaceType SingleRange::spaceType() const + { + return SpaceType::SPIN; + } + std::string SingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos));