diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index f7633d1..8e22968 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -451,10 +451,7 @@ namespace MultiArrayTools template std::vector MapRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::ANY ); - h.metaSize = sizeof...(Ranges); - h.multiple = 1; + DataHeader h = dataHeader(); std::vector out; //out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); @@ -462,6 +459,16 @@ namespace MultiArrayTools RPackNum::fillRangeDataVec(out, mSpace); return out; } + + template + DataHeader MapRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::ANY ); + h.metaSize = sizeof...(Ranges); + h.multiple = 1; + return h; + } template typename MapRange::IndexType MapRange::begin() const diff --git a/src/include/map_range.h b/src/include/map_range.h index 57562d4..1b05612 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -257,7 +257,8 @@ namespace MultiArrayTools virtual size_t size() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + virtual std::string stringMeta(size_t pos) const final; virtual std::vector data() const final; diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index 43b84d1..2ff289c 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -78,7 +78,8 @@ namespace MultiArrayTools virtual IndexType end() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + virtual std::string stringMeta(size_t pos) const final; virtual std::vector data() const final; diff --git a/src/include/ranges/dynamic_range.cc.h b/src/include/ranges/dynamic_range.cc.h index 7e749fd..67ed416 100644 --- a/src/include/ranges/dynamic_range.cc.h +++ b/src/include/ranges/dynamic_range.cc.h @@ -459,10 +459,7 @@ namespace MultiArrayTools template std::vector DynamicRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::DYN ); - h.metaSize = mOrig.size(); - h.multiple = 1; + DataHeader h = dataHeader(); std::vector out; char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); @@ -473,6 +470,16 @@ namespace MultiArrayTools return out; } + template + DataHeader DynamicRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::DYN ); + h.metaSize = mOrig.size(); + h.multiple = 1; + return h; + } + template typename DynamicRange::IndexType DynamicRange::begin() const { diff --git a/src/include/ranges/dynamic_range.h b/src/include/ranges/dynamic_range.h index 6e5b4a2..c7be122 100644 --- a/src/include/ranges/dynamic_range.h +++ b/src/include/ranges/dynamic_range.h @@ -303,7 +303,8 @@ namespace MultiArrayTools virtual IndexType end() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() 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 9534aa3..7b0b7cc 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -189,7 +189,8 @@ namespace MultiArrayTools virtual size_t size() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + virtual std::string stringMeta(size_t pos) const final; virtual std::vector data() const final; @@ -568,10 +569,7 @@ namespace MultiArrayTools template std::vector MultiRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::ANY ); - h.metaSize = sizeof...(Ranges); - h.multiple = 1; + DataHeader h = dataHeader(); std::vector out; //out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); @@ -579,6 +577,16 @@ namespace MultiArrayTools RPackNum::fillRangeDataVec(out, mSpace); return out; } + + template + DataHeader MultiRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::ANY ); + h.metaSize = sizeof...(Ranges); + h.multiple = 1; + return h; + } template typename MultiRange::IndexType MultiRange::begin() const diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index 5c9e0f3..454584f 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -82,7 +82,7 @@ namespace MultiArrayTools virtual std::vector data() const = 0; // usefull when writing to files, etc... virtual SpaceType spaceType() const = 0; - + virtual DataHeader dataHeader() 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 diff --git a/src/include/ranges/range_types/classic_range.h b/src/include/ranges/range_types/classic_range.h index ba07956..a232bec 100644 --- a/src/include/ranges/range_types/classic_range.h +++ b/src/include/ranges/range_types/classic_range.h @@ -39,7 +39,8 @@ namespace MultiArrayTools virtual size_t dim() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + virtual std::string stringMeta(size_t pos) const final; virtual std::vector data() const final; diff --git a/src/include/ranges/range_types/null_range.h b/src/include/ranges/range_types/null_range.h index a4e5882..16e7c2c 100644 --- a/src/include/ranges/range_types/null_range.h +++ b/src/include/ranges/range_types/null_range.h @@ -49,7 +49,8 @@ namespace MultiArrayTools virtual std::vector data() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + 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 5d4878d..3187403 100644 --- a/src/include/ranges/range_types/space_range.h +++ b/src/include/ranges/range_types/space_range.h @@ -41,7 +41,8 @@ namespace MultiArrayTools virtual std::vector data() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + int get(size_t pos) const; size_t getMeta(int metaPos) const; diff --git a/src/include/ranges/range_types/spin_range.h b/src/include/ranges/range_types/spin_range.h index b1f3e8c..5fdfa5b 100644 --- a/src/include/ranges/range_types/spin_range.h +++ b/src/include/ranges/range_types/spin_range.h @@ -42,7 +42,8 @@ namespace MultiArrayTools virtual std::vector data() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + 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 ff7047a..128edf3 100644 --- a/src/include/ranges/single_range.h +++ b/src/include/ranges/single_range.h @@ -197,7 +197,8 @@ namespace MultiArrayTools virtual size_t dim() const final; virtual SpaceType spaceType() const final; - + virtual DataHeader dataHeader() const final; + virtual std::string stringMeta(size_t pos) const final; virtual std::vector data() const final; @@ -504,11 +505,7 @@ namespace MultiArrayTools template std::vector SingleRange::data() const { - DataHeader h; - h.spaceType = static_cast( TYPE ); - h.metaSize = metaSize(mSpace); - h.metaType = NumTypeMap::num; - h.multiple = 0; + DataHeader h = dataHeader(); std::vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); @@ -519,6 +516,17 @@ namespace MultiArrayTools return out; } + template + DataHeader SingleRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( TYPE ); + h.metaSize = metaSize(mSpace); + h.metaType = NumTypeMap::num; + h.multiple = 0; + return h; + } + template typename SingleRange::IndexType SingleRange::begin() const { diff --git a/src/include/ranges/type_map.h b/src/include/ranges/type_map.h index 17f31f9..117bfac 100644 --- a/src/include/ranges/type_map.h +++ b/src/include/ranges/type_map.h @@ -4,6 +4,7 @@ #include #include +#include #include namespace MultiArrayTools @@ -79,6 +80,8 @@ namespace MultiArrayTools pos = termpos + 1; } } + +#define XCOMMAX() , #define include_type(t,n) template <> struct TypeMap { typedef t type; };\ template <> struct NumTypeMap { static constexpr size_t num = n; }; @@ -89,11 +92,21 @@ namespace MultiArrayTools include_type(float,4) include_type(double,5) include_type(std::string,6) - + include_type(std::vector,101) + include_type(std::vector,102) + include_type(std::vector,105) + include_type(std::vector,106) + include_type(std::array,201) + include_type(std::array,202) + include_type(std::array,301) + include_type(std::array,302) + #undef include_type } #endif +#undef XCOMMAX + #ifdef register_type register_type(1) diff --git a/src/lib/ranges/anonymous_range.cc b/src/lib/ranges/anonymous_range.cc index a52e494..5014aea 100644 --- a/src/lib/ranges/anonymous_range.cc +++ b/src/lib/ranges/anonymous_range.cc @@ -110,10 +110,7 @@ namespace MultiArrayTools std::vector AnonymousRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::ANON ); - h.metaSize = mOrig.size(); - h.multiple = 1; + DataHeader h = dataHeader(); std::vector out; char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); @@ -123,7 +120,16 @@ namespace MultiArrayTools } return out; } - + + DataHeader AnonymousRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::ANON ); + h.metaSize = mOrig.size(); + h.multiple = 1; + return h; + } + size_t AnonymousRange::anonymousDim() const { return mOrig.size(); diff --git a/src/lib/ranges/range_types/classic_range.cc b/src/lib/ranges/range_types/classic_range.cc index d942fa9..9cdba7d 100644 --- a/src/lib/ranges/range_types/classic_range.cc +++ b/src/lib/ranges/range_types/classic_range.cc @@ -60,10 +60,7 @@ namespace MultiArrayTools std::vector SingleRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::NONE ); - h.metaSize = sizeof(size_t); - h.multiple = 0; + DataHeader h = dataHeader(); std::vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); @@ -73,6 +70,15 @@ namespace MultiArrayTools return out; } + DataHeader SingleRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::NONE ); + h.metaSize = sizeof(size_t); + h.multiple = 0; + return h; + } + typename SingleRange::IndexType SingleRange::begin() const { diff --git a/src/lib/ranges/range_types/null_range.cc b/src/lib/ranges/range_types/null_range.cc index 4c5e5c7..d42ebb5 100644 --- a/src/lib/ranges/range_types/null_range.cc +++ b/src/lib/ranges/range_types/null_range.cc @@ -83,16 +83,22 @@ namespace MultiArrayTools std::vector SingleRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::NUL ); - h.metaSize = 0; - h.multiple = 0; + DataHeader h = dataHeader(); std::vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); return out; } + + DataHeader SingleRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::NUL ); + h.metaSize = 0; + h.multiple = 0; + return h; + } typename SingleRange::IndexType SingleRange::begin() const { diff --git a/src/lib/ranges/range_types/space_range.cc b/src/lib/ranges/range_types/space_range.cc index 3d537aa..e4ca7f3 100644 --- a/src/lib/ranges/range_types/space_range.cc +++ b/src/lib/ranges/range_types/space_range.cc @@ -66,10 +66,7 @@ namespace MultiArrayTools std::vector SingleRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::PSPACE ); - h.metaSize = sizeof(size_t); - h.multiple = 0; + DataHeader h = dataHeader(); std::vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); @@ -78,6 +75,15 @@ namespace MultiArrayTools out.insert(out.end(), scp, scp + h.metaSize); return out; } + + DataHeader SingleRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::PSPACE ); + h.metaSize = sizeof(size_t); + h.multiple = 0; + return h; + } typename SingleRange::IndexType SingleRange::begin() const { diff --git a/src/lib/ranges/range_types/spin_range.cc b/src/lib/ranges/range_types/spin_range.cc index c5c7b0e..b391481 100644 --- a/src/lib/ranges/range_types/spin_range.cc +++ b/src/lib/ranges/range_types/spin_range.cc @@ -63,17 +63,23 @@ namespace MultiArrayTools std::vector SingleRange::data() const { - DataHeader h; - h.spaceType = static_cast( SpaceType::SPIN ); - h.metaSize = 0; - h.multiple = 0; + DataHeader h = dataHeader(); std::vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); return out; } - + + DataHeader SingleRange::dataHeader() const + { + DataHeader h; + h.spaceType = static_cast( SpaceType::SPIN ); + h.metaSize = 0; + h.multiple = 0; + return h; + } + typename SingleRange::IndexType SingleRange::begin() const { SingleIndex i( std::dynamic_pointer_cast >