2018-10-29 14:19:42 +01:00
|
|
|
|
|
|
|
#ifndef __dynamic_meta_h__
|
|
|
|
#define __dynamic_meta_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <utility>
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
#include "allocator.h"
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-10-29 14:19:42 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
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>
|
2019-02-13 21:59:13 +01:00
|
|
|
static inline void set(const std::tuple<Us...>& in, vector<DynamicMetaElem>& meta)
|
2018-11-01 22:11:08 +01:00
|
|
|
{
|
|
|
|
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>
|
2019-02-13 21:59:13 +01:00
|
|
|
static inline void set(const std::tuple<Us...>& in, vector<DynamicMetaElem>& meta)
|
2018-11-01 22:11:08 +01:00
|
|
|
{
|
|
|
|
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:
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<DynamicMetaElem> mMeta;
|
2018-10-29 14:19:42 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // namespace CNORXZ
|
2018-10-29 14:19:42 +01:00
|
|
|
|
|
|
|
#endif
|