cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
parse_toml_root.h
Go to the documentation of this file.
1
/*
2
* Copyright 2023 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
#include <string>
23
#include <unordered_map>
24
25
#include <toml++/toml.h>
26
27
#include "
msgpack_rpc/config/client_config.h
"
28
#include "
msgpack_rpc/config/logging_config.h
"
29
#include "
msgpack_rpc/config/server_config.h
"
30
#include "
msgpack_rpc/config/toml/parse_toml_client_server.h
"
31
#include "
msgpack_rpc/config/toml/parse_toml_common.h
"
32
#include "
msgpack_rpc/config/toml/parse_toml_logging.h
"
33
34
namespace
msgpack_rpc::config::toml::impl {
35
44
inline
void
parse_toml
(const ::toml::table& root_table,
45
std::unordered_map<std::string, LoggingConfig>& logging_configs,
46
std::unordered_map<std::string, ClientConfig>& client_configs,
47
std::unordered_map<std::string, ServerConfig>& server_configs) {
48
if
(
const
auto
logging_node = root_table.at_path(
"logging"
)) {
49
const
auto
* logging_table = logging_node.as_table();
50
if
(logging_table ==
nullptr
) {
51
impl::throw_error
(logging_node.node()->source(),
"logging"
,
52
"\"logging\" must be a table of tables."
);
53
}
54
impl::parse_toml
(*logging_table, logging_configs);
55
}
56
57
if
(
const
auto
client_node = root_table.at_path(
"client"
)) {
58
const
auto
* client_table = client_node.as_table();
59
if
(client_table ==
nullptr
) {
60
impl::throw_error
(client_node.node()->source(),
"client"
,
61
"\"client\" must be a table of tables."
);
62
}
63
impl::parse_toml
(*client_table, client_configs);
64
}
65
66
if
(
const
auto
server_node = root_table.at_path(
"server"
)) {
67
const
auto
* server_table = server_node.as_table();
68
if
(server_table ==
nullptr
) {
69
impl::throw_error
(server_node.node()->source(),
"server"
,
70
"\"server\" must be a table of tables."
);
71
}
72
impl::parse_toml
(*server_table, server_configs);
73
}
74
}
75
76
}
// namespace msgpack_rpc::config::toml::impl
client_config.h
Definition of ClientConfig class.
logging_config.h
Definition of LoggingConfig class.
parse_toml_client_server.h
Definition of parse_toml functions for clients and servers.
msgpack_rpc::config::toml::impl::parse_toml
void parse_toml(const ::toml::table &table, MessageParserConfig &config)
Parse a configuration of parsers of messages from TOML.
Definition
parse_toml_client_server.h:46
parse_toml_common.h
Definition of common functions and macros to parse TOML files.
msgpack_rpc::config::toml::impl::throw_error
void throw_error(const ::toml::source_region &source, std::string_view config_key)
Throw an exception for an error of TOML.
Definition
parse_toml_common.h:43
parse_toml_logging.h
Definition of parse_toml functions for logging.
server_config.h
Definition of ServerConfig class.
src
msgpack_rpc
config
toml
parse_toml_root.h
Generated on
for cpp-msgpack-rpc by
1.18.0