Skip to content

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.

std::string astrea::utilities::clean_entry (
    const nlohmann::json & entry
) 

Parameters:

  • entry The 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:

  • T The type of the value to extract.

Parameters:

  • json The JSON object to extract from.
  • key The key to look for in the JSON object.

Returns:

The extracted value of type T.

Exception:

  • std::runtime_error if 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:

  • T The type of the value to extract.

Parameters:

  • json The JSON object to extract from.
  • key The 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_error if 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:

  • json The JSON object to extract from.
  • key The 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_error if 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:

  • json The JSON object to extract from.
  • key The key to look for in the JSON object.

Returns:

The extracted string value.

Exception:

  • std::runtime_error if 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<typename T>
std::string astrea::utilities::get_type_name () 

Template parameters:

  • T The 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:

  • original The original string.
  • before The substring to be replaced.
  • after The 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:

  • s The string to split.
  • delimiter The delimiter to split by.

Returns:

A vector of substrings.

Note:

Taken from https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c


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:

  • str The string to trim.
  • whitespace The 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