调用析构函数时,boost xml_iarchive崩溃

时间:2013-05-06 10:15:08

标签: xml boost boost-serialization boost-iostreams

我在试图找出这段代码的原因时遇到了一些麻烦 当函数返回0时会崩溃;

我怀疑当它从start函数返回时它会调用 xml_iarchive的析构函数,它在那里失败。

我必须先调用flush或某些函数来进行清理 xml_iarchive调用它的析构函数。

我不知道,:)

    // 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 
    }

1 个答案:

答案 0 :(得分:0)

原来这是包装的问题,我花了一整个 关于这个问题的一天