Boost logo

Boost Users :

From: Bryan Donlan (bdonlan_at_[hidden])
Date: 2006-05-30 15:44:44


Hi all,

I'm currently working on a game engine, and hoping to use boost
serialization for the world saving code. It's nearly perfect except
for one snag - serializing pointers to sprite file classes.

Ideally I'd like to simply serialize the name of the sprite file, and
on deserialization find the file in the sprite cache 'gallery', but
this requires using split serialization in all the classes that
reference sprites. Is there a way to simply override the serialization
of /pointers/ to classes?

I've tried the following:
typedef creaturesImage *p_img;

namespace boost {
    namespace serialization {
        template <class Archive>
        inline void save(Archive &ar, const p_img &obj, const int version) {
            bool isNull = (obj == NULL);
            ar & isNull;
            if (!isNull) {
                std::string name = obj->serializedName();
                ar & name;
            }
        }

        template <class Archive>
        inline void load(Archive &ar, p_img &obj, const int version) {
            bool isNull;
            ar & isNull;
            if (isNull)
                obj = NULL;
            else {
                std::string name;
                ar & name;
                obj = world.gallery.getImage(name);
            }
        }
    }
}

BOOST_SERIALIZATION_SPLIT_FREE(creaturesImage *);
BOOST_CLASS_IMPLEMENTATION(creaturesImage *,
boost::serialization::primitive_type);

However, this seems to be ignored; the compiler errors complain of
such things as
/usr/include/boost/serialization/access.hpp:109: error: 'class
creaturesImage' has no member named 'serialize'
(full log at http://pastebin.com/747527)

The code in question can be found at
http://ccdevnet.org/viewcvs.cgi/trunk/?rev=941 (ser/ subdirectory and
serialization.h particularly), or by subversion at
svn://ccdevnet.org/openc2e/trunk (rev 941 contains the code cited
here; build with make openc2e_s; dependency list at
http://openc2e.ccdevnet.org/download).

Thanks,

Bryan Donlan


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