cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
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
33
34namespace msgpack_rpc::config::toml::impl {
35
44inline 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
Definition of ClientConfig class.
Definition of LoggingConfig class.
Definition of parse_toml functions for clients and servers.
void parse_toml(const ::toml::table &table, MessageParserConfig &config)
Parse a configuration of parsers of messages from TOML.
Definition of common functions and macros to parse TOML files.
void throw_error(const ::toml::source_region &source, std::string_view config_key)
Throw an exception for an error of TOML.
Definition of parse_toml functions for logging.
Definition of ServerConfig class.