|
CoriEngine
|
Saves and loads aggregate structs to/from drive. More...
#include <BinaryFileManager.hpp>
Static Public Member Functions | |
| template<typename T> requires std::is_aggregate_v<T> | |
| static void | SaveAggregateStruct (const T &data, const std::filesystem::path &file, const bool safeMode=false) |
| Saves an instance of an aggregate struct onto the disk. | |
| template<typename T> requires std::is_aggregate_v<T> | |
| static std::expected< T, Core::CoriError<> > | LoadAggregateStruct (const std::filesystem::path &file, const bool backupFallback=false) |
| Loads an aggregate struct from the file on the disk. | |
Saves and loads aggregate structs to/from drive.
You can load or save aggregate struct that contain trivial types or std::vector of any type.
It has some safety mechanisms to prevent file corruption or detect it afterward, also it will not allow you to load the data that came from one aggregate struct type into another.
1: When you create the file it generates 1 128bit UUID and writes it to the header and to the footer of the file, if during reading these UUIDs in footer and header mismatch, it means that the file is corrupted, it will try to look for a backup (.bak file), if it exists it will load it.
2: During compile time an aggregate struct UID is generated for every specialization of SaveAggregateStruct method, this aggregate struct UID is saved in the header of the file, later when loading it checks if this saved aggregate struct UID is the same as of the struct type you're trying to load the data in, if it detects missmatch, it will not load the data into that struct and instead look for a backup file.
3: When saving a file it calculates a checksum of the data, when loading the file it checks the saved checksum in the header to the checksum calculated from the read data, if it detects a mismatch it will look for a backup.
4: When a file is saved it saves total data size in the header, when reading the file it compares this saved value to the actual size of read data, if it detects a mismatch it will look for a backup.
Definition at line 33 of file BinaryFileManager.hpp.
|
inlinestatic |
Loads an aggregate struct from the file on the disk.
| T | Aggregate struct type to load into. Should be the same type you provided in SaveAggregateStruct when saving it. |
| file | File to read from. |
| backupFallback | Whether to look for a backup, or no. |
Definition at line 111 of file BinaryFileManager.hpp.

|
inlinestatic |
Saves an instance of an aggregate struct onto the disk.
| T | Aggregate struct type to save. |
| data | Instance of the aggregate struct to save. |
| file | File to save to. |
| safeMode | Safe mode selector. When enabled it will create a backup after it writes the target file. |
Definition at line 43 of file BinaryFileManager.hpp.
