coastline 0.0.4
Loading...
Searching...
No Matches
coastline::GameConfig Class Reference

The settings of BossRally.ini. More...

#include <config.h>

Public Member Functions

bool Save (const std::filesystem::path &path) const
 Atomically replace path under a process lock.
std::optional< std::string > Get (std::string_view section, std::string_view key) const
long GetInteger (std::string_view section, std::string_view key, long fallback) const
int GetIndex (std::string_view section, std::string_view key, std::size_t count, int fallback) const
float GetFloat (std::string_view section, std::string_view key, float fallback) const
bool GetBoolean (std::string_view section, std::string_view key, bool fallback) const
void Set (std::string_view section, std::string_view key, std::string value)
 Store a value, replacing any value of the same key.

Static Public Member Functions

static GameConfig Load (const std::filesystem::path &path)
 Read path.
static GameConfig Parse (std::string_view text)
 Parse INI section headers, Key=Value lines, and comments that start with ; or #.

Detailed Description

The settings of BossRally.ini.

The PC release writes the sections Video and Game, and the SDL game adds keys to the same sections. Section and key names compare without case, as the Windows profile routines compare them.

Member Function Documentation

◆ Load()

GameConfig coastline::GameConfig::Load ( const std::filesystem::path & path)
static

Read path.

A missing, unreadable, or malformed file gives an empty configuration. Invalid numeric display and audio settings are removed to restore their defaults.

Parameters
pathThe INI file.
Returns
The settings the file has.

◆ Parse()

GameConfig coastline::GameConfig::Parse ( std::string_view text)
static

Parse INI section headers, Key=Value lines, and comments that start with ; or #.

Parameters
textThe text of the file.
Returns
The settings the text has.

◆ Save()

bool coastline::GameConfig::Save ( const std::filesystem::path & path) const

Atomically replace path under a process lock.

Failures before replacement preserve existing data.

Parameters
pathThe INI file.
Returns
Whether writing, replacement, and synchronisation succeed.

◆ Get()

std::optional< std::string > coastline::GameConfig::Get ( std::string_view section,
std::string_view key ) const
Parameters
sectionThe section name.
keyThe key name.
Returns
The value, or nothing when the key is absent.

◆ GetInteger()

long coastline::GameConfig::GetInteger ( std::string_view section,
std::string_view key,
long fallback ) const
Parameters
sectionThe section name.
keyThe key name.
fallbackThe value for an absent or malformed key.
Returns
The value as an integer.

◆ GetIndex()

int coastline::GameConfig::GetIndex ( std::string_view section,
std::string_view key,
std::size_t count,
int fallback ) const
Parameters
sectionThe section name.
keyThe key name.
countThe number of choices.
fallbackThe value for an absent or malformed key, or a value outside the choices.
Returns
A choice index from 0 to count - 1, or fallback for invalid input.

◆ GetFloat()

float coastline::GameConfig::GetFloat ( std::string_view section,
std::string_view key,
float fallback ) const
Parameters
sectionThe section name.
keyThe key name.
fallbackThe value for an absent or malformed key.
Returns
The finite parsed number, or fallback for invalid or non-finite input.

◆ GetBoolean()

bool coastline::GameConfig::GetBoolean ( std::string_view section,
std::string_view key,
bool fallback ) const
Parameters
sectionThe section name.
keyThe key name.
fallbackThe value for an absent or malformed key.
Returns
Whether the value is a non-zero integer, true, yes, or on, ignoring case.

◆ Set()

void coastline::GameConfig::Set ( std::string_view section,
std::string_view key,
std::string value )

Store a value, replacing any value of the same key.

Parameters
sectionThe section name.
keyThe key name.
valueThe new value.

The documentation for this class was generated from the following file: