RADLib
RADical C++ application framework

RADSettings is the public settings library for application configuration. It stores key/value settings in JSON or INI files and layers typed accessors over RADCore::RADJsonValue.

RADSettings::Settings is the store. It can be constructed with an explicit fileName and RADSettings::Format (Json or Ini), or with a RADSettings::AppIdentity (organization and application), in which case it resolves a standard platform config path. fileName() and format() report the backing file, load() reads it (treating a missing file as empty), and save() writes it, creating parent directories as needed. The static Settings::defaultFileName() returns the resolved config path for an identity without constructing a store.

Key management uses contains(), remove(), and clear(). Values can be read and written generically through value() / setValue() with RADCore::RADJsonValue, or through the typed helpers: boolValue(), intValue(), doubleValue(), and stringValue() for reads, and setBool(), setInt(), setDouble(), and setString() for writes. Each typed getter takes a default that is returned when the key is absent.

Core features:

  • JSON and INI settings files.
  • App/organization based default config paths.
  • Typed getters and setters for common scalar values.
  • Compatibility with RADCore::RADJsonValue.

Example:

RADSettings::AppIdentity identity{"RadComp", "RADPxTool"};
std::string error;
settings.load(&error);
int width = settings.intValue("window/width", 1280);
bool firstRun = !settings.contains("initialized");
settings.setInt("window/width", width);
settings.setBool("initialized", true);
settings.setString("theme", "crimson");
if (!settings.save(&error)) {
RADLOG_ERROR("settings") << "save failed: " << error;
}
#define RADLOG_ERROR(category)
Logs with RADLogging at error level.
Definition: RADLogging.h:116
Typed application settings store.
Definition: RADSettings.h:35
@ Json
JSON object settings file.
Application identity used for standard settings paths.
Definition: RADSettings.h:27