Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx::config_t::TomlConfig Class Reference

A trusted wrapper around the untrusted toml library More...

#include <ssgx_config_t.h>

Public Member Functions

 TomlConfig ()
 Default constructor for the TOML class.
 
 ~TomlConfig ()
 Destruction.
 
bool LoadFile (const char *toml_file_path)
 Load a TOML file and initialize the TOML object.
 
template<typename... Types>
std::optional< int64_t > GetInteger (Types... args)
 Finds an integer value in the TOML file.
 
template<typename... Types>
std::optional< std::string > GetString (Types... args)
 Finds a string value in the TOML file.
 
template<typename... Types>
std::optional< std::vector< int64_t > > GetIntegerArray (Types... args)
 Finds an integer array of values in the TOML file.
 
template<typename... Types>
std::optional< std::vector< std::string > > GetStringArray (Types... args)
 Finds a string array of values in the TOML file.
 
std::string GetLastErrorMsg () const
 Get the error code when the function returns false.
 

Detailed Description

A trusted wrapper around the untrusted toml library

Compared to the TOML v1.0.0 standard:

  1. We support reading strings and their arrays.
  2. We support reading integers (-2^63 to 2^63-1) and their arrays.
  3. We do not support reading dates and times or their arrays.
  4. We do not support reading floating-point numbers or their arrays.
  5. We do not support reading booleans or their arrays.

Constructor & Destructor Documentation

◆ TomlConfig()

ssgx::config_t::TomlConfig::TomlConfig ( )
inline

Default constructor for the TOML class.

◆ ~TomlConfig()

ssgx::config_t::TomlConfig::~TomlConfig ( )

Destruction.

Member Function Documentation

◆ GetInteger()

template<typename... Types>
std::optional< int64_t > ssgx::config_t::TomlConfig::GetInteger ( Types... args)
inline

Finds an integer value in the TOML file.

Template Parameters
TypesThe types of the keys (either const char* or int)
Parameters
[in]argsThe keys representing the data path to the integer value
Returns
The integer value if success, otherwise return std::nullopt.
Example
bool ok;
ok = toml.LoadFile("/root/config");
if (!ok) return false;
std::optional<int64_t> value = toml.GetInteger("animal", "dog", "age");
if (!value.has_value()) {
Printf("Failed, error: %s\n", toml.GetLastErrorMsg().c_str());
return false;
}
Printf("Value: %d\n", value);
A trusted wrapper around the untrusted toml library
Definition ssgx_config_t.h:124
bool LoadFile(const char *toml_file_path)
Load a TOML file and initialize the TOML object.
std::optional< int64_t > GetInteger(Types... args)
Finds an integer value in the TOML file.
Definition ssgx_config_t.h:178
std::string GetLastErrorMsg() const
Get the error code when the function returns false.
Definition ssgx_config_t.h:285

◆ GetIntegerArray()

template<typename... Types>
std::optional< std::vector< int64_t > > ssgx::config_t::TomlConfig::GetIntegerArray ( Types... args)
inline

Finds an integer array of values in the TOML file.

Template Parameters
TypesThe types of the keys (either const char* or int)
Parameters
[in]argsThe keys representing the data path to the array of values
Returns
The integer values array if success, otherwise return std::nullopt.
Example
bool ok;
ok = toml.LoadFile("/root/config");
if (!ok) return false;
std::vector<std::string> values = toml.GetIntegerArray("number");
if (!values.has_value()) {
Printf("Failed, error: %s\n", toml.GetLastErrorMsg().c_str());
return false;
}
Printf("values count: %d\n", values.size());
std::optional< std::vector< int64_t > > GetIntegerArray(Types... args)
Finds an integer array of values in the TOML file.
Definition ssgx_config_t.h:236

◆ GetLastErrorMsg()

std::string ssgx::config_t::TomlConfig::GetLastErrorMsg ( ) const
inlinenodiscard

Get the error code when the function returns false.

Returns
error code
Example
bool ok;
ok = toml.LoadFile("/root/config");
if (!ok) {
Printf("error msg: %s\n", toml.GetLastErrorMsg().c_str());
return false;
}

◆ GetString()

template<typename... Types>
std::optional< std::string > ssgx::config_t::TomlConfig::GetString ( Types... args)
inline

Finds a string value in the TOML file.

Template Parameters
TypesThe types of the keys (either const char* or int)
Parameters
[in]argsThe keys representing the data path to the string value
Returns
The string value if success, otherwise return std::nullopt.
Example
bool ok;
ok = toml.LoadFile("/root/config");
if (!ok) return false;
std::optional<std::string>> value = toml.GetString("animal", "dog", "name");
if (!value.has_value()) {
Printf("Failed, error: %s\n", toml.GetLastErrorMsg().c_str());
return false;
}
Printf("Value: %s\n", value.c_str());
std::optional< std::string > GetString(Types... args)
Finds a string value in the TOML file.
Definition ssgx_config_t.h:207

◆ GetStringArray()

template<typename... Types>
std::optional< std::vector< std::string > > ssgx::config_t::TomlConfig::GetStringArray ( Types... args)
inline

Finds a string array of values in the TOML file.

Template Parameters
TypesThe types of the keys (either const char* or int)
Parameters
[in]argsThe keys representing the data path to the array of values
Returns
The string values array if success, otherwise return std::nullopt.
Example
bool ok;
ok = toml.LoadFile("/root/config");
if (!ok) return false;
std::vector<std::string> values = toml.GetStringArray("colors");
if (!values.has_value()) {
Printf("Failed, error: %s\n", toml.GetLastErrorMsg().c_str());
return false;
}
Printf("values count: %d\n", values.size());
std::optional< std::vector< std::string > > GetStringArray(Types... args)
Finds a string array of values in the TOML file.
Definition ssgx_config_t.h:265

◆ LoadFile()

bool ssgx::config_t::TomlConfig::LoadFile ( const char * toml_file_path)

Load a TOML file and initialize the TOML object.

Parameters
[in]toml_file_pathThe path to the TOML file to parse
Returns
True if the TOML object was successfully created; false otherwise
Example
bool ok;
ok = toml.LoadFile(toml, "/root/config");
if (!ok) return false;

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