C++ and serialization

Started by
9 comments, last by klayAlloy 18 years, 1 month ago
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();
      }
   }

Advertisement
There is no built in C++ serialization...you have to write your own :(
Quote:Original post by SAE Superman
...you have to write your own :(
Or use the aforementioned boost library.
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.
C++ doesn't have any introspection capabilities, so writing an automatic serialization library would be difficult.
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++?
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.
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...
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<>.
thanks for the advice, I think I'm going to look for some free XML parsers first.

This topic is closed to new replies.

Advertisement