cpp*_*nda 5 xml serialization boost
我只是找不到从boost xmlarchives中删除版本跟踪的方法.
例
<Settings class_id="0" tracking_level="0" version="1">
<px class_id="1" tracking_level="1" version="0" object_id="_0">
<TestInt>3</TestInt>
<Resolution class_id="2" tracking_level="0" version="0">
<x>800</x>
<y>600</y>
</Resolution>
<SomeStuff>0</SomeStuff>
</px>
</Settings>
Run Code Online (Sandbox Code Playgroud)
我想得到class_id ="0"tracking_level ="0"version ="1"的东西,因为在这种情况下我只是不需要它并想要一个像文件一样的简单干净配置
码
void serialize(Archive & ar, const unsigned int version)
{
ar & make_nvp("TestInt", TestInt);
ar & make_nvp("Resolution", resolution);
ar & make_nvp("SomeStuff", SomeStuff);
}
Run Code Online (Sandbox Code Playgroud)
我发现了boost :: serialization :: track_never,但无处可用
对于原始海报来说太迟了,我想分享我发现的东西
BOOST_CLASS_IMPLEMENTATION(My_class, object_serializable)
Run Code Online (Sandbox Code Playgroud)
诀窍.
尝试使用“ no_header”选项创建iarchive:
boost::archive::xml_iarchive ia(is, boost::archive::no_header);
Run Code Online (Sandbox Code Playgroud)
小智 5
要删除可以使用的xml存档文件的标头
boost::archive::xml_iarchive ia(is, boost::archive::no_header);
Run Code Online (Sandbox Code Playgroud)
要禁用显示属性class_id,tracking_level和版本,您必须使用
BOOST_CLASS_IMPLEMENTATION( <type>, boost::serialization::object_serializable )
BOOST_CLASS_TRACKING( <type>, boost::serialization::track_never )
Run Code Online (Sandbox Code Playgroud)
对于每种类型.需要按此顺序调用这些宏.NB你不能使用
BOOST_CLASS_VERSION
Run Code Online (Sandbox Code Playgroud)
用上面描述的宏.