some utils

This commit is contained in:
Christian Zimmermann 2019-03-27 19:00:16 +01:00
parent a0a139b0a1
commit 45d25a4d76
4 changed files with 36 additions and 4 deletions

View file

@ -120,6 +120,32 @@ namespace MultiArrayTools
return std::dynamic_pointer_cast<Range>( rbptr ); return std::dynamic_pointer_cast<Range>( rbptr );
} }
inline auto createRange(const vector<char>* cvec, int metaType, size_t size)
-> std::shared_ptr<RangeBase>
{
auto f = createSingleRangeFactory(cvec, metaType, size);
return f->create();
}
inline auto createRangeA(const vector<char>* cvec, int metaType, size_t size)
-> std::shared_ptr<AnonymousRange>
{
AnonymousRangeFactory arf(createRange(cvec, metaType, size));
return createExplicit(arf);
}
inline auto cvecMetaCast(const std::shared_ptr<SingleRange<vector<char>,SpaceType::ANY>>& r, int metaType)
-> std::shared_ptr<RangeBase>
{
return createRange(&r->get(0), metaType, r->size());
}
inline auto cvecMetaCastA(const std::shared_ptr<SingleRange<vector<char>,SpaceType::ANY>>& r, int metaType)
-> std::shared_ptr<AnonymousRange>
{
return createRangeA(&r->get(0), metaType, r->size());
}
template <class Range, typename... Args> template <class Range, typename... Args>
auto createRangeE(Args&&... args) auto createRangeE(Args&&... args)
-> std::shared_ptr<Range> -> std::shared_ptr<Range>

View file

@ -64,6 +64,12 @@ namespace MultiArrayTools
auto createRange(const vector<char>& cvec) auto createRange(const vector<char>& cvec)
-> std::shared_ptr<Range>; -> std::shared_ptr<Range>;
inline auto createRange(const vector<char>* cvec, int metaType, size_t size)
-> std::shared_ptr<RangeBase>;
inline auto createRangeA(const vector<char>* cvec, int metaType, size_t size)
-> std::shared_ptr<AnonymousRange>;
template <class Range, typename... Args> template <class Range, typename... Args>
auto createRangeE(Args&&... args) auto createRangeE(Args&&... args)
-> std::shared_ptr<Range>; -> std::shared_ptr<Range>;

View file

@ -63,7 +63,7 @@ namespace MultiArrayTools
}; };
std::shared_ptr<RangeFactoryBase> createRangeFactory(const char** dp); std::shared_ptr<RangeFactoryBase> createRangeFactory(const char** dp);
std::shared_ptr<RangeFactoryBase> createSingleRangeFactory(const vector<vector<char>>& d, size_t metaType); std::shared_ptr<RangeFactoryBase> createSingleRangeFactory(const vector<char>*& d, int metaType, size_t size);
class RangeBase class RangeBase
{ {

View file

@ -122,15 +122,15 @@ namespace MultiArrayTools
return out; return out;
} }
std::shared_ptr<RangeFactoryBase> createSingleRangeFactory(const vector<vector<char>>& d, int metaType) std::shared_ptr<RangeFactoryBase> createSingleRangeFactory(const vector<char>*& d, int metaType, size_t size)
{ {
std::shared_ptr<RangeFactoryBase> out = nullptr; std::shared_ptr<RangeFactoryBase> out = nullptr;
if(metaType == -1){ if(metaType == -1){
assert(0); assert(0);
} }
#define register_type(x) else if(x == metaType) { \ #define register_type(x) else if(x == metaType) { \
vector<TypeMap<x>::type> vd(d.size()); \ vector<TypeMap<x>::type> vd(size); \
std::transform(d.begin(),d.end(),vd.begin(), \ std::transform(d,d+size,vd.begin(), \
[](const vector<char>& c) \ [](const vector<char>& c) \
{ assert(c.size() == sizeof(TypeMap<x>::type)); \ { assert(c.size() == sizeof(TypeMap<x>::type)); \
return *reinterpret_cast<TypeMap<x>::type const*>(c.data()); }); \ return *reinterpret_cast<TypeMap<x>::type const*>(c.data()); }); \