cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
parse_toml_common.h File Reference

Definition of common functions and macros to parse TOML files. More...

#include <chrono>
#include <exception>
#include <string>
#include <string_view>
#include <fmt/format.h>
#include <toml++/toml.h>
#include "msgpack_rpc/common/msgpack_rpc_exception.h"
#include "msgpack_rpc/common/status_code.h"
Include dependency graph for parse_toml_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  msgpack_rpc
 Namespace of cpp-msgpack-rpc library.
namespace  msgpack_rpc::config
 Namespace of configurations.

Macros

#define MSGPACK_RPC_PARSE_TOML_VALUE(KEY_STR, CONFIG_FUNCTION, TYPE)
 Internal macro to parse a value from TOML.
#define MSGPACK_RPC_PARSE_TOML_VALUE_DURATION(KEY_STR, CONFIG_FUNCTION)
 Internal macro to parse a value from TOML.

Functions

void msgpack_rpc::config::toml::impl::throw_error (const ::toml::source_region &source, std::string_view config_key)
 Throw an exception for an error of TOML.
void msgpack_rpc::config::toml::impl::throw_error (const ::toml::source_region &source, std::string_view config_key, std::string_view error_message)
 Throw an exception for an error of TOML.

Detailed Description

Definition of common functions and macros to parse TOML files.

Definition in file parse_toml_common.h.

Macro Definition Documentation

◆ MSGPACK_RPC_PARSE_TOML_VALUE

#define MSGPACK_RPC_PARSE_TOML_VALUE ( KEY_STR,
CONFIG_FUNCTION,
TYPE )
Value:
const auto config_value = value.value<TYPE>(); \
if (!config_value) { \
throw_error(value.source(), KEY_STR); \
} \
try { \
config.CONFIG_FUNCTION(*config_value); \
} catch (const std::exception& e) { \
throw_error(value.source(), KEY_STR, e.what()); \
}

Internal macro to parse a value from TOML.

Definition at line 69 of file parse_toml_common.h.

◆ MSGPACK_RPC_PARSE_TOML_VALUE_DURATION

#define MSGPACK_RPC_PARSE_TOML_VALUE_DURATION ( KEY_STR,
CONFIG_FUNCTION )
Value:
const auto config_value = value.value<double>(); \
if (!config_value) { \
throw_error(value.source(), KEY_STR); \
} \
try { \
config.CONFIG_FUNCTION( \
std::chrono::duration_cast<std::chrono::nanoseconds>( \
std::chrono::duration<double>(*config_value))); \
} catch (const std::exception& e) { \
throw_error(value.source(), KEY_STR, e.what()); \
}

Internal macro to parse a value from TOML.

Definition at line 81 of file parse_toml_common.h.

Function Documentation

◆ throw_error() [1/2]

void msgpack_rpc::config::toml::impl::throw_error ( const ::toml::source_region & source,
std::string_view config_key )
inline

Throw an exception for an error of TOML.

Parameters
[in]sourceLocation in TOML.
[in]config_keyKey of the configuration.

Definition at line 43 of file parse_toml_common.h.

◆ throw_error() [2/2]

void msgpack_rpc::config::toml::impl::throw_error ( const ::toml::source_region & source,
std::string_view config_key,
std::string_view error_message )
inline

Throw an exception for an error of TOML.

Parameters
[in]sourceLocation in TOML.
[in]config_keyKey of the configuration.
[in]error_messageError message.

Definition at line 59 of file parse_toml_common.h.