Metall  v0.28
A persistent memory allocator for data-centric analytics
parse.hpp
Go to the documentation of this file.
1 // Copyright 2021 Lawrence Livermore National Security, LLC and other Metall
2 // Project Developers. See the top-level COPYRIGHT file for details.
3 //
4 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
5 
6 #ifndef METALL_JSON_PARSE_HPP
7 #define METALL_JSON_PARSE_HPP
8 
9 #include <iostream>
10 #include <string_view>
11 #include <memory>
12 
13 #include <metall/json/json_fwd.hpp>
14 
15 namespace metall::json {
16 
17 namespace {
18 namespace bj = boost::json;
19 }
20 
26 #ifdef DOXYGEN_SKIP
27 template <typename allocator_type = std::allocator<std::byte>>
29  std::string_view input_json_string,
30  const allocator_type &allocator = allocator_type())
31 #else
32 template <typename allocator_type>
33 inline value<allocator_type> parse(std::string_view input_json_string,
34  const allocator_type &allocator)
35 #endif
36 {
37  bj::error_code ec;
38  auto bj_value = bj::parse(input_json_string.data(), ec);
39  if (ec) {
40  std::cerr << "Failed to parse: " << ec.message() << std::endl;
41  return value<allocator_type>{allocator};
42  }
43 
44  return metall::json::value_from(std::move(bj_value), allocator);
45 }
46 
47 } // namespace metall::json
48 
49 #endif // METALL_JSON_PARSE_HPP
Namespace for Metall JSON container, which is in an experimental phase.
Definition: array.hpp:17
value< allocator_type > parse(std::string_view input_json_string, const allocator_type &allocator=allocator_type())
Parses a JSON represented as a string.
Definition: parse.hpp:28
value< allocator_type > value_from(T &&input_data, const allocator_type &allocator=allocator_type())
Convert an input data and construct a JSON value.
Definition: value_from.hpp:71