SerialPod.hpp
Tools to save and load data from classes.
This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2023-2024 Michigan State University MIT Software license; see doc/LICENSE.md
The SerialPod object knows whether it is loading or saving and object, and provides a simple mechanism to do so.
=> How to use: A standard class can use a SerialPod by adding a Serialize(SerialPod & pod) member function.
An object of an independent class MyClass with a fixed interface can have a stand-alone Serialize function in the form of Serialize(SerialPod & pod, const MyClass & obj).
Any class can have a constructor that takes a SerialPod to allow reconstruction of const objects. As long as such a constructor is provided, the Serialize function can be const.
More complex classes (e.g., those that do memory management) will need to have separate SerialSave(SerialPod & pod) const and SerialLoad(SerialPod & pod) functions.
=> Example: Inside of MyClass we might have:
void MyClass(SerialPod & pod) { pod(member_a, member_b, member_c); // List all members to save/load }
=> Resolving duplications: If more than one version of a serialization function exists, functions external to the class always have precedence over those internal (so that classes can later be changed how they serialize).
If both a specific function (e.g., Load) and general function (i.e, Serialize) exist, the more specific one will always be used.
Regular streaming is used only when no other options exist.
Note
Status: ALPHA
Defines
-
INCLUDE_EMP_SERIALIZE_SERIAL_POD_HPP_GUARD
Functions
Variables
- template<typename OBJ_T> concept hasSerializeMember = requires(OBJ_T & value, SerialPod& pod) {{value.Serialize(pod) };}
Concept to identify id a type has a Serialize() member function.
- template<typename OBJ_T> concept hasSerialLoadMember = requires(OBJ_T & value, SerialPod& pod) {{value.SerialLoad(pod) };}
Concept to identify id a type has a SerialLoad() member function.
- template<typename OBJ_T> concept hasSerialSaveMember = requires(OBJ_T & value, SerialPod& pod) {{value.SerialSave(pod) };}
Concept to identify id a type has a SerialSave() member function.
- template<typename OBJ_T> concept hasSerializeOverload = requires(OBJ_T & value, SerialPod& pod) {{Serialize(pod, value) };}
Concept to identify id a type has a stand-alone Serialize() overload.
- template<typename OBJ_T> concept hasSerialLoadOverload = requires(OBJ_T & value, SerialPod& pod) {{SerialLoad(pod, value) };}
Concept to identify id a type has a stand-alone SerialLoad() overload.
- template<typename OBJ_T> concept hasSerialSaveOverload = requires(OBJ_T & value, SerialPod& pod) {{SerialSave(pod, value) };}
Concept to identify id a type has a stand-alone SerialSave() overload.
- template<typename OBJ_T> concept hasSerializeConstructor = requires(SerialPod& pod) {{ OBJ_T(pod) };}
Concept to identify id a type has a de-serialization constructor.