我在试图弄清楚为什么当函数返回 0 时这段代码会崩溃时遇到了一些麻烦;
我怀疑当它从 start 函数返回时,它会调用 xml_iarchive 的析构函数并且它在那里失败了。
在 xml_iarchive 调用其析构函数之前,我是否必须调用 flush 或某些函数来进行清理。
我不知道, :)
// serialize
class FileLayout
{
private:
std::string m_name;
int m_datetime;
std::string m_version;
std::string m_clientpath;
int m_length;
public:
FileLayout()
{
};
FileLayout(std::string name ,int datetime,
std::string version, std::string clientpath,
int length)
{
m_name = name;
m_datetime = datetime;
m_version = version;
m_clientpath = clientpath;
m_length = length;
};
// Allow serialization to access non-public data members.
friend class boost::serialization::access;
template<typename Archive>
void serialize(Archive& ar, const unsigned version)
{
ar & boost::serialization::make_nvp("Name", m_name);
ar & boost::serialization::make_nvp("DateTime", m_datetime);
ar & boost::serialization::make_nvp("Version", m_version);
ar & boost::serialization::make_nvp("ClientPath", m_clientpath);
ar & boost::serialization::make_nvp("Length", m_length);
}
// get
std::string name()
{
return m_name;
};
int datetime()
{
return m_datetime;
};
std::string version()
{
return m_version;
};
std::string clientpath()
{
return m_clientpath;
};
int length()
{
return m_length;
};
};
int Start(std::string &data) // xml
{
// set filesize
// set name
boost::iostreams::basic_array_source<char> device(data.c_str(), data.size());
boost::iostreams::stream<boost::iostreams::basic_array_source<char> > s(device);
boost::archive::xml_iarchive ia(s,boost::archive::no_header);
ia >> BOOST_SERIALIZATION_NVP(filelayout);
data.clear();
return 0; // fails here
}