用typedef定义的原生型的系列化提振包含结构内 [英] boost serialization of native type defined with typedef contained within struct
问题描述
我有一个包含各种类型和枚举一个MyFile.hpp头文件。我该怎么办给出的例子code的序列化/ desrialization。
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
//MyFile.hpp
namespace A {
namespace B {
typedef std::string MyString;
typedef std::map<std::string,std::string> my_type;
typedef bool result;
struct MyTimer
{
int time;
private :
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & time;
}
};
enum MODE
{
Sleep=1,
HybridSleep,
Hybernate
}
}
}
我需要做实施相应MYFILE.CPP但不知道该怎么办,我去前进。
I need to do implementation in corresponding MyFile.cpp but don't know how do i go ahead.
谢谢,
推荐答案
地图,字符串等可以直接通过包括相关的头连载:
Maps, strings etc. can just be serialized by including the relevant header:
#include <boost/serialization/map.hpp>
#include <boost/serialization/string.hpp>
一个类型T是可序列化,当且仅当以下条件之一为真:
A type T is Serializable if and only if one of the following is true:
-
这是一个基本类型。
it is a primitive type.
这是基本类型,我们指的是C ++内置类型,只有C ++内置类型。 算术(包括字符),布尔,枚举的基本类型即可。下面系列化特征,我们定义为不同的目的不同的方式原始的执行层面。这可能是混乱的来源。
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.
- 类成员函数连载
- 全局函数序列化
有关更棘手的情况下,有 BOOST_STRONG_TYPEDEF
(见的文件的序列化包装)
For more tricky cases there is BOOST_STRONG_TYPEDEF
(see documentation "Serialization Wrappers")
这篇关于用typedef定义的原生型的系列化提振包含结构内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!