inLimbo
TUI Music Player that keeps you in Limbo.
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Loading...
Searching...
No Matches
toml_parser.hpp File Reference
#include "toml.hpp"
#include <cstdlib>
#include <filesystem>
#include <iostream>

Go to the source code of this file.

Macros

#define PARENT_LIB   "library"
 Macros for parent and field names used in the TOML configuration.
 
#define PARENT_LIB_FIELD_NAME   "name"
 
#define PARENT_LIB_FIELD_DIR   "directory"
 
#define PARENT_FTP   "ftp"
 
#define PARENT_FTP_FIELD_USER   "username"
 
#define PARENT_FTP_FIELD_SALT   "salt"
 
#define PARENT_FTP_FIELD_PWD_HASH   "password_hash"
 
#define PARENT_DBG   "debug"
 
#define PARENT_DBG_FIELD_TAGLIB_PARSER_LOG    "taglib_parser_log"
 
#define PARENT_DBG_FIELD_COLORS_PARSER_LOG   "colors_parser_log"
 
#define PARENT_DBG_FIELD_KEYBINDS_PARSER_LOG   "keybinds_parser_log"
 
#define PARENT_KEYBINDS   "keybinds"
 
#define SPECIAL_KEYBIND_ENTER_STR   "Enter"
 
#define SPECIAL_KEYBIND_TAB_STR   "Tab"
 
#define SPECIAL_KEYBIND_SPACE_STR   "Space"
 
#define PARENT_COLORS   "colors"
 
#define PARENT_UI   "ui"
 
#define CUSTOM_CONFIG_MACRO   "INLIMBO_CONFIG_HOME"
 

Functions

string getBaseConfigPath ()
 Retrieves the path to the configuration directory.
 
string getConfigPath (string fileName)
 Retrieves the full path to the configuration file.
 
string getCachePath ()
 
bool configFileExists (const string &filePath)
 Checks if the configuration file exists.
 
auto loadConfig ()
 Loads the configuration file.
 
auto parseTOMLField (string parent, string field) -> string_view
 Parses a string field from the TOML configuration.
 
auto parseTOMLFieldCustom (const toml::parse_result &custom_config, string parent, string field) -> string_view
 Parses a string field from a custom TOML configuration that is called by the INLIMBO_CONFIG_HOME macro at runtime.
 
auto parseTOMLFieldInt (string parent, string field) -> int64_t
 Parses an integer field from the TOML configuration.
 
auto parseTOMLFieldIntCustom (const toml::parse_result &custom_config, string parent, string field) -> int64_t
 Parses an integer field from a custom TOML configuration set by the INLIMBO_CONFIG_HOME macro at runtime.
 
auto parseTOMLFieldBool (const string &parent, const string &field) -> bool
 

Variables

auto config = loadConfig()
 

Macro Definition Documentation

◆ CUSTOM_CONFIG_MACRO

#define CUSTOM_CONFIG_MACRO   "INLIMBO_CONFIG_HOME"

Custom config.toml macro setup

◆ PARENT_COLORS

#define PARENT_COLORS   "colors"

Parent section for color settings

◆ PARENT_DBG

#define PARENT_DBG   "debug"

Parent section for debug settings

◆ PARENT_DBG_FIELD_COLORS_PARSER_LOG

#define PARENT_DBG_FIELD_COLORS_PARSER_LOG   "colors_parser_log"

◆ PARENT_DBG_FIELD_KEYBINDS_PARSER_LOG

#define PARENT_DBG_FIELD_KEYBINDS_PARSER_LOG   "keybinds_parser_log"

◆ PARENT_DBG_FIELD_TAGLIB_PARSER_LOG

#define PARENT_DBG_FIELD_TAGLIB_PARSER_LOG    "taglib_parser_log"

Field for debug parser log setting

◆ PARENT_FTP

#define PARENT_FTP   "ftp"

Parent section for FTP settings

◆ PARENT_FTP_FIELD_PWD_HASH

#define PARENT_FTP_FIELD_PWD_HASH   "password_hash"

Field for FTP password hash

◆ PARENT_FTP_FIELD_SALT

#define PARENT_FTP_FIELD_SALT   "salt"

Field for FTP salt

◆ PARENT_FTP_FIELD_USER

#define PARENT_FTP_FIELD_USER   "username"

Field for FTP username

◆ PARENT_KEYBINDS

#define PARENT_KEYBINDS   "keybinds"

Parent section for keybinds

◆ PARENT_LIB

#define PARENT_LIB   "library"

Macros for parent and field names used in the TOML configuration.

These macros represent the sections and fields in the TOML configuration file. Parent section for library settings

◆ PARENT_LIB_FIELD_DIR

#define PARENT_LIB_FIELD_DIR   "directory"

Field for the library directory

◆ PARENT_LIB_FIELD_NAME

#define PARENT_LIB_FIELD_NAME   "name"

Field for the library name

◆ PARENT_UI

#define PARENT_UI   "ui"

Parent section for ui settings

◆ SPECIAL_KEYBIND_ENTER_STR

#define SPECIAL_KEYBIND_ENTER_STR   "Enter"

Special keybind for Enter

◆ SPECIAL_KEYBIND_SPACE_STR

#define SPECIAL_KEYBIND_SPACE_STR   "Space"

Special keybind for Space

◆ SPECIAL_KEYBIND_TAB_STR

#define SPECIAL_KEYBIND_TAB_STR   "Tab"

Special keybind for Tab

Function Documentation

◆ configFileExists()

bool configFileExists ( const string & filePath)

Checks if the configuration file exists.

This function checks if the config.toml file exists at the given file path.

Parameters
filePathThe path to the configuration file.
Returns
true if the file exists, otherwise false.

◆ getBaseConfigPath()

string getBaseConfigPath ( )

Retrieves the path to the configuration directory.

By default, this function uses the HOME environment variable to determine the user's home directory. However, it checks for the presence of a INLIMBO_CONFIG_HOME environment variable first, which can override the default location. This allows for custom configuration paths during testing.

Returns
A string representing the base path to the configuration directory.
Exceptions
std::runtime_errorIf the HOME environment variable is not found and no custom path is provided.

◆ getCachePath()

string getCachePath ( )

< Exit gracefully if the HOME environment variable is not set.

◆ getConfigPath()

string getConfigPath ( string fileName)

Retrieves the full path to the configuration file.

This constructs the full path to a specific configuration file.

Parameters
fileNameThe name of the configuration file (e.g., "config.toml").
Returns
A string representing the full path to the configuration file.

◆ loadConfig()

auto loadConfig ( )

Loads the configuration file.

This function loads the config.toml file and parses it using the toml library. If the file does not exist, the program exits gracefully with an error message.

Returns
A toml::parse_result object representing the parsed configuration.
Exceptions
std::runtime_errorIf the configuration file does not exist or cannot be parsed.

◆ parseTOMLField()

auto parseTOMLField ( string parent,
string field ) -> string_view

Parses a string field from the TOML configuration.

This function retrieves the value of a specific field within a parent section of the TOML configuration. If the field is not found, it returns an empty string view.

Parameters
parentThe parent section name (e.g., "library").
fieldThe field name within the parent section (e.g., "name").
Returns
A string view representing the value of the field.

< If the field is not found, return an empty string view.

◆ parseTOMLFieldBool()

auto parseTOMLFieldBool ( const string & parent,
const string & field ) -> bool

◆ parseTOMLFieldCustom()

auto parseTOMLFieldCustom ( const toml::parse_result & custom_config,
string parent,
string field ) -> string_view

Parses a string field from a custom TOML configuration that is called by the INLIMBO_CONFIG_HOME macro at runtime.

This function retrieves the value of a specific field within a parent section of the TOML configuration. If the field is not found, it returns an empty string view.

Parameters
parentThe parent section name (e.g., "library").
fieldThe field name within the parent section (e.g., "name").
Returns
A string view representing the value of the field.

< If the field is not found, return an empty string view.

◆ parseTOMLFieldInt()

auto parseTOMLFieldInt ( string parent,
string field ) -> int64_t

Parses an integer field from the TOML configuration.

This function retrieves the value of a specific field as an integer from the TOML configuration. If the field is not found, it returns -1 as a default value.

Parameters
parentThe parent section name (e.g., "ftp").
fieldThe field name within the parent section (e.g., "username").
Returns
The integer value of the field, or -1 if the field is not found.

< If the field is not found, return -1 as default.

◆ parseTOMLFieldIntCustom()

auto parseTOMLFieldIntCustom ( const toml::parse_result & custom_config,
string parent,
string field ) -> int64_t

Parses an integer field from a custom TOML configuration set by the INLIMBO_CONFIG_HOME macro at runtime.

This function retrieves the value of a specific field as an integer from the TOML configuration. If the field is not found, it returns -1 as a default value.

Parameters
parentThe parent section name (e.g., "ftp").
fieldThe field name within the parent section (e.g., "username").
Returns
The integer value of the field, or -1 if the field is not found.

< If the field is not found, return -1 as default.

Variable Documentation

◆ config

auto config = loadConfig()

Parse the configuration file during the initialization