2018-10-29 14:19:42 +01:00
|
|
|
|
|
|
|
#ifndef __dynamic_meta_h__
|
|
|
|
#define __dynamic_meta_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef std::pair<const char*,size_t> DynamicMetaElem;
|
2018-11-01 22:11:08 +01:00
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
struct DynamicMetaSetter
|
|
|
|
{
|
|
|
|
template <typename... Us>
|
|
|
|
static inline void set(const std::tuple<Us...>& in, std::vector<DynamicMetaElem>& meta)
|
|
|
|
{
|
|
|
|
typedef typename std::tuple_element<N,std::tuple<Us...>>::type elemtype;
|
|
|
|
meta[N].first = reinterpret_cast<const char*>( &std::get<N>(in) );
|
|
|
|
meta[N].second = sizeof(elemtype);
|
|
|
|
DynamicMetaSetter<N-1>::set(in,meta);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct DynamicMetaSetter<0>
|
|
|
|
{
|
|
|
|
template <typename... Us>
|
|
|
|
static inline void set(const std::tuple<Us...>& in, std::vector<DynamicMetaElem>& meta)
|
|
|
|
{
|
|
|
|
typedef typename std::tuple_element<0,std::tuple<Us...>>::type elemtype;
|
|
|
|
meta[0].first = reinterpret_cast<const char*>( &std::get<0>(in) );
|
|
|
|
meta[0].second = sizeof(elemtype);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
|
|
|
|
class DynamicMetaT
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::vector<DynamicMetaElem> mMeta;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DynamicMetaT() = default;
|
|
|
|
DynamicMetaT(const DynamicMetaT& in) = default;
|
|
|
|
DynamicMetaT(DynamicMetaT&& in) = default;
|
|
|
|
DynamicMetaT& operator=(const DynamicMetaT& in) = default;
|
|
|
|
DynamicMetaT& operator=(DynamicMetaT&& in) = default;
|
|
|
|
|
|
|
|
template <typename... Us>
|
2018-11-01 22:11:08 +01:00
|
|
|
DynamicMetaT(const std::tuple<Us...>* meta) : mMeta(sizeof...(Us))
|
2018-10-29 14:19:42 +01:00
|
|
|
{
|
2018-11-01 22:11:08 +01:00
|
|
|
DynamicMetaSetter<sizeof...(Us)-1>::set(*meta,mMeta);
|
2018-10-29 14:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const DynamicMetaT& in) const;
|
|
|
|
bool operator!=(const DynamicMetaT& in) const;
|
|
|
|
|
|
|
|
size_t size() const;
|
|
|
|
|
|
|
|
DynamicMetaElem& operator[](size_t pos);
|
|
|
|
const DynamicMetaElem& operator[](size_t pos) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace MultiArrayTools
|
|
|
|
|
|
|
|
#endif
|