Boost logo

Boost Users :

From: Bill Lear (rael_at_[hidden])
Date: 2005-01-24 08:43:01


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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net