It's probably obvious that I'm more familiar with Python than C++...
I was wondering if there's a convenient way of storing objects / miscellaneous STL structures on the hard drive for later importing and use in C++ in the same manner that Python does with the Pickle module.
I know I can write a raw dump, but I'd rather avoid that. I'm also working with some god-awfully huge files, so some compression would also be a bonus.

A bit of Googling led to the conclusion that I don't know how to word this question in a way that a search engine can understand.

Thanks in advance!

8 Years
Discussion Span
Last Post by rts1

I help maintain a C++ library called the PicklingTools: http://www.picklingtools.com. One of its main goals is to allow C++ users to pickle data so that Python can read it.

The library gives you data structures that "look like" Python from C++, and then allows you to pickle/unpickle those. All (?) the basic types are provided: int, float, long int, string, None, dict, list, ordered dict, tuple. There are some hooks to use user-defined types, but those are a bit immature at the moment.

Here's a simple C++ example:

#include "chooseser.h"

int main()
// Here's a complicated Python-esque dictionary
Val v = Tab("{ 'a':1, 'b':[1, 2.2, 'three'], 'c':None }");
cout << v["a"] << endl; // prints 1

// Write the dictionary to Disk AS A PICKLE
DumpValToFile(v, "example.p0", SERIALIZE_P0); // can also be SERIALIZE_P2

// From Python, you can pickle.load(file('example.p0'))

// Read it back in
Val result;
LoadValFromFile("example.p0", result; SERIALIZE_P0);
cout << result << endl; // print

The library has been around for a while (8 years?) and is active.
There is also a User's Guide and FAQ in html and pdf and text in the documentation

Hope you find this useful.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.