Jump to content
  • Advertisement
Sign in to follow this  

C++ and serialization

This topic is 4451 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

For example, java has a serializing class as such. is there any serializing class in C++ that is part of the STL? I think there's on from the boost library, but is that the generic serializing class for c++? Thanks, links and other comments will be well appreciated.
import java.util.*;
import java.io.*;
public class SavePerson implements Serializable{
   public static void main(String args[]){
      Person person = new Person("Jack Jones");
      try{
         FileOutputStream fos = new FileOutputStream("Name.txt");
         ObjectOutputStream oos = new ObjectOutputStream(fos);
         System.out.print("Person's Name Written: ");
         System.out.println(person.getName());
         oos.writeObject(person);
         oos.flush();
         oos.close();
      }  catch(Exception e){
         e.printStackTrace();
      }
   }

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by SAE Superman
you have to write your own :(


Well not necessarily, third-party libraries exist most notably Boost.Serialization.

@Tradone:

Yes it is for C++ and boost is about as close to standardized library components as you can get.

Share this post


Link to post
Share on other sites
C++ doesn't have any introspection capabilities, so writing an automatic serialization library would be difficult.

Share this post


Link to post
Share on other sites
Quote:
Original post by SAE Superman
There is no built in C++ serialization...you have to write your own :(


Why do you guys quote me??? I think my answer satified the questions:

is there any serializing class in C++ that is part of the STL?
I think there's on from the boost library, but is that the generic serializing class for c++?

Share this post


Link to post
Share on other sites
Quote:
Original post by SAE Superman
Quote:
Original post by SAE Superman
There is no built in C++ serialization...you have to write your own :(


Why do you guys quote me??? I think my answer satified the questions:

is there any serializing class in C++ that is part of the STL?
I think there's on from the boost library, but is that the generic serializing class for c++?


Boost seems to be accepted as "next-to" the STL, and I think that some parts of boost are to be included in the STL in the future:

Quote:
Source: http://www.boost.org/
Ten Boost libraries are already included in the C++ Standards Committee's Library Technical Report ( TR1) as a step toward becoming part of a future C++ Standard. More Boost libraries are proposed for the upcoming TR2.


So given the lack of serialization in the STL, I would say that boost is the next best thing to "the generic serializing class for c++", if not the best.

Share this post


Link to post
Share on other sites
thanks, I think I got it.
so boost is the closest to the generic serialization library.

then how about tokenization and parsing?
any generic libraries or close to generic?

I know there's a tokenization class for boost.
but if there's anything built into c++ rather use a generic...

Share this post


Link to post
Share on other sites
Quote:
Original post by Tradone
then how about tokenization and parsing?
any generic libraries or close to generic?

I know there's a tokenization class for boost.
but if there's anything built into c++ rather use a generic...
There's nothing built in to C++ that offers everything that boost::tokenizer<> does. tokenizer<> is easy to use, so there's isn't much reason not to take advantage of it.

For more complex parsing there's spirit, but it can be non-trivial to use. I wrote a spirit-based parser for my engine, but switched back to my hand-rolled parser due to performance issues. This isn't spirit's fault, I don't think; I did some research online and there are a lot of things you can do to tweak spirit's performance. For me at least though I realized it would take more time to learn how to use spirit correctly than I had available. I'm not a pro though; a more experienced programmer might be able to integrate spirit much more easily. So that's another option.

There are also several free parsers for XML, it that's what you need. If your needs are simple though, try boost::tokenizer<>.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!