Sign in to follow this  

Using boost::serialization for custom files?

This topic is 4673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been reading the documentation on boost and I'm more convinced than ever that I should start using it. If serialization is as easy as it looks then I can't wait to get started. I was wondering if it's feasible to use boost's serialization to create a sort of custom file format.
class Map
{
  int w;
  int h;
  Map* nextMapOrSomething;

  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  {
     ar & w;
     ar & h;
     ar & nextMapOrSomething;
  }
};
Keep in mind, I'm asking this on a hobbyist level. I simply want to know if this idea will work because it'd ease my (solo) development so much! Thanks in advance. [Edited by - Rhaal on March 31, 2005 4:45:50 PM]

Share this post


Link to post
Share on other sites
don't know anything about boost::serialization, but do not try to serialize pointers. remember pointers can only point to addresses that are currently in memory, which will not be the same when you read the file in again.

Share this post


Link to post
Share on other sites
Quote:
Original post by graveyard filla
don't know anything about boost::serialization, but do not try to serialize pointers. remember pointers can only point to addresses that are currently in memory, which will not be the same when you read the file in again.

According to the docs, boost::serialization takes care about creating new instances when reading the pointer.

Share this post


Link to post
Share on other sites
Quote:
Original post by dalleboy
According to the docs, boost::serialization takes care about creating new instances when reading the pointer.


Hence, the reason I'm attracted to it [grin] However, I didn't phrase my question properly (or my example, rather). Obviously it'll work for what I showed because that's it's purpose. I meant a custom file format such as:


class MapStuff
{
std::list<SomeBitmapHandle> m_Tiles;
std::list<SomeWAVHandle> m_SFX;
// A lot more containers...

void serialize(Archive & ar, const unsigned int version)
{
ar & m_Tiles;
ar & m_SFX;
// Other containers...
}
};


It just seems too easy to be true and, if not, I wonder why I don't see it advised more.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rhaal
I wonder why I don't see it advised more.

Its still a new library (introduced in Boost 1.32, released November 19, 2004), and its userbase is still a bit low. Look at the Boost Mailing Lists, and you'll find lots of good tricks and tips for using Boost.

Share this post


Link to post
Share on other sites

This topic is 4673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this