Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-02-08 11:39:38


try something like the following:

#include <fstream>
#include <boost/serialization/binary_object.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

class _IplImage {
public:
    friend boost::serialization::access;
    int roi, width, height, depth, nChannels;
    int imageSize;
    int * imageData;
    template<class Archive>
    void save(Archive & ar, const unsigned int version) const {
        ar << roi << width << height << depth << nChannels;
        ar << imageSize;
        ar << boost::serialization::binary_object(imageData, imageSize);
    }
    template<class Archive>
    void load(Archive & ar, const unsigned int version){
        ar >> roi >> width >> height >> depth >> nChannels;
        ar >> imageSize;
        ar >> boost::serialization::binary_object(imageData, imageSize);
    }
    BOOST_SERIALIZATION_SPLIT_MEMBER()
};

main(int argc, char *argv[]){
    const _IplImage i;
    {
        std::ofstream os("test");
        boost::archive::text_oarchive oa(os);
        oa << i;
    }
    _IplImage new_i;
    {
        std::ifstream is("test");
        boost::archive::text_iarchive ia(is);
        ia >> new_i;
    }
    // compare the new and old images
}

This compiles w/o issue on my system.

Robert Ramey


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