RE: [Boost-users] Serialization problem loading a vector of items
I seem to remember being told that std::string was not meant to be inherited from, could it be the same in your case? -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Bill Lear Sent: 24 January 2005 13:43 To: boost-users@lists.boost.org Subject: Re: [Boost-users] Serialization problem loading a vector of items On Friday, January 21, 2005 at 12:29:37 (-0600) Bill Lear writes:
I am curious why loading a vector of items from an input stream fails using one method but works using a slightly different method. ...
I have not seen a response to this post. Along similar lines, I am having problems with sub-classing the std::vector class. I've tried multiple ways, but can't get it to load (de-serialize) properly. I've used private inheritance (my first choice), public inheritance. Neither work. Here is my attempt at public inheritance: template <class T> class RingBuffer: public std::vector<T> { public: RingBuffer() : _first_ind(0), _last_ind(0) { } double first() { return (*this)[_first_ind]; } double last() { return (*this)[_last_ind]; } void add(T v) { _last_ind = (_last_ind + 1) % size(); (*this)[_last_ind] = v; if (_last_ind == _first_ind) { _first_ind = (_first_ind + 1) % size(); } } private: int _first_ind; int _last_ind; friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int) { ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(std::vector<T>) & BOOST_SERIALIZATION_NVP(_first_ind) & BOOST_SERIALIZATION_NVP(_last_ind); } }; As before, I can save this to a stream, but cannot get it to load from a stream. I am using boost 1.32, with gcc 3.2. Bill _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Monday, January 24, 2005 at 15:30:06 (+0000) Foster, Gareth writes:
I seem to remember being told that std::string was not meant to be inherited from, could it be the same in your case?
I don't think so. The inheritance is not the problem. The code works fine, as expected, except for the serialization (1/2 of it works, the other half does not). Bill
How does it fail? Does it fail to compile? Does it give an exception? If so which one. If it fails with text or binary archive, does it also fail on xml archives? that would be useful information. Robert Ramey Bill Lear wrote:
On Monday, January 24, 2005 at 15:30:06 (+0000) Foster, Gareth writes:
I seem to remember being told that std::string was not meant to be inherited from, could it be the same in your case?
I don't think so. The inheritance is not the problem. The code works fine, as expected, except for the serialization (1/2 of it works, the other half does not).
Bill
On Monday, January 24, 2005 at 08:54:23 (-0800) Robert Ramey writes:
How does it fail? Does it fail to compile? Does it give an exception? If so which one. If it fails with text or binary archive, does it also fail on xml archives? that would be useful information.
I'll try to get together a complete test case by this evening. Bill
On Monday, January 24, 2005 at 13:07:41 (-0600) Bill Lear writes:
On Monday, January 24, 2005 at 08:54:23 (-0800) Robert Ramey writes:
How does it fail? Does it fail to compile? Does it give an exception? If so which one. If it fails with text or binary archive, does it also fail on xml archives? that would be useful information.
I'll try to get together a complete test case by this evening.
Below is test code that shows the problem. It is working with text
and failing with XML serialization --- perhaps I'm simply not
understanding something else that I need to do, though we are using
XML serialization extensively.
The text serialization produces this as output:
22 serialization::archive 3 0 0 10 0 0 0 0 0 0 0 0 0 0 0 9
The XML serialization produces this as output:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
Bill Lear wrote:
Below is test code that shows the problem. It is working with text and failing with XML serialization --- perhaps I'm simply not understanding something else that I need to do,
Anything that works for text must work for xml (assuming NVP is used correctly) so by definition you've found a bug. I will look into this - it shouldn't be too difficult.
though we are using XML serialization extensively
You must be, this is the third bug you've found in the system. And this is in spite of having run 200 tests with 5 or six different compilers! One thing I notice rigth off the bat. I believe there is a bug in the 1.32 version that will be fixed in the next version regarding the usage of < and
characters in NVP names. That is :
BOOST_SERIALIZATION_BASE_OBJECT_NVP(std::vector<T>) in your case. try changing the name to remove the < and > characters and see if that helps. try: ar & boost::serialization::make_nvp("vectorT", boost::serialization::base_object<name >(*this)); Robert Ramey
On Monday, January 24, 2005 at 15:46:47 (-0800) Robert Ramey writes:
... in your case. try changing the name to remove the < and > characters and see if that helps. try:
ar & boost::serialization::make_nvp("vectorT", boost::serialization::base_object<name >(*this));
Works indeed. For those who may be following this, I tried the
following, verbatim:
ar & boost::serialization::make_nvp("vectorT",
boost::serialization::base_object
participants (3)
-
Bill Lear
-
Foster, Gareth
-
Robert Ramey