dataHeader function

This commit is contained in:
Christian Zimmermann 2018-11-07 10:58:07 +01:00
parent 772d9c2828
commit 6626384f69
18 changed files with 130 additions and 50 deletions

View file

@ -451,10 +451,7 @@ namespace MultiArrayTools
template <class MapF, class... Ranges>
std::vector<char> MapRange<MapF,Ranges...>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANY );
h.metaSize = sizeof...(Ranges);
h.multiple = 1;
DataHeader h = dataHeader();
std::vector<char> out;
//out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
@ -462,6 +459,16 @@ namespace MultiArrayTools
RPackNum<sizeof...(Ranges)-1>::fillRangeDataVec(out, mSpace);
return out;
}
template <class MapF, class... Ranges>
DataHeader MapRange<MapF,Ranges...>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANY );
h.metaSize = sizeof...(Ranges);
h.multiple = 1;
return h;
}
template <class MapF, class... Ranges>
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::begin() const

View file

@ -257,7 +257,8 @@ namespace MultiArrayTools
virtual size_t size() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;

View file

@ -78,7 +78,8 @@ namespace MultiArrayTools
virtual IndexType end() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;

View file

@ -459,10 +459,7 @@ namespace MultiArrayTools
template <class EC>
std::vector<char> DynamicRange<EC>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::DYN );
h.metaSize = mOrig.size();
h.multiple = 1;
DataHeader h = dataHeader();
std::vector<char> out;
char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
@ -473,6 +470,16 @@ namespace MultiArrayTools
return out;
}
template <class EC>
DataHeader DynamicRange<EC>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::DYN );
h.metaSize = mOrig.size();
h.multiple = 1;
return h;
}
template <class EC>
typename DynamicRange<EC>::IndexType DynamicRange<EC>::begin() const
{

View file

@ -303,7 +303,8 @@ namespace MultiArrayTools
virtual IndexType end() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;

View file

@ -189,7 +189,8 @@ namespace MultiArrayTools
virtual size_t size() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;
@ -568,10 +569,7 @@ namespace MultiArrayTools
template <class... Ranges>
std::vector<char> MultiRange<Ranges...>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANY );
h.metaSize = sizeof...(Ranges);
h.multiple = 1;
DataHeader h = dataHeader();
std::vector<char> out;
//out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
@ -579,6 +577,16 @@ namespace MultiArrayTools
RPackNum<sizeof...(Ranges)-1>::fillRangeDataVec(out, mSpace);
return out;
}
template <class... Ranges>
DataHeader MultiRange<Ranges...>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANY );
h.metaSize = sizeof...(Ranges);
h.multiple = 1;
return h;
}
template <class... Ranges>
typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::begin() const

View file

@ -82,7 +82,7 @@ namespace MultiArrayTools
virtual std::vector<char> data() const = 0; // usefull when writing to files, etc...
virtual SpaceType spaceType() const = 0;
virtual DataHeader dataHeader() const = 0;
//virtual bool regular() const = 0; // integer distance (e.g. 2,3,4,...)
//virtual bool linear() const = 0; // 1dim valuable (e.g. 2.45, 3.12, 3.56,...)
//virtual bool multi() const = 0; // mdim

View file

@ -39,7 +39,8 @@ namespace MultiArrayTools
virtual size_t dim() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;

View file

@ -49,7 +49,8 @@ namespace MultiArrayTools
virtual std::vector<char> data() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
size_t get(size_t pos) const;
size_t getMeta(size_t metapos) const;

View file

@ -41,7 +41,8 @@ namespace MultiArrayTools
virtual std::vector<char> data() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
int get(size_t pos) const;
size_t getMeta(int metaPos) const;

View file

@ -42,7 +42,8 @@ namespace MultiArrayTools
virtual std::vector<char> data() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const;

View file

@ -197,7 +197,8 @@ namespace MultiArrayTools
virtual size_t dim() const final;
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;
@ -504,11 +505,7 @@ namespace MultiArrayTools
template <typename U, SpaceType TYPE>
std::vector<char> SingleRange<U,TYPE>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( TYPE );
h.metaSize = metaSize(mSpace);
h.metaType = NumTypeMap<U>::num;
h.multiple = 0;
DataHeader h = dataHeader();
std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
@ -519,6 +516,17 @@ namespace MultiArrayTools
return out;
}
template <typename U, SpaceType TYPE>
DataHeader SingleRange<U,TYPE>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( TYPE );
h.metaSize = metaSize(mSpace);
h.metaType = NumTypeMap<U>::num;
h.multiple = 0;
return h;
}
template <typename U, SpaceType TYPE>
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const
{

View file

@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <array>
#include <iostream>
namespace MultiArrayTools
@ -79,6 +80,8 @@ namespace MultiArrayTools
pos = termpos + 1;
}
}
#define XCOMMAX() ,
#define include_type(t,n) template <> struct TypeMap<n> { typedef t type; };\
template <> struct NumTypeMap<t> { static constexpr size_t num = n; };
@ -89,11 +92,21 @@ namespace MultiArrayTools
include_type(float,4)
include_type(double,5)
include_type(std::string,6)
include_type(std::vector<size_t>,101)
include_type(std::vector<int>,102)
include_type(std::vector<double>,105)
include_type(std::vector<std::string>,106)
include_type(std::array<size_t XCOMMAX() 2>,201)
include_type(std::array<int XCOMMAX() 2>,202)
include_type(std::array<size_t XCOMMAX() 3>,301)
include_type(std::array<int XCOMMAX() 3>,302)
#undef include_type
}
#endif
#undef XCOMMAX
#ifdef register_type
register_type(1)

View file

@ -110,10 +110,7 @@ namespace MultiArrayTools
std::vector<char> AnonymousRange::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANON );
h.metaSize = mOrig.size();
h.multiple = 1;
DataHeader h = dataHeader();
std::vector<char> out;
char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
@ -123,7 +120,16 @@ namespace MultiArrayTools
}
return out;
}
DataHeader AnonymousRange::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANON );
h.metaSize = mOrig.size();
h.multiple = 1;
return h;
}
size_t AnonymousRange::anonymousDim() const
{
return mOrig.size();

View file

@ -60,10 +60,7 @@ namespace MultiArrayTools
std::vector<char> SingleRange<size_t,SpaceType::NONE>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::NONE );
h.metaSize = sizeof(size_t);
h.multiple = 0;
DataHeader h = dataHeader();
std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
@ -73,6 +70,15 @@ namespace MultiArrayTools
return out;
}
DataHeader SingleRange<size_t,SpaceType::NONE>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::NONE );
h.metaSize = sizeof(size_t);
h.multiple = 0;
return h;
}
typename SingleRange<size_t,SpaceType::NONE>::IndexType SingleRange<size_t,SpaceType::NONE>::begin() const
{

View file

@ -83,16 +83,22 @@ namespace MultiArrayTools
std::vector<char> SingleRange<size_t,SpaceType::NUL>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::NUL );
h.metaSize = 0;
h.multiple = 0;
DataHeader h = dataHeader();
std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
return out;
}
DataHeader SingleRange<size_t,SpaceType::NUL>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::NUL );
h.metaSize = 0;
h.multiple = 0;
return h;
}
typename SingleRange<size_t,SpaceType::NUL>::IndexType SingleRange<size_t,SpaceType::NUL>::begin() const
{

View file

@ -66,10 +66,7 @@ namespace MultiArrayTools
std::vector<char> SingleRange<int,SpaceType::PSPACE>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::PSPACE );
h.metaSize = sizeof(size_t);
h.multiple = 0;
DataHeader h = dataHeader();
std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
@ -78,6 +75,15 @@ namespace MultiArrayTools
out.insert(out.end(), scp, scp + h.metaSize);
return out;
}
DataHeader SingleRange<int,SpaceType::PSPACE>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::PSPACE );
h.metaSize = sizeof(size_t);
h.multiple = 0;
return h;
}
typename SingleRange<int,SpaceType::PSPACE>::IndexType SingleRange<int,SpaceType::PSPACE>::begin() const
{

View file

@ -63,17 +63,23 @@ namespace MultiArrayTools
std::vector<char> SingleRange<size_t,SpaceType::SPIN>::data() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::SPIN );
h.metaSize = 0;
h.multiple = 0;
DataHeader h = dataHeader();
std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
return out;
}
DataHeader SingleRange<size_t,SpaceType::SPIN>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::SPIN );
h.metaSize = 0;
h.multiple = 0;
return h;
}
typename SingleRange<size_t,SpaceType::SPIN>::IndexType SingleRange<size_t,SpaceType::SPIN>::begin() const
{
SingleIndex<size_t,SpaceType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >