Namespace astrea::utilities¶
Namespace List > astrea > utilities
Classes¶
| Type | Name |
|---|---|
| class | ProgressBar A simple console progress bar utility. |
Public Functions¶
| Type | Name |
|---|---|
| std::string | clean_entry (const nlohmann::json & entry) Cleans a JSON entry by removing quotes and returning it as a string. |
| T | extract_from_json (const nlohmann::json & json, const std::string & key) Extracts a value of type T from a JSON object using the specified key. |
| std::optional< T > | extract_optional_from_json (const nlohmann::json & json, const std::string & key) Extracts an optional value of type T from a JSON object using the specified key. |
| std::optional< std::string > | extract_optional_string_from_json (const nlohmann::json & json, const std::string & key) Extracts an optional string value from a JSON object using the specified key. |
| std::string | extract_string_from_json (const nlohmann::json & json, const std::string & key) Extracts a string value from a JSON object using the specified key. |
| std::string | get_type_name () Gets the demangled(ish) type name of a given type. |
| std::string | replace_all (std::string const & original, std::string const & before, std::string const & after) Replaces all occurrences of a substring with another substring in a string. |
| std::vector< std::string > | split (std::string s, const std::string & delimiter) Splits a string into a vector of substrings based on a delimiter. |
| std::string | trim (const std::string & str, const std::string & whitespace=" \t") Trims whitespace from both ends of a string. |
Public Functions Documentation¶
function clean_entry¶
Cleans a JSON entry by removing quotes and returning it as a string.
Parameters:
entryThe JSON entry to clean.
Returns:
A cleaned string without quotes.
function extract_from_json¶
Extracts a value of type T from a JSON object using the specified key.
template<typename T>
T astrea::utilities::extract_from_json (
const nlohmann::json & json,
const std::string & key
)
Template parameters:
TThe type of the value to extract.
Parameters:
jsonThe JSON object to extract from.keyThe key to look for in the JSON object.
Returns:
The extracted value of type T.
Exception:
std::runtime_errorif the key is not found or if the value is null.
function extract_optional_from_json¶
Extracts an optional value of type T from a JSON object using the specified key.
template<typename T>
std::optional< T > astrea::utilities::extract_optional_from_json (
const nlohmann::json & json,
const std::string & key
)
Template parameters:
TThe type of the value to extract.
Parameters:
jsonThe JSON object to extract from.keyThe key to look for in the JSON object.
Returns:
An std::optional containing the extracted value, or std::nullopt if the key is not found or the value is null.
Exception:
std::runtime_errorif the key is not found.
function extract_optional_string_from_json¶
Extracts an optional string value from a JSON object using the specified key.
std::optional< std::string > astrea::utilities::extract_optional_string_from_json (
const nlohmann::json & json,
const std::string & key
)
Parameters:
jsonThe JSON object to extract from.keyThe key to look for in the JSON object.
Returns:
An std::optional containing the extracted string value, or std::nullopt if the key is not found or the value is null.
Exception:
std::runtime_errorif the key is not found.
function extract_string_from_json¶
Extracts a string value from a JSON object using the specified key.
std::string astrea::utilities::extract_string_from_json (
const nlohmann::json & json,
const std::string & key
)
Parameters:
jsonThe JSON object to extract from.keyThe key to look for in the JSON object.
Returns:
The extracted string value.
Exception:
std::runtime_errorif the key is not found or if the value is null.
function get_type_name¶
Gets the demangled(ish) type name of a given type.
Template parameters:
TThe type to get the name of.
Returns:
The demangled type name as a string.
function replace_all¶
Replaces all occurrences of a substring with another substring in a string.
std::string astrea::utilities::replace_all (
std::string const & original,
std::string const & before,
std::string const & after
)
Parameters:
originalThe original string.beforeThe substring to be replaced.afterThe substring to replace with.
Returns:
A new string with all occurrences replaced.
function split¶
Splits a string into a vector of substrings based on a delimiter.
std::vector< std::string > astrea::utilities::split (
std::string s,
const std::string & delimiter
)
Parameters:
sThe string to split.delimiterThe delimiter to split by.
Returns:
A vector of substrings.
Note:
function trim¶
Trims whitespace from both ends of a string.
std::string astrea::utilities::trim (
const std::string & str,
const std::string & whitespace=" \t"
)
Parameters:
strThe string to trim.whitespaceThe characters to trim (default is space and tab).
Returns:
A trimmed string.
The documentation for this class was generated from the following file astrea/utilities/utilities/json_util.cpp