R-Type  2
Doom but in better
Loading...
Searching...
No Matches
TOMLLoader Class Reference

A utility class for parsing, navigating, and managing TOML files and data. More...

#include <TOMLLoader.hpp>

Collaboration diagram for TOMLLoader:
Collaboration graph

Public Member Functions

 TOMLLoader ()
 Default constructor.
 
 TOMLLoader (const std::string &tomlPath)
 Constructor that initializes the loader with a TOML file path.
 
 TOMLLoader (const TOMLLoader &tomlInstance)
 Copy constructor.
 
 TOMLLoader (const toml::table &tomlTable, const std::string &tomlPath)
 Constructor that initializes the loader with a TOML table.
 
 TOMLLoader (const toml::array &tomlArray, const std::string &tomlPath)
 Constructor that initializes the loader with a TOML array.
 
 TOMLLoader (const toml::array &tomlArray, const std::string &key, const std::string &tomlPath)
 Constructor that initializes the loader with a TOML array under a specific key.
 
 ~TOMLLoader ()=default
 Default destructor.
 
void setTOMLPath (const std::string &tomlPath)
 Sets the path of the TOML file to load.
 
const bool isTOMLLoaded () const
 Checks if the TOML file is successfully loaded.
 
const std::string getTOMLPath () const
 Retrieves the path of the loaded TOML file.
 
const std::string getTOMLString () const
 Retrieves the TOML data as a string.
 
const toml::table getRawTOML () const
 Retrieves the raw TOML table.
 
template<typename T >
getValue (const std::string &key) const
 Retrieves a value of type T from the TOML table.
 
const toml::node_type getValueType (const std::string &key) const
 Retrieves the type of a value for a specific key as a TOML node type.
 
const std::string getValueTypeAsString (const std::string &key) const
 Retrieves the type of a value for a specific key as a string.
 
const std::string getTypeAsString (const std::string &key) const
 Retrieves the type of a value for a specific key as a string (alias).
 
const std::string getTypeAsString (const toml::node_type &type) const
 Converts a TOML node type to a string representation.
 
const bool hasKey (const std::string &key) const
 Checks if a specific key exists in the TOML data.
 
std::vector< std::string > getKeys () const
 Retrieves all keys from the TOML table.
 
toml::table getTable (const std::string &key) const
 Retrieves a TOML table for a specific key.
 
toml::array getArray (const std::string &key) const
 Retrieves a TOML array for a specific key.
 
void update (const TOMLLoader &copy)
 Updates the current loader with another loader's data.
 
void update (const toml::table &copy)
 Updates the current loader with a TOML table.
 
void update (const toml::array &copy)
 Updates the current loader with a TOML array.
 
void update (const toml::array &copy, const std::string &key)
 Updates the current loader with a TOML array under a specific key.
 
void printTOML () const
 Prints the TOML data to the debug stream.
 
TOMLLoaderoperator= (const TOMLLoader &copy)
 Copy assignment operator.
 
TOMLLoaderoperator= (const toml::table &copy)
 Assignment operator for TOML tables.
 
TOMLLoaderoperator= (const toml::array &copy)
 Assignment operator for TOML arrays.
 

Detailed Description

A utility class for parsing, navigating, and managing TOML files and data.

Definition at line 31 of file TOMLLoader.hpp.

Constructor & Destructor Documentation

◆ TOMLLoader() [1/6]

TOMLLoader::TOMLLoader ( )

Default constructor.

Definition at line 16 of file TOMLLoader.cpp.

◆ TOMLLoader() [2/6]

TOMLLoader::TOMLLoader ( const std::string & tomlPath)

Constructor that initializes the loader with a TOML file path.

Parameters
tomlPathThe path to the TOML file to be loaded.

Definition at line 21 of file TOMLLoader.cpp.

◆ TOMLLoader() [3/6]

TOMLLoader::TOMLLoader ( const TOMLLoader & tomlInstance)

Copy constructor.

Parameters
tomlInstanceThe instance to copy.

Definition at line 27 of file TOMLLoader.cpp.

◆ TOMLLoader() [4/6]

TOMLLoader::TOMLLoader ( const toml::table & tomlTable,
const std::string & tomlPath )

Constructor that initializes the loader with a TOML table.

Parameters
tomlTableA TOML table.
tomlPathThe path to the TOML file.

Definition at line 32 of file TOMLLoader.cpp.

◆ TOMLLoader() [5/6]

TOMLLoader::TOMLLoader ( const toml::array & tomlArray,
const std::string & tomlPath )

Constructor that initializes the loader with a TOML array.

Parameters
tomlArrayA TOML array.
tomlPathThe path to the TOML file.

Definition at line 40 of file TOMLLoader.cpp.

◆ TOMLLoader() [6/6]

TOMLLoader::TOMLLoader ( const toml::array & tomlArray,
const std::string & key,
const std::string & tomlPath )

Constructor that initializes the loader with a TOML array under a specific key.

Parameters
tomlArrayA TOML array.
keyThe key associated with the array.
tomlPathThe path to the TOML file.

Definition at line 48 of file TOMLLoader.cpp.

◆ ~TOMLLoader()

TOMLLoader::~TOMLLoader ( )
default

Default destructor.

Member Function Documentation

◆ getArray()

toml::array TOMLLoader::getArray ( const std::string & key) const

Retrieves a TOML array for a specific key.

Parameters
keyThe key to retrieve.
Returns
The corresponding TOML array.
Exceptions
CustomExceptions::NoTOMLKeyif the key does not exist or is not an array.

Definition at line 143 of file TOMLLoader.cpp.

◆ getKeys()

std::vector< std::string > TOMLLoader::getKeys ( ) const

Retrieves all keys from the TOML table.

Returns
A vector of all keys.

Definition at line 124 of file TOMLLoader.cpp.

◆ getRawTOML()

const toml::table TOMLLoader::getRawTOML ( ) const

Retrieves the raw TOML table.

Returns
The raw TOML table.

Definition at line 78 of file TOMLLoader.cpp.

◆ getTable()

toml::table TOMLLoader::getTable ( const std::string & key) const

Retrieves a TOML table for a specific key.

Parameters
keyThe key to retrieve.
Returns
The corresponding TOML table.
Exceptions
CustomExceptions::NoTOMLKeyif the key does not exist or is not a table.

Definition at line 134 of file TOMLLoader.cpp.

◆ getTOMLPath()

const std::string TOMLLoader::getTOMLPath ( ) const

Retrieves the path of the loaded TOML file.

Returns
The path as a string.

Definition at line 67 of file TOMLLoader.cpp.

◆ getTOMLString()

const std::string TOMLLoader::getTOMLString ( ) const

Retrieves the TOML data as a string.

Returns
The TOML data in string format.

Definition at line 72 of file TOMLLoader.cpp.

◆ getTypeAsString() [1/2]

const std::string TOMLLoader::getTypeAsString ( const std::string & key) const

Retrieves the type of a value for a specific key as a string (alias).

Parameters
keyThe key to query.
Returns
The type as a string.

Definition at line 104 of file TOMLLoader.cpp.

◆ getTypeAsString() [2/2]

const std::string TOMLLoader::getTypeAsString ( const toml::node_type & type) const

Converts a TOML node type to a string representation.

Parameters
typeThe TOML node type.
Returns
The type as a string.

Definition at line 109 of file TOMLLoader.cpp.

◆ getValue()

template<typename T >
T TOMLLoader::getValue ( const std::string & key) const
inline

Retrieves a value of type T from the TOML table.

Template Parameters
TThe type of the value to retrieve.
Parameters
keyThe key of the value to retrieve.
Returns
The value of type T.
Exceptions
CustomExceptions::NoTOMLKeyif the key is not found or the value cannot be converted.
Warning
Do not move the initialisation of this function outside of the header file or compilation issues will arise.

Definition at line 116 of file TOMLLoader.hpp.

◆ getValueType()

const toml::node_type TOMLLoader::getValueType ( const std::string & key) const

Retrieves the type of a value for a specific key as a TOML node type.

Parameters
keyThe key to query.
Returns
The TOML node type.

Definition at line 84 of file TOMLLoader.cpp.

◆ getValueTypeAsString()

const std::string TOMLLoader::getValueTypeAsString ( const std::string & key) const

Retrieves the type of a value for a specific key as a string.

Parameters
keyThe key to query.
Returns
The type as a string.

Definition at line 93 of file TOMLLoader.cpp.

◆ hasKey()

const bool TOMLLoader::hasKey ( const std::string & key) const

Checks if a specific key exists in the TOML data.

Parameters
keyThe key to check.
Returns
True if the key exists, false otherwise.

Definition at line 118 of file TOMLLoader.cpp.

◆ isTOMLLoaded()

const bool TOMLLoader::isTOMLLoaded ( ) const

Checks if the TOML file is successfully loaded.

Returns
True if loaded, false otherwise.

Definition at line 62 of file TOMLLoader.cpp.

◆ operator=() [1/3]

TOMLLoader & TOMLLoader::operator= ( const toml::array & copy)

Assignment operator for TOML arrays.

Parameters
copyThe TOML array to assign.
Returns
Reference to the current loader.

Definition at line 198 of file TOMLLoader.cpp.

◆ operator=() [2/3]

TOMLLoader & TOMLLoader::operator= ( const toml::table & copy)

Assignment operator for TOML tables.

Parameters
copyThe TOML table to assign.
Returns
Reference to the current loader.

Definition at line 192 of file TOMLLoader.cpp.

◆ operator=() [3/3]

TOMLLoader & TOMLLoader::operator= ( const TOMLLoader & copy)

Copy assignment operator.

Parameters
copyThe loader to copy.
Returns
Reference to the current loader.

Definition at line 186 of file TOMLLoader.cpp.

◆ printTOML()

void TOMLLoader::printTOML ( ) const

Prints the TOML data to the debug stream.

Definition at line 180 of file TOMLLoader.cpp.

◆ setTOMLPath()

void TOMLLoader::setTOMLPath ( const std::string & tomlPath)

Sets the path of the TOML file to load.

Parameters
tomlPathThe file path to set.

Definition at line 56 of file TOMLLoader.cpp.

◆ update() [1/4]

void TOMLLoader::update ( const toml::array & copy)

Updates the current loader with a TOML array.

Parameters
copyThe TOML array to copy data from.

Definition at line 168 of file TOMLLoader.cpp.

◆ update() [2/4]

void TOMLLoader::update ( const toml::array & copy,
const std::string & key )

Updates the current loader with a TOML array under a specific key.

Parameters
copyThe TOML array to copy data from.
keyThe key associated with the array.

Definition at line 174 of file TOMLLoader.cpp.

◆ update() [3/4]

void TOMLLoader::update ( const toml::table & copy)

Updates the current loader with a TOML table.

Parameters
copyThe TOML table to copy data from.

Definition at line 162 of file TOMLLoader.cpp.

◆ update() [4/4]

void TOMLLoader::update ( const TOMLLoader & copy)

Updates the current loader with another loader's data.

Parameters
copyThe other loader to copy data from.

Definition at line 152 of file TOMLLoader.cpp.


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