diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index 102af5a..a19cf73 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -63,6 +63,7 @@ namespace MultiArrayTools }; std::shared_ptr createRangeFactory(const char** dp); + std::shared_ptr createSingleRangeFactory(const vector>& d, size_t metaType); class RangeBase { diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index 6f1d5eb..015b8a1 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -7,6 +7,8 @@ #include "ranges/range_base.h" +#include + namespace MultiArrayTools { @@ -100,6 +102,48 @@ namespace MultiArrayTools return out; } + + std::shared_ptr mkANY(int metaType, size_t metaSize, char const** dp) + { + std::shared_ptr out = nullptr; + if(metaType == -1){ + assert(0); + } +#define register_type(x) else if(x == metaType) { \ + vector::type> vd; \ + metaCat(vd, *dp, metaSize); \ + out = std::make_shared::type, \ + SpaceType::ANY> >(vd); } +#include "ranges/type_map.h" +#undef register_type + else { + assert(0); + } + return out; + } + + std::shared_ptr createSingleRangeFactory(const vector>& d, int metaType) + { + std::shared_ptr out = nullptr; + if(metaType == -1){ + assert(0); + } +#define register_type(x) else if(x == metaType) { \ + vector::type> vd(d.size()); \ + std::transform(d.begin(),d.end(),vd.begin(), \ + [](const vector& c) \ + { assert(c.size() == sizeof(TypeMap::type)); \ + return *reinterpret_cast::type const*>(c.data()); }); \ + out = std::make_shared::type, \ + SpaceType::ANY> >(vd); } +#include "ranges/type_map.h" +#undef register_type + else { + assert(0); + } + return out; + } + std::shared_ptr createRangeFactory(char const** dp) { DataHeader h = *reinterpret_cast(*dp); @@ -123,20 +167,7 @@ namespace MultiArrayTools else { if(h.spaceType == static_cast( SpaceType::ANY ) ) { // generic single range - if(h.metaType == -1){ - assert(0); - } -#define register_type(x) else if(x == h.metaType) { \ - vector::type> vd;\ - metaCat(vd, *dp, h.metaSize); \ - out = std::make_shared::type, \ - SpaceType::ANY> >(vd); } -#include "ranges/type_map.h" -#undef register_type - else { - assert(0); - } - + out = mkANY(h.metaType, h.metaSize, dp); } else if(h.spaceType == static_cast( SpaceType::NONE ) ) { // classic range