ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::config Namespace Reference

Functions

void _init ()
 Load the file named by ASW_CONFIG, if it is set. Called by asw::core::init() before the window opens.
 
void _shutdown ()
 Remove all settings. Called by asw::core::shutdown().
 
bool load (const std::string &path)
 Load settings from a file. Settings already loaded stay, unless the file sets them again.
 
bool has (const std::string &key)
 Check if a setting is set.
 
std::optional< std::string > get_string (const std::string &key)
 Get a setting as text.
 
std::optional< bool > get_bool (const std::string &key)
 Get a setting as true or false. 1, true, yes and on are true. 0, false, no and off are false. Case does not matter.
 
std::optional< int > get_int (const std::string &key)
 Get a setting as a whole number.
 
std::optional< float > get_float (const std::string &key)
 Get a setting as a number.
 

Variables

constexpr const char * PATH_VARIABLE = "ASW_CONFIG"
 Name of the environment variable that holds the config file path.
 

Function Documentation

◆ _init()

void asw::config::_init ( )

Load the file named by ASW_CONFIG, if it is set. Called by asw::core::init() before the window opens.

Definition at line 65 of file config.cpp.

◆ _shutdown()

void asw::config::_shutdown ( )

Remove all settings. Called by asw::core::shutdown().

Definition at line 75 of file config.cpp.

◆ get_bool()

std::optional< bool > asw::config::get_bool ( const std::string & key)

Get a setting as true or false. 1, true, yes and on are true. 0, false, no and off are false. Case does not matter.

Parameters
keyThe setting.
Returns
The value, or nothing if it is not set or is not one of those.

Definition at line 108 of file config.cpp.

◆ get_float()

std::optional< float > asw::config::get_float ( const std::string & key)

Get a setting as a number.

Parameters
keyThe setting.
Returns
The value, or nothing if it is not set or is not a number.

Definition at line 145 of file config.cpp.

◆ get_int()

std::optional< int > asw::config::get_int ( const std::string & key)

Get a setting as a whole number.

Parameters
keyThe setting.
Returns
The value, or nothing if it is not set or is not a whole number.

Definition at line 127 of file config.cpp.

◆ get_string()

std::optional< std::string > asw::config::get_string ( const std::string & key)

Get a setting as text.

Parameters
keyThe setting.
Returns
The value, or nothing if it is not set.

Definition at line 99 of file config.cpp.

◆ has()

bool asw::config::has ( const std::string & key)

Check if a setting is set.

Parameters
keyThe setting, such as "display.fullscreen".
Returns
true if it is set.

Definition at line 94 of file config.cpp.

◆ load()

bool asw::config::load ( const std::string & path)

Load settings from a file. Settings already loaded stay, unless the file sets them again.

Each line is key = value. Blank lines and lines starting with # or ; are ignored. Keys are grouped with dots, such as display.fullscreen.

Parameters
pathThe file to load.
Returns
true if the file was read.

Definition at line 80 of file config.cpp.

Variable Documentation

◆ PATH_VARIABLE

const char* asw::config::PATH_VARIABLE = "ASW_CONFIG"
inlineconstexpr

Name of the environment variable that holds the config file path.

Definition at line 18 of file config.h.