Diag-Client-Lib
json_parser.cpp
Go to the documentation of this file.
1 /* Diagnostic Client library
2 * Copyright (C) 2024 Avijit Dey
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8 
9 #include "parser/json_parser.h"
10 
11 #include "common/logger.h"
12 
13 namespace boost_support {
14 namespace parser {
15 
16 core_type::Result<void, ParsingErrorCode> Read(std::string_view config_path, boost_tree &json_tree) {
18  // Get the tree with configuration details
19  try {
20  boost::property_tree::read_json(std::string{config_path}, json_tree);
21  parse_result.EmplaceValue();
22  } catch (boost::property_tree::json_parser_error &error) {
23  parse_result.EmplaceError(ParsingErrorCode::kError);
25  __FILE__, __LINE__, __func__,
26  [&error](std::stringstream &msg) { msg << "Reading of config failed with error: " << error.message(); });
27  }
28  return parse_result;
29 }
30 
31 } // namespace parser
32 } // namespace boost_support
static auto GetLibBoostLogger() noexcept -> LibBoostLogger &
Definition: logger.h:20
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29
void EmplaceValue(Args &&...args) noexcept
Put a new value into this instance, constructed in-place from the given arguments.
Definition: result.h:187
core_type::Result< void, ParsingErrorCode > Read(std::string_view config_path, boost_tree &json_tree)
Parser to get the configuration from json file.
Definition: json_parser.cpp:16
boost::property_tree::ptree boost_tree
Type alias for boost property tree.
Definition: json_parser.h:23