本文介绍了用typedef定义的原生型的系列化提振包含结构内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含各种类型和枚举一个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>
枚举)
For more tricky cases there is BOOST_STRONG_TYPEDEF
(see documentation "Serialization Wrappers")
这篇关于用typedef定义的原生型的系列化提振包含结构内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!