Sign in to follow this  
Tradone

C++ and serialization

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
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
Quote:
Original post by Tradone
thanks for the advice, I think I'm going to look for some free XML parsers first.


TinyXML is a great xml parser and it's extremely easy to use. It's also open source.

www.grinninglizard.com/tinyxml/

Share this post


Link to post
Share on other sites

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