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> template <class MapF, class... Ranges>
std::vector<char> MapRange<MapF,Ranges...>::data() const std::vector<char> MapRange<MapF,Ranges...>::data() const
{ {
DataHeader h; DataHeader h = dataHeader();
h.spaceType = static_cast<int>( SpaceType::ANY );
h.metaSize = sizeof...(Ranges);
h.multiple = 1;
std::vector<char> out; std::vector<char> out;
//out.reserve(h.metaSize + sizeof(DataHeader)); //out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
@ -463,6 +460,16 @@ namespace MultiArrayTools
return out; 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> template <class MapF, class... Ranges>
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::begin() const typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::begin() const
{ {

View file

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

View file

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

View file

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

View file

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

View file

@ -189,6 +189,7 @@ namespace MultiArrayTools
virtual size_t size() const final; virtual size_t size() const final;
virtual SpaceType spaceType() const final; virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual std::vector<char> data() const final;
@ -568,10 +569,7 @@ namespace MultiArrayTools
template <class... Ranges> template <class... Ranges>
std::vector<char> MultiRange<Ranges...>::data() const std::vector<char> MultiRange<Ranges...>::data() const
{ {
DataHeader h; DataHeader h = dataHeader();
h.spaceType = static_cast<int>( SpaceType::ANY );
h.metaSize = sizeof...(Ranges);
h.multiple = 1;
std::vector<char> out; std::vector<char> out;
//out.reserve(h.metaSize + sizeof(DataHeader)); //out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
@ -580,6 +578,16 @@ namespace MultiArrayTools
return out; 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> template <class... Ranges>
typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::begin() const 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 std::vector<char> data() const = 0; // usefull when writing to files, etc...
virtual SpaceType spaceType() const = 0; virtual SpaceType spaceType() const = 0;
virtual DataHeader dataHeader() const = 0;
//virtual bool regular() const = 0; // integer distance (e.g. 2,3,4,...) //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 linear() const = 0; // 1dim valuable (e.g. 2.45, 3.12, 3.56,...)
//virtual bool multi() const = 0; // mdim //virtual bool multi() const = 0; // mdim

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <array>
#include <iostream> #include <iostream>
namespace MultiArrayTools namespace MultiArrayTools
@ -80,6 +81,8 @@ namespace MultiArrayTools
} }
} }
#define XCOMMAX() ,
#define include_type(t,n) template <> struct TypeMap<n> { typedef t type; };\ #define include_type(t,n) template <> struct TypeMap<n> { typedef t type; };\
template <> struct NumTypeMap<t> { static constexpr size_t num = n; }; template <> struct NumTypeMap<t> { static constexpr size_t num = n; };
@ -89,11 +92,21 @@ namespace MultiArrayTools
include_type(float,4) include_type(float,4)
include_type(double,5) include_type(double,5)
include_type(std::string,6) 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 #undef include_type
} }
#endif #endif
#undef XCOMMAX
#ifdef register_type #ifdef register_type
register_type(1) register_type(1)

View file

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

View file

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

View file

@ -83,10 +83,7 @@ namespace MultiArrayTools
std::vector<char> SingleRange<size_t,SpaceType::NUL>::data() const std::vector<char> SingleRange<size_t,SpaceType::NUL>::data() const
{ {
DataHeader h; DataHeader h = dataHeader();
h.spaceType = static_cast<int>( SpaceType::NUL );
h.metaSize = 0;
h.multiple = 0;
std::vector<char> out; std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
@ -94,6 +91,15 @@ namespace MultiArrayTools
return out; 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 typename SingleRange<size_t,SpaceType::NUL>::IndexType SingleRange<size_t,SpaceType::NUL>::begin() const
{ {
SingleIndex<size_t,SpaceType::NUL> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NUL> > SingleIndex<size_t,SpaceType::NUL> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NUL> >

View file

@ -66,10 +66,7 @@ namespace MultiArrayTools
std::vector<char> SingleRange<int,SpaceType::PSPACE>::data() const std::vector<char> SingleRange<int,SpaceType::PSPACE>::data() const
{ {
DataHeader h; DataHeader h = dataHeader();
h.spaceType = static_cast<int>( SpaceType::PSPACE );
h.metaSize = sizeof(size_t);
h.multiple = 0;
std::vector<char> out; std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
@ -79,6 +76,15 @@ namespace MultiArrayTools
return out; 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 typename SingleRange<int,SpaceType::PSPACE>::IndexType SingleRange<int,SpaceType::PSPACE>::begin() const
{ {
SingleIndex<int,SpaceType::PSPACE> i( std::dynamic_pointer_cast<SingleRange<int,SpaceType::PSPACE> > SingleIndex<int,SpaceType::PSPACE> i( std::dynamic_pointer_cast<SingleRange<int,SpaceType::PSPACE> >

View file

@ -63,10 +63,7 @@ namespace MultiArrayTools
std::vector<char> SingleRange<size_t,SpaceType::SPIN>::data() const std::vector<char> SingleRange<size_t,SpaceType::SPIN>::data() const
{ {
DataHeader h; DataHeader h = dataHeader();
h.spaceType = static_cast<int>( SpaceType::SPIN );
h.metaSize = 0;
h.multiple = 0;
std::vector<char> out; std::vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
@ -74,6 +71,15 @@ namespace MultiArrayTools
return out; 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 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> > SingleIndex<size_t,SpaceType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >