container for primitive and structs added
This commit is contained in:
parent
0df6555d08
commit
3bee2457a6
|
@ -34,7 +34,6 @@ public:
|
|||
* singular types or has some form of encoding in a buffer present
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Struct Message
|
||||
*/
|
||||
|
@ -92,7 +91,7 @@ public:
|
|||
Reader(MessageType &msg) : message{msg} {}
|
||||
|
||||
Builder asBuilder() { return Builder{message}; }
|
||||
|
||||
|
||||
/*
|
||||
* Get member by index
|
||||
*/
|
||||
|
|
|
@ -45,4 +45,65 @@ public:
|
|||
|
||||
template <size_t i> Element<i> &get() { return std::get<i>(values); }
|
||||
};
|
||||
|
||||
/*
|
||||
* Helper for the basic message container, so the class doesn't have to be
|
||||
* specialized 10 times.
|
||||
*/
|
||||
template <class T> struct PrimitiveTypeHelper;
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::SignedIntegral, 1>> {
|
||||
using Type = int8_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::SignedIntegral, 2>> {
|
||||
using Type = int16_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::SignedIntegral, 4>> {
|
||||
using Type = int32_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::SignedIntegral, 8>> {
|
||||
using Type = int64_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::UnsignedIntegral, 1>> {
|
||||
using Type = uint8_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::UnsignedIntegral, 2>> {
|
||||
using Type = uint16_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::UnsignedIntegral, 4>> {
|
||||
using Type = uint32_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::UnsignedIntegral, 8>> {
|
||||
using Type = uint64_t;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::FloatingPoint, 4>> {
|
||||
using Type = float;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeHelper<schema::Primitive<schema::FloatingPoint, 8>> {
|
||||
using Type = double;
|
||||
};
|
||||
|
||||
template <class T, class N> class MessageContainer<schema::Primitive<T, N>> {
|
||||
public:
|
||||
using ValueType = PrimitiveTypeHelper<schema::Primitive<T, N>>::Type;
|
||||
|
||||
private:
|
||||
ValueType value;
|
||||
|
||||
public:
|
||||
MessageContainer() : value{0} {}
|
||||
|
||||
void set(const ValueType &v) { value = v; }
|
||||
|
||||
const T &get() { return value; }
|
||||
};
|
||||
} // namespace gin
|
||||
|
|
Loading…
Reference in New Issue