Serialization problem loading a vector of items
I am curious why loading a vector of items from an input stream fails
using one method but works using a slightly different method.
Given a load method:
template <class T>
T* load(std::istream& in) {
boost::archive::xml_iarchive ia(in);
T* t;
ia & BOOST_SERIALIZATION_NVP(t);
return t;
}
and use of it:
vector<item>* v = load
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
Bill Lear wrote:
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 havn't responded because I didn't have a ready answer and I havn't been able to find the time required to respond with a worthy answer. I am interested and I will look in to it. Robert Ramey
participants (2)
-
Bill Lear
-
Robert Ramey