#include <OptionsFile.h>
Public Types | |
enum class | ReadFlags |
using | ModuleNameToFileVersionMapperType = function< optional< Common::Version >(const String &moduleName)> |
using | ModuleDataUpgraderType = function< VariantValue(const optional< Common::Version > &version, const VariantValue &rawVariantValue)> |
Public Member Functions | |
nonvirtual BLOB | ReadRaw () const |
nonvirtual void | WriteRaw (const BLOB &blob) |
template<typename T > | |
nonvirtual optional< T > | Read () |
template<typename T > | |
nonvirtual void | Write (const T &optionsObject) |
Static Public Attributes | |
static const LoggerType | kDefaultLogger |
static const ModuleDataUpgraderType | kDefaultUpgrader |
static const Variant::Reader | kDefaultReader = Variant::JSON::Reader{} |
static const Variant::Writer | kDefaultWriter = Variant::JSON::Writer{} |
Simple wrapper on ObjectVariantMapper code, and code to serialize to/from JSON/XML etc, to wrap all this into an easy to use (but configurable/customizable) helper to serialize configuration data between disk and module-specific C++ objects.
This is SOMEWHAT flexible and customizable, but not so much. Its mostly intended to be a one-size-fits all utility that will often be useful, and will save some typing. If it does fit your needs, don't use it, and use ObjectVariantMapper and the reader abstractions directly.
Definition at line 79 of file OptionsFile.h.
using Stroika::Foundation::DataExchange::OptionsFile::ModuleNameToFileVersionMapperType = function<optional<Common::Version> (const String& moduleName)> |
Optionally provide (based on filenames/locations) information about the incoming file(read file) version.
Definition at line 112 of file OptionsFile.h.
using Stroika::Foundation::DataExchange::OptionsFile::ModuleDataUpgraderType = function<VariantValue (const optional<Common::Version>& version, const VariantValue& rawVariantValue)> |
This function gets a crack at revising the form (in variant/tree form) of the data to accomodate a version change. The version may not be known, in which case the function is still called, but with the verison information missing.
Definition at line 125 of file OptionsFile.h.
|
strong |
Just a parameter to Read() function.
Definition at line 178 of file OptionsFile.h.
BLOB OptionsFile::ReadRaw | ( | ) | const |
Read the content of the associated file as a BLOB.
Definition at line 183 of file OptionsFile.cpp.
void OptionsFile::WriteRaw | ( | const BLOB & | blob | ) |
Writes the given blob to the associated file, if it represents a change. This will silently avoid writing, if the blob is already the same as what is on disk.
Definition at line 189 of file OptionsFile.cpp.
nonvirtual optional< T > Stroika::Foundation::DataExchange::OptionsFile::Read | ( | ) |
Read () reads in the data from the associated options file, and returns it as a struct you've defined.
The mapping to/from external format is defined by OptionsFile constructor parameters.
The predefined (template specialization) of Read<VariantValue> doesn't use ObjectVariantMapper: it does the raw read (just using the Reader object).
Note also that Read<VariantValue> does use any provided ModuleDataUpgrader, so that the data is upgraded before its seen by the object variant mapper.
Read () will emit warnings, and maps to 'isMissing' or default value (depending on overload) if read data is corrupted. To avoid this behavior, use ReadRaw() directly.
nonvirtual void Stroika::Foundation::DataExchange::OptionsFile::Write | ( | const T & | optionsObject | ) |
Note - predefined version Write<VariantValue> doesn't use ObjectVariantMapper.
Write () serializes T, and then invokes WriteRaw ().
|
static |
Definition at line 95 of file OptionsFile.h.
|
static |
kDefaultUpgrader does nothing (no-op)
Definition at line 131 of file OptionsFile.h.
|
static |
Format serializer
Definition at line 137 of file OptionsFile.h.
|
static |
Format serializer
Definition at line 143 of file OptionsFile.h.