![]() |
Olympe Engine 2.0
2D Game Engine with ECS Architecture
|
#include "third_party/nlohmann/json.hpp"#include <fstream>#include <iostream>#include <string>#include <vector>#include <functional>
Include dependency graph for json_helper.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Namespaces | |
| namespace | JsonHelper |
Typedefs | |
| using | json = nlohmann::json |
Functions | |
| bool | JsonHelper::LoadJsonFromFile (const std::string &filepath, json &j) |
| Load and parse a JSON file. | |
| bool | JsonHelper::SaveJsonToFile (const std::string &filepath, const json &j, int indent=4) |
| Save a JSON object to a file with formatting. | |
| std::string | JsonHelper::GetString (const json &j, const std::string &key, const std::string &defaultValue="") |
| Safely get a string value from JSON. | |
| int | JsonHelper::GetInt (const json &j, const std::string &key, int defaultValue=0) |
| Safely get an integer value from JSON. | |
| uint32_t | JsonHelper::GetUInt (const json &j, const std::string &key, uint32_t defaultValue=0) |
| Safely get an unsigned integer value from JSON. | |
| float | JsonHelper::GetFloat (const json &j, const std::string &key, float defaultValue=0.0f) |
| Safely get a float value from JSON. | |
| double | JsonHelper::GetDouble (const json &j, const std::string &key, double defaultValue=0.0) |
| Safely get a double value from JSON. | |
| bool | JsonHelper::GetBool (const json &j, const std::string &key, bool defaultValue=false) |
| Safely get a boolean value from JSON. | |
| template<typename T > | |
| T | JsonHelper::json_get (const json &j, const std::string &key, const T &defaultValue) |
| Generic template function to safely get any type from JSON. | |
| bool | JsonHelper::IsArray (const json &j, const std::string &key) |
| Check if a key contains an array. | |
| bool | JsonHelper::IsObject (const json &j, const std::string &key) |
| Check if a key contains an object. | |
| size_t | JsonHelper::GetArraySize (const json &j, const std::string &key) |
| Get the size of an array. | |
| void | JsonHelper::ForEachInArray (const json &j, const std::string &key, std::function< void(const json &, size_t)> callback) |
| Iterate over an array with a callback function. | |
| float | JsonHelper::GetNestedFloat (const json &j, const std::string &parentKey, const std::string &childKey, float defaultValue=0.0f) |
| Get a nested float value from a parent object. | |
| std::string | JsonHelper::GetNestedString (const json &j, const std::string &parentKey, const std::string &childKey, const std::string &defaultValue="") |
| Get a nested string value from a parent object. | |
| int | JsonHelper::GetNestedInt (const json &j, const std::string &parentKey, const std::string &childKey, int defaultValue=0) |
| Get a nested int value from a parent object. | |
| bool | JsonHelper::LoadConfig (const std::string &filepath, json &j) |
| Load a configuration file (alias for LoadJsonFromFile) | |
| bool | JsonHelper::SaveConfig (const std::string &filepath, const json &j) |
| Save a configuration file (alias for SaveJsonToFile with indent=2) | |
| bool | JsonHelper::ValidateKeys (const json &j, const std::vector< std::string > &requiredKeys) |
| Validate that all required keys exist in a JSON object. | |
| bool | JsonHelper::ValidateKeysVerbose (const json &j, const std::vector< std::string > &requiredKeys, const std::string &context="") |
| Validate that all required keys exist and log which ones are missing. | |
Definition at line 28 of file json_helper.h.