Archived

This topic is now archived and is closed to further replies.

jonboym

Serialization & STL

Recommended Posts

jonboym    122
Hi, Right I''m getting a little confused with saving my data objects to file. I''m new to STL and basically trying to replicate MFC style (or better!) serialization. Firstly I have a class which contains all the main actors for my game in STL vectors (actually the vectors contain pointers to the actors as they are created on the heap). I want to know how to serialize them using C++ streams & STL. BUT some of the classes contained in the vectors need pointers to other objects of different class in different vector containers and some have static data members (so only need serializing once). Advice? Jon

Share this post


Link to post
Share on other sites
Sneftel    1788
IIRC, Boost has some libraries related to serialization.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Kylotan    9860
I don''t see anything in Boost, but maybe I missed it.

There''s no simple solution - you have to explicitly write input and output functionality for each class, writing each separate data member out to the file. Writing out the classname or a magic number first helps catch loading errors, but you don''t get around needing to do it all by hand really. The key is to write generic functions that read and write as many different types as possible or at least share code, and make good use of your object hierarchy so that you don''t have to implement much more when you derive a new class.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites