Metall  v0.28
A persistent memory allocator for data-centric analytics
serialize.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_SERIALIZE_HPP
7 #define METALL_JSON_SERIALIZE_HPP
8 
9 #include <iostream>
10 
12 #include <metall/json/json_fwd.hpp>
13 
14 namespace metall::json {
15 
16 namespace {
17 namespace mc = metall::container;
18 namespace bj = boost::json;
19 } // namespace
20 
21 template <typename allocator_type>
23  return bj::serialize(value_to<bj::value>(input));
24 }
25 
26 template <typename allocator_type>
28  bj::object object;
29  for (const auto &elem : input) {
30  object[elem.key().data()] = value_to<bj::value>(elem.value());
31  }
32  return bj::serialize(object);
33 }
34 
35 template <typename allocator_type>
37  bj::array array;
38  for (const auto &elem : input) {
39  array.emplace_back(value_to<bj::value>(elem));
40  }
41  return bj::serialize(array);
42 }
43 
44 template <typename char_type, typename traits, typename allocator_type>
47  return input.data();
48 }
49 
50 template <typename allocator_type>
51 std::ostream &operator<<(std::ostream &os, const value<allocator_type> &val) {
52  os << serialize(val);
53  return os;
54 }
55 
56 template <typename allocator_type>
57 std::ostream &operator<<(std::ostream &os, const object<allocator_type> &obj) {
58  os << serialize(obj);
59  return os;
60 }
61 
62 template <typename allocator_type>
63 std::ostream &operator<<(std::ostream &os, const array<allocator_type> &arr) {
64  os << serialize(arr);
65  return os;
66 }
67 
68 } // namespace metall::json
69 
70 #endif // METALL_JSON_SERIALIZE_HPP
JSON array. An array is an ordered collection of values.
Definition: array.hpp:43
JSON object. An object is a table key and value pairs. The order of key-value pairs depends on the im...
Definition: object.hpp:22
Namespace for Metall container.
basic_string< char > string
A string container that uses char as its character type and Metall as its default allocator.
Definition: string.hpp:23
Namespace for Metall JSON container, which is in an experimental phase.
Definition: array.hpp:17
std::string serialize(const value< allocator_type > &input)
Definition: serialize.hpp:22
metall::container::basic_string< char_t, traits, allocator_type > basic_string
JSON basic string type.
Definition: json_fwd.hpp:44
std::ostream & operator<<(std::ostream &os, const value< allocator_type > &val)
Definition: serialize.hpp:51
std::string serialize(const basic_string< char_type, traits, allocator_type > &input)
Definition: serialize.hpp:45