From 45d25a4d76381fc5d9541819574a9d0215ffb939 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 27 Mar 2019 19:00:16 +0100 Subject: [PATCH] some utils --- src/include/helper_tools.cc.h | 26 ++++++++++++++++++++++++++ src/include/helper_tools.h | 6 ++++++ src/include/ranges/range_base.h | 2 +- src/lib/ranges/range_base.cc | 6 +++--- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/include/helper_tools.cc.h b/src/include/helper_tools.cc.h index 2d37f4c..ecda582 100644 --- a/src/include/helper_tools.cc.h +++ b/src/include/helper_tools.cc.h @@ -120,6 +120,32 @@ namespace MultiArrayTools return std::dynamic_pointer_cast( rbptr ); } + inline auto createRange(const vector* cvec, int metaType, size_t size) + -> std::shared_ptr + { + auto f = createSingleRangeFactory(cvec, metaType, size); + return f->create(); + } + + inline auto createRangeA(const vector* cvec, int metaType, size_t size) + -> std::shared_ptr + { + AnonymousRangeFactory arf(createRange(cvec, metaType, size)); + return createExplicit(arf); + } + + inline auto cvecMetaCast(const std::shared_ptr,SpaceType::ANY>>& r, int metaType) + -> std::shared_ptr + { + return createRange(&r->get(0), metaType, r->size()); + } + + inline auto cvecMetaCastA(const std::shared_ptr,SpaceType::ANY>>& r, int metaType) + -> std::shared_ptr + { + return createRangeA(&r->get(0), metaType, r->size()); + } + template auto createRangeE(Args&&... args) -> std::shared_ptr diff --git a/src/include/helper_tools.h b/src/include/helper_tools.h index 24403ed..53c1ee0 100644 --- a/src/include/helper_tools.h +++ b/src/include/helper_tools.h @@ -64,6 +64,12 @@ namespace MultiArrayTools auto createRange(const vector& cvec) -> std::shared_ptr; + inline auto createRange(const vector* cvec, int metaType, size_t size) + -> std::shared_ptr; + + inline auto createRangeA(const vector* cvec, int metaType, size_t size) + -> std::shared_ptr; + template auto createRangeE(Args&&... args) -> std::shared_ptr; diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index a19cf73..9eab881 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -63,7 +63,7 @@ namespace MultiArrayTools }; std::shared_ptr createRangeFactory(const char** dp); - std::shared_ptr createSingleRangeFactory(const vector>& d, size_t metaType); + std::shared_ptr createSingleRangeFactory(const vector*& d, int metaType, size_t size); class RangeBase { diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index 015b8a1..db498ea 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -122,15 +122,15 @@ namespace MultiArrayTools return out; } - std::shared_ptr createSingleRangeFactory(const vector>& d, int metaType) + std::shared_ptr createSingleRangeFactory(const vector*& d, int metaType, size_t size) { 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(), \ + vector::type> vd(size); \ + std::transform(d,d+size,vd.begin(), \ [](const vector& c) \ { assert(c.size() == sizeof(TypeMap::type)); \ return *reinterpret_cast::type const*>(c.data()); }); \