Boost logo

Boost :

Subject: Re: [boost] [serialization] "stream error" when port from boost_1.33 toboost_1.36
From: Robert Ramey (ramey_at_[hidden])
Date: 2008-09-25 13:04:57


Take a look at the xml archive and see if there are any anomolies in it.

Robert Ramey

ipangth wrote:
>> I just port a project using boost_1.33_1 to use boost_1.36.
>> The project has a Server class using a std::set<Server>
>> serialization,
>> the serialization save and load functions code see behind.
>>
>> I use gcc 4.1 and run on FC6.
>> The porting problem is, when the old boost_1.33 generates(save) a
>> xml file, then use boost_1.36 load the xml throws an exception
>> "stream error"!
>>
>> the exception error code line : boost::archive::xml_iarchive ia(ifs);
>>
>> How can i sovle it?
>>
>>
>> class Server
>> {
>> public:
>> int id;
>> std::string ip;
>> int port;
>>
>> private:
>> static std::set<Server> lst_;
>>
>> static int dirty_;
>> };
>>
>> #endif
>>
>>
>>
>> #ifdef USE_SERVER_SERIALIZATION
>>
>> #ifndef _SERVER_SERIALIZATION_
>> #define _SERVER_SERIALIZATION_
>>
>> BOOST_CLASS_VERSION(Server, 1)
>> namespace boost {
>> namespace serialization {
>>
>> template <class archive>
>> void serialize(archive & ar, Server & t, const unsigned int
>> ver) {
>> ar & BOOST_SERIALIZATION_NVP(t.id);
>> ar & BOOST_SERIALIZATION_NVP(t.ip);
>> ar & BOOST_SERIALIZATION_NVP(t.port);
>> }
>>
>> }
>> }
>>
>> #endif
>>
>> #endif
>>
>> int Server::save( const std::string & file)
>> {
>> try {
>> std::ofstream ofs(file.c_str(), std::ios::binary);
>> {
>> boost::archive::xml_oarchive oa(ofs);
>> oa << BOOST_SERIALIZATION_NVP(lst_);
>> }
>> } catch(...) {
>> return ERROR_ERROR;
>> }
>>
>>
>>
>> return ERROR_SUCCEED;
>> }
>>
>>
>> int Server::load(const std::string & file)
>> {
>> std::set<Server> Server::lst_;
>> try
>> {
>> std::ifstream ifs(file.c_str(), std::ios::binary);
>>
>> {
>> boost::archive::xml_iarchive ia(ifs);
>> ia >> BOOST_SERIALIZATION_NVP(lst_);
>> }
>> }
>> catch(std::exception & e)
>> {
>> std::cout << e.what() << std::endl;
>> }
>>
>> return 0;
>> }
>>
>>
>>
>>
>> --
>> Best regards,
>> PangYongQiang
>>
>
>
>
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk