Boost logo

Boost :

Subject: Re: [boost] [serialization] "stream error" when port fromboost_1.33 toboost_1.36
From: Robert Ramey (ramey_at_[hidden])
Date: 2008-09-26 00:16:16


One odd thing to me is the usage of std::ios::binary which will handle cr/lf
as two
characters rather than one.

ipangth wrote:
>> What are the anomolies?
>> I debug the xml file with VC8, and the ifstream test retturn
>> "failbit".
>> See the xml file attached behind, i dont know how to find the
>> "failbit".
>> And some one can see the attach xml to help me?
>>
>> template<class CharType>
>> bool basic_xml_grammar<CharType>::my_parse(
>> BOOST_DEDUCED_TYPENAME basic_xml_grammar<CharType>::IStream & is,
>> const rule_t & rule_,
>> CharType delimiter
>> ){
>> if(is.fail()){ ////here return false, the stream state is
>> "failbit" boost::throw_exception(
>> archive_exception(archive_exception::stream_error)
>> );
>> }
>>
>> 2008/9/26 Robert Ramey <ramey_at_[hidden]>:
>>> 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
>>>
>>>
>>>
>>> _______________________________________________
>>> Unsubscribe & other changes:
>>> http://lists.boost.org/mailman/listinfo.cgi/boost
>>>
>>
>>
>>
>> --
>> 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