Jazz2::Utils::JsonFile class

Reads and writes JSON files that hold a single object.

Editor settings, shortcuts, rules of tile sets and level pack manifests are JSON objects, read whole into memory and written through AtomicFile, tab-indented so they can be edited by hand. The values read are still of any type, they're read through JsonAccess.

Public types

enum class ReadResult : std::uint8_t { Missing, Ok, Unreadable }
What reading a file found.

Public static functions

static auto Read(StringView path, Json::Value& value, std::int64_t maxSize, StringView what) -> ReadResult
Reads a file holding a JSON object.
static auto Parse(StringView text, Json::Value& value, std::string* errors = nullptr) -> bool
Reads JSON from text, returns false and why if it can't be read.
static auto ToString(const Json::Value& value, bool compact = false) -> std::string
Returns the text of a value, tab-indented, or with compact on a single line.
static auto Write(StringView path, const Json::Value& value, bool keepBackup = false) -> bool
Writes a value into a file through AtomicFile, tab-indented, the previous file is kept as .bak with keepBackup.
static auto Stage(StringView path, const Json::Value& value) -> bool
Writes a value only into the temporary file of path, see AtomicFile::Stage().

Constructors, destructors, conversion operators

JsonFile() deleted

Enum documentation

enum class Jazz2::Utils::JsonFile::ReadResult : std::uint8_t

What reading a file found.

Enumerators
Missing

There's no file, or it's empty

Ok

The file was read

Unreadable

There is a file but it can't be read or isn't a JSON object

Function documentation

static ReadResult Jazz2::Utils::JsonFile::Read(StringView path, Json::Value& value, std::int64_t maxSize, StringView what)

Reads a file holding a JSON object.

Parameters
path File to read
value Receives the object, an empty object unless the file was read
maxSize Largest file that is read, a larger one is ReadResult::Unreadable
what Names the file in the log, as "Editor settings"

Why a file that is there can't be read is logged.