diff --git a/src/include/ranges/type_map.h b/src/include/ranges/type_map.h index c009e19..ada6d30 100644 --- a/src/include/ranges/type_map.h +++ b/src/include/ranges/type_map.h @@ -25,64 +25,127 @@ namespace MultiArrayTools static constexpr size_t num = 0; }; + template + struct TypeHandle + { + static inline void stringCat(vector& out, const vector& in) + { + //for(auto& x: in) { std::cout << x << std::endl; } + const char* scp = reinterpret_cast(in.data()); + out.insert(out.end(), scp, scp + in.size() * sizeof(T)); + } + + static inline size_t metaSize(const vector& in) + { + return in.size() * sizeof(T); + } + + static inline void metaCat(vector& vec, const char* begin, size_t size) + { + const T* tp = reinterpret_cast( begin ); + vec.insert(vec.end(), tp, tp + size / sizeof(T)); + } + }; + + template <> + struct TypeHandle + { + static inline void stringCat(vector& out, const vector& in) + { + //for(auto& x: in) { std::cout << x << std::endl; } + std::string tmp = ""; + for(auto& x: in){ + tmp += x + '\n'; + } + const char* scp = reinterpret_cast(tmp.data()); + out.insert(out.end(), scp, scp + tmp.size()); + } + + static inline size_t metaSize(const vector& in) + { + size_t out = 0; + for(auto& x: in){ + out += x.size() + 1; + } + return out; + } + + static inline void metaCat(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"; + size_t termpos = tmp.find_first_of(es, pos); + std::string tmpstr = tmp.substr(pos, termpos-pos); + vec.push_back(tmpstr); + pos = termpos + 1; + } + } + }; + + template + struct TypeHandle> + { + static inline void stringCat(vector& out, const vector>& in) + { + //for(auto& x: in) { std::cout << x << std::endl; } + for(auto& x: in){ + const size_t size = x.size(); + const char* ss = reinterpret_cast(&size); + const char* scp = reinterpret_cast(x.data()); + out.insert(out.end(), ss, ss + sizeof(size_t)); + out.insert(out.end(), scp, scp + size*sizeof(T)); + } + } + + static inline size_t metaSize(const vector>& in) + { + size_t out = 0; + for(auto& x: in){ + out += x.size()*sizeof(T); + out += sizeof(size_t); + } + return out; + } + + static inline void metaCat(vector>& vec, const char* begin, size_t size) + { + size_t pos = 0; + while(pos < size){ + const size_t xsize = *reinterpret_cast(begin+pos); + pos += sizeof(size_t); + const T* dbegin = reinterpret_cast(begin+pos); + const T* dend = dbegin+xsize; + vec.emplace_back(dbegin,dend); + //vector tmp(begin+pos, begin+npos); + //vec.push_back(tmp); + pos += xsize*sizeof(T); + } + assert(pos == size); + } + }; + template inline void stringCat(vector& out, const vector& in) { - //for(auto& x: in) { std::cout << x << std::endl; } - const char* scp = reinterpret_cast(in.data()); - out.insert(out.end(), scp, scp + in.size() * sizeof(T)); + TypeHandle::stringCat(out,in); } template inline size_t metaSize(const vector& in) { - return in.size() * sizeof(T); + return TypeHandle::metaSize(in); } template inline void metaCat(vector& vec, const char* begin, size_t size) { - const T* tp = reinterpret_cast( begin ); - vec.insert(vec.end(), tp, tp + size / sizeof(T)); + TypeHandle::metaCat(vec,begin,size); } - template <> - inline void stringCat(vector& out, const vector& in) - { - //for(auto& x: in) { std::cout << x << std::endl; } - std::string tmp = ""; - for(auto& x: in){ - tmp += x + '\n'; - } - const char* scp = reinterpret_cast(tmp.data()); - out.insert(out.end(), scp, scp + tmp.size()); - } - - template <> - inline size_t metaSize(const vector& in) - { - size_t out = 0; - for(auto& x: in){ - out += x.size() + 1; - } - return out; - } - - template <> - inline void metaCat(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"; - size_t termpos = tmp.find_first_of(es, pos); - std::string tmpstr = tmp.substr(pos, termpos-pos); - vec.push_back(tmpstr); - pos = termpos + 1; - } - } #define XCOMMAX() ,