serialize.hpp
Tools to save and load data from classes.
All of the important information about a class is stored in a DataPod, which can be used to restore the class at a later time.
Why is this better than other serialization techniques?
Only one line of code is added to a custom class to make it serializable.
Serialized objects do not need a default constructor (a DataPod constructor is added)
Serialized objects can be const since they get rebuilt during construction.
Synergistic interactions with other EMP classes, such as config and tuple_struct
In order to setup a target class to be able to be serialized into a pod, you must add a macro to include the needed functionality. For a basic class, use:
EMP_SETUP_DATAPOD(ClassName, var1, var2, …)
Where ClassName is the target class’ name and var1, var2, etc are the names of the member variables that also need to be stored. Note that member variables can be either built-in types or custom types that have also had DataPods setup in them.
If the target class is a derived class, you must use either:
EMP_SETUP_DATAPOD_D(ClassName, BassClassName, var1, var2, …)
-or-
EMP_SETUP_DATAPOD_D2(ClassName, BassClass1Name, BaseClass2Name, var1, var2, …)
…depending on how many base classes it was derived from (currently max 2).
Note also that this macro must either go in the public section of the target class definition, or the target class must be made a friend to the serialize::DataPod class.
- Todo:
Build custom load/store function for more STL objects (especially containers)
To deal with pointers we should recurse, but keep map to new pointer locations.
Setup a more robust method for dealing with arbitrary strings so we don’t have to worry about collisions in streams (JSon format??)
Setup a (compressed) binary save format in DataPods in addition to JSon.
Setup promised synergistic interactions with config and tuple_struct to auto store and load without any additional effort on the part of the library user.
Note
Status: ALPHA
-
namespace serialize
Functions
-
template<typename T>
auto StoreVar(DataPod &pod, const T &var, bool) -> typename T::emp_load_return_type& StoreVar() takes a DataPod and a variable and stores that variable to the pod. The third argument (bool vs. int) will receive a bool, and thus bool versions are preferred in the case of a tie. Specialized versions of this function can be included elsewhere, as needed, and should take a bool as the third argument.
-
template<typename T>