Persist is a C++ library that serializes data to and from streams in XML, JSON, and binary formats.
Features:
- Enumeration conversion between values and text.
- Bitmask conversion between values and text.
- Absolute and relative path conversions.
- Polymorphism.
- Multiple and possibly cyclical references to objects.
- Containers
vector
,list
,set
,multiset
,map
,multimap
. - Smart pointers
unique_ptr
,shared_ptr
,weak_ptr
. - Versioned backwards compatibility.
- UTF-8 encoded XML archives.
- JSON archives.
- Binary archives.
Anti features:
- Multiple inheritance is not supported.
The main difference between Boost Serialization and Persist is the way that they handle shared data. Boost Serialization automatically tracks pointers to shared data and writes out objects by value the first time they are encountered and then by reference for any further occurences. Persist allows the application to specify when an object is written out by reference and when it is written out by value. This is a deliberate design decision to simplify the implementation and to allow control of where data shows up in an archive - in my opinion this makes them easier to transform using XSLT and easier to read. The cost of doing it this way is that the application is then responsible for making sure that all referenced objects are written to an archive and that objects aren't written out by value more than once.
Persist supports conversion of enumerations and bit masks to useful text values for text based archives. Persist also supports the conversion of paths - converting absolute paths to relative paths when persisted in an archive and back to absolute paths when the archive is read back in.
Boost Serialization handles multiple inheritance, classes that contain reference member variables, works without RTTI, is far more portable, supports std::optional
and std::variant
, and has been reviewed and tested extensively by the Boost community.
In summary Boost Serialization is better if you don't need control over where your data appears when written to XML or JSON archives, you don't need your enumerations and bit masks converted to text, you don't need relative paths in your archives, or you don't want the responsibility of determining whether to write an object by value or by reference.
Build Persist using Forge and a C++ compiler (XCode, Visual C++, GCC, or Clang depending on operating system).
Linux:
From a Bash shell with GCC and Forge installed and available in the path:
git clone git@github.com:cwbaker/persist.git persist
cd persist
git submodule update --init
forge variant=release
./release/bin/persist_examples
macOS:
From a Bash shell with XCode and Forge installed and available in the path:
git clone git@github.com:cwbaker/persist.git persist
cd persist
git submodule update --init
forge variant=release
./release/bin/persist_examples
Windows:
From a Visual C++ x64 Native Tools command prompt with Forge installed and available in the path:
git clone git@github.com:cwbaker/persist.git persist
cd persist
git submodule update --init
forge variant=release
.\release\bin\persist_examples.exe
Linking with external code will require you to add the top level directory (e.g. "...\persist
") and the per-variant library directory (e.g. "...\perist\release\lib
") to your compiler's header and library search paths respectively.