fix meta data <-> char stream conversion for vector<T> meta type
This commit is contained in:
parent
49dd9ef548
commit
e2c33a2061
1 changed files with 106 additions and 43 deletions
|
@ -26,28 +26,31 @@ namespace MultiArrayTools
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void stringCat(vector<char>& out, const vector<T>& in)
|
struct TypeHandle
|
||||||
|
{
|
||||||
|
static inline void stringCat(vector<char>& out, const vector<T>& in)
|
||||||
{
|
{
|
||||||
//for(auto& x: in) { std::cout << x << std::endl; }
|
//for(auto& x: in) { std::cout << x << std::endl; }
|
||||||
const char* scp = reinterpret_cast<const char*>(in.data());
|
const char* scp = reinterpret_cast<const char*>(in.data());
|
||||||
out.insert(out.end(), scp, scp + in.size() * sizeof(T));
|
out.insert(out.end(), scp, scp + in.size() * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
static inline size_t metaSize(const vector<T>& in)
|
||||||
inline size_t metaSize(const vector<T>& in)
|
|
||||||
{
|
{
|
||||||
return in.size() * sizeof(T);
|
return in.size() * sizeof(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
static inline void metaCat(vector<T>& vec, const char* begin, size_t size)
|
||||||
inline void metaCat(vector<T>& vec, const char* begin, size_t size)
|
|
||||||
{
|
{
|
||||||
const T* tp = reinterpret_cast<const T*>( begin );
|
const T* tp = reinterpret_cast<const T*>( begin );
|
||||||
vec.insert(vec.end(), tp, tp + size / sizeof(T));
|
vec.insert(vec.end(), tp, tp + size / sizeof(T));
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void stringCat<std::string>(vector<char>& out, const vector<std::string>& in)
|
struct TypeHandle<std::string>
|
||||||
|
{
|
||||||
|
static inline void stringCat(vector<char>& out, const vector<std::string>& in)
|
||||||
{
|
{
|
||||||
//for(auto& x: in) { std::cout << x << std::endl; }
|
//for(auto& x: in) { std::cout << x << std::endl; }
|
||||||
std::string tmp = "";
|
std::string tmp = "";
|
||||||
|
@ -58,8 +61,7 @@ namespace MultiArrayTools
|
||||||
out.insert(out.end(), scp, scp + tmp.size());
|
out.insert(out.end(), scp, scp + tmp.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
static inline size_t metaSize(const vector<std::string>& in)
|
||||||
inline size_t metaSize<std::string>(const vector<std::string>& in)
|
|
||||||
{
|
{
|
||||||
size_t out = 0;
|
size_t out = 0;
|
||||||
for(auto& x: in){
|
for(auto& x: in){
|
||||||
|
@ -68,8 +70,7 @@ namespace MultiArrayTools
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
static inline void metaCat(vector<std::string>& vec, const char* begin, size_t size)
|
||||||
inline void metaCat<std::string>(vector<std::string>& vec, const char* begin, size_t size)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string tmp(begin, size);
|
std::string tmp(begin, size);
|
||||||
|
@ -83,6 +84,68 @@ namespace MultiArrayTools
|
||||||
pos = termpos + 1;
|
pos = termpos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct TypeHandle<vector<T>>
|
||||||
|
{
|
||||||
|
static inline void stringCat(vector<char>& out, const vector<vector<T>>& 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<const char*>(&size);
|
||||||
|
const char* scp = reinterpret_cast<const char*>(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<vector<T>>& 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<vector<T>>& vec, const char* begin, size_t size)
|
||||||
|
{
|
||||||
|
size_t pos = 0;
|
||||||
|
while(pos < size){
|
||||||
|
const size_t xsize = *reinterpret_cast<const size_t*>(begin+pos);
|
||||||
|
pos += sizeof(size_t);
|
||||||
|
const T* dbegin = reinterpret_cast<const T*>(begin+pos);
|
||||||
|
const T* dend = dbegin+xsize;
|
||||||
|
vec.emplace_back(dbegin,dend);
|
||||||
|
//vector<T> tmp(begin+pos, begin+npos);
|
||||||
|
//vec.push_back(tmp);
|
||||||
|
pos += xsize*sizeof(T);
|
||||||
|
}
|
||||||
|
assert(pos == size);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void stringCat(vector<char>& out, const vector<T>& in)
|
||||||
|
{
|
||||||
|
TypeHandle<T>::stringCat(out,in);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline size_t metaSize(const vector<T>& in)
|
||||||
|
{
|
||||||
|
return TypeHandle<T>::metaSize(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void metaCat(vector<T>& vec, const char* begin, size_t size)
|
||||||
|
{
|
||||||
|
TypeHandle<T>::metaCat(vec,begin,size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define XCOMMAX() ,
|
#define XCOMMAX() ,
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue