Metall  v0.27
A persistent memory allocator for data-centric analytics
json_fwd.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 
8 
9 #ifndef METALL_JSON_JSON_FWD_HPP
10 #define METALL_JSON_JSON_FWD_HPP
11 
12 #include <string>
13 #include <variant>
14 
15 #ifdef DOXYGEN_SKIP
17 #define METALL_LINK_WITH_BOOST_JSON
18 
20 #define METALL_BOOST_JSON_SRC_INCLUDED
21 #endif
22 
23 #ifdef METALL_LINK_WITH_BOOST_JSON
24 #include <boost/json.hpp>
25 #else
26 #ifndef METALL_BOOST_JSON_SRC_INCLUDED
27 #define METALL_BOOST_JSON_SRC_INCLUDED
28 #include <boost/json/src.hpp>
29 #endif // METALL_BOOST_JSON_SRC_INCLUDED
30 #endif // METALL_LINK_WITH_BOOST_JSON
31 
33 
37 namespace metall::json {
39 using null_type = std::monostate;
40 
42 template <typename char_t, typename traits, typename allocator_type>
43 using basic_string =
45 
47 template <typename allocator_type = std::allocator<std::byte>>
48 using string = basic_string<char, std::char_traits<char>, allocator_type>;
49 } // namespace metall::json
50 
51 // Forward declaration
52 #if !defined(DOXYGEN_SKIP)
53 
54 namespace metall::json {
55 
56 template <typename allocator_type = std::allocator<std::byte>>
57 class value;
58 
59 template <typename allocator_type = std::allocator<std::byte>>
60 class array;
61 
62 template <typename char_type = char,
63  typename char_traits = std::char_traits<char_type>,
64  typename allocator_type = std::allocator<char_type>>
65 class key_value_pair;
66 
67 template <typename allocator_type = std::allocator<std::byte>>
68 class object;
69 
70 template <typename allocator_type>
71 void swap(value<allocator_type> &, value<allocator_type> &) noexcept;
72 
73 template <typename allocator_type>
74 void swap(string<allocator_type> &, string<allocator_type> &) noexcept;
75 
76 template <typename allocator_type>
77 void swap(array<allocator_type> &, array<allocator_type> &) noexcept;
78 
79 template <typename allocator_type>
80 void swap(object<allocator_type> &, object<allocator_type> &) noexcept;
81 
82 template <typename char_type, typename char_traits, typename allocator_type>
83 void swap(key_value_pair<char_type, char_traits, allocator_type> &,
84  key_value_pair<char_type, char_traits, allocator_type> &) noexcept;
85 
86 template <typename char_type, typename char_traits, typename allocator_type>
87 bool operator==(const key_value_pair<char_type, char_traits, allocator_type> &,
88  const boost::json::key_value_pair &);
89 
90 template <typename char_type, typename char_traits, typename allocator_type>
91 bool operator==(const boost::json::key_value_pair &,
92  const key_value_pair<char_type, char_traits, allocator_type> &);
93 
94 template <typename char_type, typename char_traits, typename allocator_type>
95 bool operator!=(const key_value_pair<char_type, char_traits, allocator_type> &,
96  const boost::json::key_value_pair &);
97 
98 template <typename char_type, typename char_traits, typename allocator_type>
99 bool operator!=(const boost::json::key_value_pair &,
100  const key_value_pair<char_type, char_traits, allocator_type> &);
101 
102 template <typename allocator_type>
103 bool operator==(const value<allocator_type> &, const boost::json::value &);
104 
105 template <typename allocator_type>
106 bool operator==(const boost::json::value &, const value<allocator_type> &);
107 
108 template <typename allocator_type>
109 bool operator!=(const value<allocator_type> &, const boost::json::value &);
110 
111 template <typename allocator_type>
112 bool operator!=(const boost::json::value &, const value<allocator_type> &);
113 
114 template <typename allocator_type>
115 bool operator==(const array<allocator_type> &, const boost::json::array &);
116 
117 template <typename allocator_type>
118 bool operator==(const boost::json::array &, const array<allocator_type> &);
119 
120 template <typename allocator_type>
121 bool operator!=(const array<allocator_type> &, const boost::json::array &);
122 
123 template <typename allocator_type>
124 bool operator!=(const boost::json::array &, const array<allocator_type> &);
125 
126 template <typename allocator_type>
127 bool operator==(const object<allocator_type> &, const boost::json::object &);
128 
129 template <typename allocator_type>
130 bool operator==(const boost::json::object &, const object<allocator_type> &);
131 
132 template <typename allocator_type>
133 bool operator!=(const object<allocator_type> &, const boost::json::object &);
134 
135 template <typename allocator_type>
136 bool operator!=(const boost::json::object &, const object<allocator_type> &);
137 
138 template <typename char_t, typename traits, typename allocator>
139 bool operator==(const basic_string<char_t, traits, allocator> &,
140  const boost::json::string &);
141 
142 template <typename char_t, typename traits, typename allocator>
143 bool operator==(const boost::json::string &,
144  const basic_string<char_t, traits, allocator> &);
145 
146 template <typename char_t, typename traits, typename allocator>
147 bool operator!=(const basic_string<char_t, traits, allocator> &,
148  const boost::json::string &);
149 
150 template <typename char_t, typename traits, typename allocator>
151 bool operator!=(const boost::json::string &,
152  const basic_string<char_t, traits, allocator> &);
153 
154 template <typename allocator_type, int indent_size = 2>
155 void pretty_print(std::ostream &, const value<allocator_type> &);
156 
157 template <typename allocator_type>
158 std::string serialize(const value<allocator_type> &);
159 
160 template <typename allocator_type>
161 std::string serialize(const object<allocator_type> &);
162 
163 template <typename allocator_type>
164 std::string serialize(const array<allocator_type> &);
165 
166 template <typename char_type, typename traits, typename allocator_type>
167 std::string serialize(const basic_string<char_type, traits, allocator_type> &);
168 
169 template <typename allocator_type>
170 std::ostream &operator<<(std::ostream &, const value<allocator_type> &);
171 
172 template <typename allocator_type>
173 std::ostream &operator<<(std::ostream &, const object<allocator_type> &);
174 
175 template <typename allocator_type>
176 std::ostream &operator<<(std::ostream &, const array<allocator_type> &);
177 
178 template <typename allocator_type = std::allocator<std::byte>>
179 value<allocator_type> parse(std::string_view,
180  const allocator_type &allocator = allocator_type());
181 
182 template <typename T, typename allocator_type = std::allocator<std::byte>>
183 value<allocator_type> value_from(
184  T &&, const allocator_type &allocator = allocator_type());
185 
186 template <typename T, typename allocator_type>
187 T value_to(const value<allocator_type> &);
188 
189 namespace jsndtl {
190 
191 template <typename allocator_type, typename other_value_type>
192 bool general_value_equal(const value<allocator_type> &,
193  const other_value_type &) noexcept;
194 
195 template <typename char_t, typename traits, typename allocator,
196  typename other_string_type>
197 bool general_string_equal(const basic_string<char_t, traits, allocator> &,
198  const other_string_type &) noexcept;
199 
200 template <typename allocator_type, typename other_array_type>
201 bool general_array_equal(const array<allocator_type> &,
202  const other_array_type &) noexcept;
203 
204 template <typename allocator_type, typename other_object_type>
205 bool general_object_equal(const object<allocator_type> &,
206  const other_object_type &) noexcept;
207 
208 template <typename char_type, typename char_traits, typename allocator_type,
209  typename other_key_value_pair_type>
211  const key_value_pair<char_type, char_traits, allocator_type> &,
212  const other_key_value_pair_type &) noexcept;
213 } // namespace jsndtl
214 
215 #endif // DOXYGEN_SKIP
216 
217 } // namespace metall::json
218 
219 #endif // METALL_JSON_JSON_FWD_HPP
boost::container::basic_string< CharT, Traits, Allocator > basic_string
A string container that uses Metall as its default allocator.
Definition: string.hpp:19
bool general_value_equal(const value< allocator_type > &value, const other_value_type &other_value) noexcept
Provides 'equal' calculation for other value types that have the same interface as the value class.
Definition: value.hpp:28
bool general_object_equal(const object< allocator_type > &object, const other_object_type &other_object) noexcept
Provides 'equal' calculation for other object types that have the same interface as the object class.
Definition: object.hpp:38
bool general_string_equal(const basic_string< char_t, traits, allocator > &string, const other_string_type &other_string) noexcept
Definition: string.hpp:17
bool general_array_equal(const array< allocator_type > &array, const other_array_type &other_array) noexcept
Provides 'equal' calculation for other array types that have the same interface as the array class.
Definition: array.hpp:28
bool general_key_value_pair_equal(const key_value_pair< char_type, char_traits, allocator_type > &key_value, const other_key_value_pair_type &other_key_value) noexcept
Provides 'equal' calculation for other key-value types that have the same interface as the object cla...
Definition: key_value_pair.hpp:26
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::monostate null_type
JSON null type.
Definition: json_fwd.hpp:39
bool operator==(const key_value_pair< char_type, char_traits, allocator_type > &key_value, const bj::key_value_pair &bj_key_value)
Definition: equal.hpp:18
void swap(array< allocator_type > &lhd, array< allocator_type > &rhd) noexcept
Swap value instances.
Definition: array.hpp:193
void pretty_print(std::ostream &os, const value< allocator_type > &json_value)
Pretty-prints a JSON value.
Definition: pretty_print.hpp:75
bool operator!=(const key_value_pair< char_type, char_traits, allocator_type > &key_value, const bj::key_value_pair &bj_key_value)
Definition: equal.hpp:32
std::ostream & operator<<(std::ostream &os, const value< allocator_type > &val)
Definition: serialize.hpp:51
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
T value_to(const mj::value< allocator_type > &value)
Convert a JSON value to another data type.
Definition: value_to.hpp:72
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
basic_string< char, std::char_traits< char >, allocator_type > string
JSON string.
Definition: json_fwd.hpp:48