2017-04-13 56 views
1

我正在使用boost::icl::interval_map來維護City的區間搜索樹,並且它的高溫和低溫。我想將interval_map序列化爲一個文件。在編譯期間boost xml序列化失敗

該代碼適用於文本和二進制序列化,但是xml序列化無法編譯。以下是錯誤我得到

[email protected]:~/workspace/CPPCodes/interval-tree/city# make 
g++ -o main -std=c++14 -g -ggdb -O0 main.cpp -lboost_serialization 
In file included from /usr/include/boost/mpl/aux_/na_assert.hpp:23:0, 
       from /usr/include/boost/mpl/arg.hpp:25, 
       from /usr/include/boost/mpl/placeholders.hpp:24, 
       from /usr/include/boost/archive/basic_binary_iprimitive.hpp:52, 
       from /usr/include/boost/archive/binary_iarchive_impl.hpp:21, 
       from /usr/include/boost/archive/binary_iarchive.hpp:20, 
       from main.cpp:4: 
/usr/include/boost/archive/basic_xml_oarchive.hpp: In instantiation of ‘void boost::archive::basic_xml_oarchive<Archive>::save_override(T&, int) [with T = const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_oarchive]’: 
/usr/include/boost/archive/detail/interface_oarchive.hpp:63:9: required from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_oarchive]’ 
main.cpp:186:8: required from here 
/usr/include/boost/archive/basic_xml_oarchive.hpp:99:9: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::serialization::is_wrapper<const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************)’ 
     BOOST_MPL_ASSERT((serialization::is_wrapper<T>)); 
     ^
/usr/include/boost/mpl/assert.hpp:83:5: note: candidate: template<bool C> int mpl_::assertion_failed(typename mpl_::assert<C>::type) 
int assertion_failed(typename assert<C>::type); 
    ^
/usr/include/boost/mpl/assert.hpp:83:5: note: template argument deduction/substitution failed: 
/usr/include/boost/archive/basic_xml_oarchive.hpp:99:9: note: cannot convert ‘mpl_::assert_arg<boost::serialization::is_wrapper<const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > > >(0u, 1)’ (type ‘mpl_::failed************ boost::serialization::is_wrapper<const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************’) to type ‘mpl_::assert<false>::type {aka mpl_::assert<false>}’ 
     BOOST_MPL_ASSERT((serialization::is_wrapper<T>)); 
     ^
/usr/include/boost/archive/basic_xml_iarchive.hpp: In instantiation of ‘void boost::archive::basic_xml_iarchive<Archive>::load_override(T&, int) [with T = boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_iarchive]’: 
/usr/include/boost/archive/xml_iarchive.hpp:103:51: required from ‘void boost::archive::xml_iarchive_impl<Archive>::load_override(T&, int) [with T = boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_iarchive]’ 
/usr/include/boost/archive/detail/interface_iarchive.hpp:60:9: required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_iarchive]’ 
main.cpp:194:8: required from here 
/usr/include/boost/archive/basic_xml_iarchive.hpp:76:9: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::serialization::is_wrapper<boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************)’ 
     BOOST_MPL_ASSERT((serialization::is_wrapper<T>)); 
     ^
/usr/include/boost/mpl/assert.hpp:83:5: note: candidate: template<bool C> int mpl_::assertion_failed(typename mpl_::assert<C>::type) 
int assertion_failed(typename assert<C>::type); 
    ^
/usr/include/boost/mpl/assert.hpp:83:5: note: template argument deduction/substitution failed: 
/usr/include/boost/archive/basic_xml_iarchive.hpp:76:9: note: cannot convert ‘mpl_::assert_arg<boost::serialization::is_wrapper<boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > > >(0u, 1)’ (type ‘mpl_::failed************ boost::serialization::is_wrapper<boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************’) to type ‘mpl_::assert<false>::type {aka mpl_::assert<false>}’ 
     BOOST_MPL_ASSERT((serialization::is_wrapper<T>)); 
     ^
Makefile:7: recipe for target 'main' failed 
make: *** [main] Error 1 

BOOST_MPL_ASSERT編譯

// Anything not an attribute and not a name-value pair is an 
// error and should be trapped here. 
template<class T> 
void save_override(T & t, BOOST_PFTO int) 
{ 
    // If your program fails to compile here, its most likely due to 
    // not specifying an nvp wrapper around the variable to 
    // be serialized. 
    BOOST_MPL_ASSERT((serialization::is_wrapper<T>)); 
    this->detail_common_oarchive::save_override(t, 0); 
} 

過程中失敗的意見建議,我不使用NVP來包裹被序列化的成員。但是,我認爲,我已經使用了所有成員變量的BOOST_SERIALIZATION_NVPboost::serialization::make_nvp。不知道發生了什麼事。

的代碼在這裏被推:https://github.com/prasad-joshi/CPPCodes/tree/xml_failure/interval-tree/city

+0

這是相當多的代碼來查看,你可以嘗試做一個更簡單的例子嗎? – jwimberley

+1

非常感謝您查看代碼。這裏是最小的示例代碼https://github.com/prasad-joshi/CPPCodes/blob/xml_failure/interval-tree/city/main.cpp。儘管如此,它仍然是116行代碼。我已經放棄了反序列化代碼,並使用std :: set代替boost flat_set。 爲了給你一些想法,Code維護一個城市低溫和高溫的區間樹。我想序列化區間樹。 –

回答

1

你的問題,部分是assertion_failed when using Boost Serialization with xml_oarchive重複,我想。通過將oa << tree更改爲oa << BOOST_SERIALIZATION_NVP(tree)來修正編譯錯誤。我得到的輸出檔案文件是有意義的:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<!DOCTYPE boost_serialization> 
<boost_serialization signature="serialization::archive" version="14"> 
<tree class_id="0" tracking_level="0" version="0"> 
    <sz>1</sz> 
    <INTERVAL class_id="1" tracking_level="0" version="0"> 
     <bb>2</bb> 
     <l>28</l> 
     <u>39</u> 
    </INTERVAL> 
    <SET class_id="2" tracking_level="0" version="0"> 
     <count>1</count> 
     <item_version>0</item_version> 
     <item class_id="3" tracking_level="0" version="0"> 
      <city_>cpur</city_> 
      <low_>28</low_> 
      <high_>39</high_> 
     </item> 
    </SET> 
</tree> 
+0

哦!是的,它的工作。非常感謝您的幫助和時間。 –