inLimbo
TUI Music Player that keeps you in Limbo.
 
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_PARSER_LOG   "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"
 

Functions

string getConfigPath (string fileName)
 Retrieves the path to the configuration file.
 
string getCachePath ()
 
bool configFileExists (const string &filePath)
 Checks if the configuration file exists.
 
auto loadConfig ()
 Loads the configuration file.
 
string_view parseTOMLField (string parent, string field)
 Parses a string field from the TOML configuration.
 
int64_t parseTOMLFieldInt (string parent, string field)
 Parses an integer field from the TOML configuration.
 

Variables

auto config = loadConfig()
 

Macro Definition Documentation

◆ 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_PARSER_LOG

#define PARENT_DBG_FIELD_PARSER_LOG   "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

◆ 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.

◆ getCachePath()

string getCachePath ( )

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

◆ getConfigPath()

string getConfigPath ( string fileName)

Retrieves the path to the configuration file.

This function constructs the path to the config.toml file located in the user's home directory, inside the .config/inLimbo/ folder.

Parameters
fileNameThe name of the configuration file (e.g., "config.toml").
Returns
A string representing the full path to the configuration file.
Exceptions
std::runtime_errorIf the HOME environment variable is not found.

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

◆ 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()

string_view parseTOMLField ( string parent,
string field )

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.

◆ parseTOMLFieldInt()

int64_t parseTOMLFieldInt ( string parent,
string field )

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.

Variable Documentation

◆ config

auto config = loadConfig()

Parse the configuration file during the initialization