Skip to content

Instantly share code, notes, and snippets.

@OXPHOS
Created July 19, 2016 03:39
Show Gist options
  • Save OXPHOS/80bc8fce462c377766dc05d15fbc9e9d to your computer and use it in GitHub Desktop.
Save OXPHOS/80bc8fce462c377766dc05d15fbc9e9d to your computer and use it in GitHub Desktop.
template<class Archive>
void cereal_save(Archive& ar) const
{
switch (m_datatype.e_containertype) {
case TYPE_SGVECTOR
case TYPE_INT_32:
ar(*(reinterpret_cast<int32_t*>(storage))); break;
case TYPE_FLOAT_64:
ar(*(reinterpret_cast<float64_t*>(storage))); break;
case TYPE_SGVECTOR_INT_32:
ar(*(reinterpret_cast<SGVector<int32_t>*>(storage))); break;
case TYPE_SGVECTOR_FLOAT_64:
ar(*(reinterpret_cast<SGVector<float64_t>*>(storage))); break;
case TYPE_UNDEFINED:
SG_SWARNING("Type error: undefined data type\n");
break;
}
}
namespace serialization
{
enum EnumContainerType
{
TYPE_UNDEFINED,
TYPE_PRIMITIVE,
TYPE_SGVECTOR,
TYPE_SGMATRIX
};
enum EnumPrimitiveType
{
TYPE_UNDEFINED,
TYPE_INT_32,
TYPE_FLOAT_64,
TYPE_SGVECTOR_INT_32,
TYPE_SGVECTOR_FLOAT_64
};
struct DataType
{
EnumContainerType e_containertype;
EnumPrimitiveType e_primitivetype;
template<T>
void set():
{
e_containertype = Type2Enum<T>.e_containertype);
e_primitivetype = Type2Enum<T>.e_primitivetype);
}
}
template<typename T>
struct Type2Enum
{
static constexpr EnumContainerType e_containertype = TYPE_UNDEFINED;
static constexpr EnumPrimitiveType e_primitivetype = TYPE_UNDEFINED;
};
template<>
struct Type2Enum<int32_t>
{
static constexpr EnumContainerType e_containertype = TYPE_PRIMITIVE;
static constexpr EnumPrimitiveType e_primitivetype = TYPE_INT_32;
};
template<>
struct Type2Enum<float64_t>
{
static constexpr EnumContainerType e_containertype = TYPE_PRIMITIVE;
static constexpr EnumPrimitiveType e_primitivetype = TYPE_FLOAT_64;
};
template<>
struct Type2Enum<SGVector<int32_t> >
{
static constexpr EnumContainerType e_containertype = TYPE_SGVECTOR;
static constexpr EnumPrimitiveType e_primitivetype = TYPE_INT_32;
};
template<>
struct Type2Enum<SGVector<float64_t> >
{
static constexpr EnumContainerType e_containertype = TYPE_SGVECTOR;
static constexpr EnumPrimitiveType e_primitivetype = TYPE_FLOAT_64;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment