Class for managing JSON Files.
More...
#include <json_manager.h>
|
| JSONManager () |
| Constructs a JSONManager object. More...
|
|
bool | projectExists (const std::string &projectName) |
| Validate if a project JSON exists. More...
|
|
void | deleteProject (const std::string &projectName) |
| Delete an existing project JSON. More...
|
|
template<typename T > |
void | setProjectValue (const std::string &projectName, const std::string &key, T value) |
| Sets a value for a given key in the project JSON. More...
|
|
template<typename T > |
void | setProjectNestedValue (const std::string &projectName, const std::vector< std::string > &keyPath, const T &value) |
| Sets a nested value for a given key in the project JSON. More...
|
|
template<typename T > |
T | getProjectValue (const std::string &projectName, const std::string &key) |
| Gets a value for a given key in the project JSON. More...
|
|
template<typename T = nlohmann::json> |
T | getProjectNestedValue (const std::string &projectName, const std::vector< std::string > &keyPath, const T &defaultValue=T()) |
| Gets a nested value for a given key in the project JSON. More...
|
|
Class for managing JSON Files.
This class supports creating new JSON files, writing/reading to and from JSON files Default JSON generation and saving/loading data from provided paths
◆ JSONManager()
Constructs a JSONManager object.
Initializes the JSONManager. The constructor sets up internal variables and creates the DEFAULT_JSON_PATH folder
◆ createDefaultProjectJSON()
void createDefaultProjectJSON |
( |
const std::string & |
projectName | ) |
|
|
private |
Creates a default project JSON.
The project shall be created within the DEFAULT_JSON_PATH folder
- Parameters
-
projectName | Name of the project being created |
◆ deleteProject()
void deleteProject |
( |
const std::string & |
projectName | ) |
|
Delete an existing project JSON.
- Parameters
-
projectName | Name of the project to delete |
◆ getProjectFilePath()
std::filesystem::path getProjectFilePath |
( |
const std::string & |
projectName | ) |
|
|
private |
Get the file path of a specified project.
- Parameters
-
projectName | Name of the project being retrieved |
- Returns
- File path relative to the root directory
◆ getProjectNestedValue()
T getProjectNestedValue |
( |
const std::string & |
projectName, |
|
|
const std::vector< std::string > & |
keyPath, |
|
|
const T & |
defaultValue = T() |
|
) |
| |
|
inline |
Gets a nested value for a given key in the project JSON.
This function loads the project's JSON, and then retrieves the value for the given key
- Template Parameters
-
T | The type of the value to be fetched |
- Parameters
-
projectName | Name of the project whose JSON will be checked |
keyPath | The key path in the JSON to check in the format: { 'key1', 'key2', 'key3' } |
- Returns
- Value saved at the JSON key
◆ getProjectValue()
T getProjectValue |
( |
const std::string & |
projectName, |
|
|
const std::string & |
key |
|
) |
| |
|
inline |
Gets a value for a given key in the project JSON.
This function loads the project's JSON, and then retrieves the value for the given key
- Template Parameters
-
T | The type of the value to be fetched |
- Parameters
-
projectName | Name of the project whose JSON will be checked |
key | The key in the JSON to check |
- Returns
- Value saved at the JSON key
◆ loadProjectJSON()
nlohmann::json loadProjectJSON |
( |
const std::string & |
projectName | ) |
|
|
private |
Loads the JSON of a specified project.
- Parameters
-
projectName | Name of the project being retrieved |
- Returns
- JSON object of the selected project
◆ projectExists()
bool projectExists |
( |
const std::string & |
projectName | ) |
|
Validate if a project JSON exists.
- Parameters
-
projectName | Name of the project to validate |
- Returns
- TRUE if the project JSON exists FALSE if the project JSON does not exist
◆ saveProjectJSON()
void saveProjectJSON |
( |
const std::string & |
projectName, |
|
|
const nlohmann::json & |
projectData |
|
) |
| |
|
private |
Saves JSON data to a specified project.
- Parameters
-
projectName | Name of the project being written to |
projectData | JSON object of the data to be written |
◆ setProjectNestedValue()
void setProjectNestedValue |
( |
const std::string & |
projectName, |
|
|
const std::vector< std::string > & |
keyPath, |
|
|
const T & |
value |
|
) |
| |
|
inline |
Sets a nested value for a given key in the project JSON.
This function loads the project's JSON, updates the value for the given key, and then saves the updated JSON back to the project file
- Template Parameters
-
T | The type of the value to be set |
- Parameters
-
projectName | Name of the project whose JSON will be updated |
keyPath | The key path in the JSON to update in the format: { 'key1', 'key2', 'key3' } |
value | The value to set for the given key |
◆ setProjectValue()
void setProjectValue |
( |
const std::string & |
projectName, |
|
|
const std::string & |
key, |
|
|
T |
value |
|
) |
| |
|
inline |
Sets a value for a given key in the project JSON.
This function loads the project's JSON, updates the value for the given key, and then saves the updated JSON back to the project file
- Template Parameters
-
T | The type of the value to be set |
- Parameters
-
projectName | Name of the project whose JSON will be updated |
key | The key in the JSON to update |
value | The value to set for the given key |
◆ DEFAULT_JSON_PATH
constexpr const char* DEFAULT_JSON_PATH = "./Simulation_JSON/" |
|
staticconstexprprivate |
◆ m_projectBasePath
std::filesystem::path m_projectBasePath |
|
private |
Temporary variable to store project file path
The documentation for this class was generated from the following files:
- simulation/common/inc/json_manager.h
- simulation/common/src/json_manager.cc