diff --git a/src/include/helper_tools.h b/src/include/helper_tools.h index b5c11c1..3754dbb 100644 --- a/src/include/helper_tools.h +++ b/src/include/helper_tools.h @@ -41,6 +41,9 @@ namespace MultiArrayTools auto createExplicit(std::shared_ptr rfp) -> std::shared_ptr; + template + auto createRange(const std::vector& cvec) + -> std::shared_ptr; } /* ========================= * @@ -112,7 +115,19 @@ namespace MultiArrayTools { return std::dynamic_pointer_cast( rfp->create() ); } - + + template + auto createRange(const std::vector& cvec) + -> std::shared_ptr + { + const char* dp = cvec.data(); + auto ff = createRangeFactory(&dp); + auto rbptr = ff->create(); + assert(rbptr->spaceType() == Range::STYPE); + // CATCH CAST ERROR HERE !!! + return std::dynamic_pointer_cast( rbptr ); + } + } #endif diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index e13666c..a81db50 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -220,7 +220,7 @@ namespace MultiArrayTools } // -> define in range_base.cc - std::shared_ptr mkMULTI(char** dp); + std::shared_ptr mkMULTI(const char** dp); /****************** * MultiIndex * diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index 1824755..a35593b 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -61,7 +61,7 @@ namespace MultiArrayTools void setSelf(); }; - std::shared_ptr createRangeFactory(char** dp); + std::shared_ptr createRangeFactory(const char** dp); class RangeBase { diff --git a/src/include/ranges/range_types/null_range.h b/src/include/ranges/range_types/null_range.h index d875d54..d0a83b9 100644 --- a/src/include/ranges/range_types/null_range.h +++ b/src/include/ranges/range_types/null_range.h @@ -79,7 +79,7 @@ namespace MultiArrayTools typedef SingleRange NullRange; typedef SingleRangeFactory NullRF; - std::shared_ptr mkNUL(char* dp, size_t size); + std::shared_ptr mkNUL(const char* dp, size_t size); } diff --git a/src/include/ranges/range_types/space_range.h b/src/include/ranges/range_types/space_range.h index 18c5595..8758a0d 100644 --- a/src/include/ranges/range_types/space_range.h +++ b/src/include/ranges/range_types/space_range.h @@ -71,7 +71,7 @@ namespace MultiArrayTools typedef SingleRange PSpaceRange; typedef SingleRangeFactory PSpaceRF; - std::shared_ptr mkPSPACE(char* dp, size_t size); + std::shared_ptr mkPSPACE(const char* dp, size_t size); template struct PromoteMSpaceRange diff --git a/src/include/ranges/range_types/spin_range.h b/src/include/ranges/range_types/spin_range.h index 05e8025..80031cd 100644 --- a/src/include/ranges/range_types/spin_range.h +++ b/src/include/ranges/range_types/spin_range.h @@ -73,7 +73,7 @@ namespace MultiArrayTools typedef SingleRange SpinRange; typedef SingleRangeFactory SpinRF; - std::shared_ptr mkSPIN(char* dp, size_t size); + std::shared_ptr mkSPIN(const char* dp, size_t size); } diff --git a/src/include/ranges/type_map.h b/src/include/ranges/type_map.h index 645faa5..2a33bc1 100644 --- a/src/include/ranges/type_map.h +++ b/src/include/ranges/type_map.h @@ -4,6 +4,7 @@ #include #include +//#include namespace MultiArrayTools { @@ -34,9 +35,9 @@ namespace MultiArrayTools } template - inline void metaCat(std::vector& vec, char* begin, size_t size) + inline void metaCat(std::vector& vec, const char* begin, size_t size) { - T* tp = reinterpret_cast( begin ); + const T* tp = reinterpret_cast( begin ); vec.insert(vec.end(), tp, tp + size / sizeof(T)); } @@ -62,10 +63,11 @@ namespace MultiArrayTools } template <> - inline void metaCat(std::vector& vec, char* begin, size_t size) + inline void metaCat(std::vector& vec, const char* begin, size_t size) { std::string tmp(begin, size); + //std::cout << tmp << std::endl; size_t pos = 0; while(pos != tmp.size()){ std::string es = "\n"; diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index 7a70339..26417fa 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -45,7 +45,7 @@ namespace MultiArrayTools return id; } - std::shared_ptr mkMULTI(char** dp, size_t metaSize) + std::shared_ptr mkMULTI(char const** dp, size_t metaSize) { std::shared_ptr out = nullptr; RVEC rvec(metaSize); @@ -88,7 +88,7 @@ namespace MultiArrayTools return out; } - std::shared_ptr mkANONYMOUS(char** dp, size_t metaSize) + std::shared_ptr mkANONYMOUS(char const** dp, size_t metaSize) { std::shared_ptr out = nullptr; auto arf = std::make_shared(); @@ -100,7 +100,7 @@ namespace MultiArrayTools return out; } - std::shared_ptr createRangeFactory(char** dp) + std::shared_ptr createRangeFactory(char const** dp) { DataHeader h = *reinterpret_cast(*dp); *dp += sizeof(DataHeader); @@ -126,7 +126,7 @@ namespace MultiArrayTools if(h.metaType == -1){ assert(0); } -#define register_type(x) else if(x == h.metaType) {\ +#define register_type(x) else if(x == h.metaType) { \ std::vector::type> vd;\ metaCat(vd, *dp, h.metaSize); \ out = std::make_shared::type, \ diff --git a/src/lib/ranges/range_types/null_range.cc b/src/lib/ranges/range_types/null_range.cc index 86beaaf..5398e8f 100644 --- a/src/lib/ranges/range_types/null_range.cc +++ b/src/lib/ranges/range_types/null_range.cc @@ -4,7 +4,7 @@ namespace MultiArrayTools { - std::shared_ptr mkNUL(char* dp, size_t size) + std::shared_ptr mkNUL(const char* dp, size_t size) { return std::make_shared(); } diff --git a/src/lib/ranges/range_types/space_range.cc b/src/lib/ranges/range_types/space_range.cc index d28b7cf..3d537aa 100644 --- a/src/lib/ranges/range_types/space_range.cc +++ b/src/lib/ranges/range_types/space_range.cc @@ -4,9 +4,9 @@ namespace MultiArrayTools { - std::shared_ptr mkPSPACE(char* dp, size_t size) + std::shared_ptr mkPSPACE(const char* dp, size_t size) { - size_t max = *reinterpret_cast(dp); + size_t max = *reinterpret_cast(dp); return std::make_shared(max); } diff --git a/src/lib/ranges/range_types/spin_range.cc b/src/lib/ranges/range_types/spin_range.cc index 501283e..c5c7b0e 100644 --- a/src/lib/ranges/range_types/spin_range.cc +++ b/src/lib/ranges/range_types/spin_range.cc @@ -4,7 +4,7 @@ namespace MultiArrayTools { - std::shared_ptr mkSPIN(char* dp, size_t size) + std::shared_ptr mkSPIN(const char* dp, size_t size) { return std::make_shared(); } diff --git a/src/tests/ranges/anonymous_unit_test.cc b/src/tests/ranges/anonymous_unit_test.cc index 9a4f0f5..80e6f80 100644 --- a/src/tests/ranges/anonymous_unit_test.cc +++ b/src/tests/ranges/anonymous_unit_test.cc @@ -126,7 +126,7 @@ namespace { TEST_F(AnonymousTest, ToString1) { std::vector vv = sr1ptr->data(); - char* dp = vv.data(); + const char* dp = vv.data(); auto ff = createRangeFactory(&dp); auto ss = std::dynamic_pointer_cast( ff->create() ); @@ -151,9 +151,9 @@ namespace { std::vector cv = cr->data(); std::vector sv = sr->data(); std::vector nv = nr->data(); - char* cp = cv.data(); - char* sp = sv.data(); - char* np = nv.data(); + const char* cp = cv.data(); + const char* sp = sv.data(); + const char* np = nv.data(); auto crf2 = createRangeFactory(&cp); auto cr2 = std::dynamic_pointer_cast( crf2->create() ); @@ -178,7 +178,7 @@ namespace { TEST_F(AnonymousTest, ToStringMulti) { std::vector vv = m3rptr->data(); - char* dp = vv.data(); + const char* dp = vv.data(); auto ff2 = std::dynamic_pointer_cast( createRangeFactory(&dp) ); auto mr2 = std::dynamic_pointer_cast( ff2->create() ); @@ -201,7 +201,7 @@ namespace { AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); auto ar = std::dynamic_pointer_cast( arf2.create() ); std::vector vv = ar->data(); - char* dp = vv.data(); + const char* dp = vv.data(); auto ff2 = std::dynamic_pointer_cast( createRangeFactory(&dp) ); auto ar2 = std::dynamic_pointer_cast( ff2->create() );