boost serialization of native type defined with typedef contained within struct

前端 未结 1 1178
旧时难觅i
旧时难觅i 2020-12-12 07:14

I have a MyFile.hpp header file which contains various types and enums. How do i do serialization/ desrialization of given example code.

//MyFile.hpp



        
相关标签:
1条回答
  • 2020-12-12 07:25

    Maps, strings etc. can just be serialized by including the relevant header:

    #include <boost/serialization/map.hpp>
    #include <boost/serialization/string.hpp>
    

    The enum counts as a primitive type:

    A type T is Serializable if and only if one of the following is true:

    • it is a primitive type.

      By primitive type we mean a C++ built-in type and ONLY a C++ built-in type. Arithmetic (including characters), bool, enum are primitive types. Below in serialization traits, we define a "primitive" implementation level in a different way for a different purpose. This can be a source of confusion.

    • It is a class type and one of the following has been declared according to the prototypes detailed below:
      • a class member function serialize
      • a global function serialize
    • it is a pointer to a Serializable type.
    • it is a reference to a Serializable type.
    • it is a native C++ Array of Serializable type.

    For more tricky cases there is BOOST_STRONG_TYPEDEF (see documentation "Serialization Wrappers")

    0 讨论(0)
提交回复
热议问题