Skip to content

Commit

Permalink
Merge pull request #218 from LLNL/feature/bugfix_json
Browse files Browse the repository at this point in the history
Required changes to support Boost 1.79
  • Loading branch information
KIwabuchi committed May 4, 2022
2 parents 27252c9 + 43f20ea commit ad244e9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 150 deletions.
137 changes: 0 additions & 137 deletions include/metall/container/experimental/json/detail/string_view.hpp

This file was deleted.

32 changes: 26 additions & 6 deletions include/metall/container/experimental/json/equal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ inline bool operator==(const array<allocator_type> &array, const bj::array &bj_a

template <typename allocator_type>
inline bool operator==(const bj::array &bj_array, const array<allocator_type> &array) {
return bj_array == array;
return array == bj_array;
}

template <typename allocator_type>
Expand All @@ -77,7 +77,7 @@ inline bool operator!=(const array<allocator_type> &array, const bj::array &bj_a

template <typename allocator_type>
inline bool operator!=(const bj::array &bj_array, const array<allocator_type> &array) {
return bj_array != array;
return array != bj_array;
}

template <typename allocator_type>
Expand All @@ -87,7 +87,7 @@ inline bool operator==(const compact_object<allocator_type> &object, const bj::o

template <typename allocator_type>
inline bool operator==(const bj::object &bj_object, const compact_object<allocator_type> &object) {
return bj_object == object;
return object == bj_object;
}

template <typename allocator_type>
Expand All @@ -97,7 +97,7 @@ inline bool operator!=(const compact_object<allocator_type> &object, const bj::o

template <typename allocator_type>
inline bool operator!=(const bj::object &bj_object, const compact_object<allocator_type> &object) {
return bj_object != object;
return object != bj_object;
}

template <typename allocator_type>
Expand All @@ -107,7 +107,7 @@ inline bool operator==(const indexed_object<allocator_type> &object, const bj::o

template <typename allocator_type>
inline bool operator==(const bj::object &bj_object, const indexed_object<allocator_type> &object) {
return bj_object == object;
return object == bj_object;
}

template <typename allocator_type>
Expand All @@ -117,7 +117,27 @@ inline bool operator!=(const indexed_object<allocator_type> &object, const bj::o

template <typename allocator_type>
inline bool operator!=(const bj::object &bj_object, const indexed_object<allocator_type> &object) {
return bj_object != object;
return object != bj_object;
}

template <typename char_t, typename traits, typename allocator>
inline bool operator==(const string<char_t, traits, allocator> &string, const bj::string &bj_string) {
return jsndtl::general_string_equal(string, bj_string);
}

template <typename char_t, typename traits, typename allocator>
inline bool operator==(const bj::string &bj_string, const string<char_t, traits, allocator> &string) {
return string == bj_string;
}

template <typename char_t, typename traits, typename allocator>
inline bool operator!=(const string<char_t, traits, allocator> &string, const bj::string &bj_string) {
return !(string == bj_string);
}

template <typename char_t, typename traits, typename allocator>
inline bool operator!=(const bj::string &bj_string, const string<char_t, traits, allocator> &string) {
return string != bj_string;
}
} // namespace metall::container::experimental::json
#endif //METALL_CONTAINER_EXPERIMENT_JSON_EQUAL_HPP
1 change: 1 addition & 0 deletions include/metall/container/experimental/json/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <metall/container/experimental/json/array.hpp>
#include <metall/container/experimental/json/key_value_pair.hpp>
#include <metall/container/experimental/json/value.hpp>
#include <metall/container/experimental/json/string.hpp>
#include <metall/container/experimental/json/parse.hpp>
#include <metall/container/experimental/json/serialize.hpp>
#include <metall/container/experimental/json/pretty_print.hpp>
Expand Down
10 changes: 10 additions & 0 deletions include/metall/container/experimental/json/json_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#define METALL_CONTAINER_EXPERIMENT_JSON_JSON_FWD_HPP

#include <variant>
#include <string>
#include <metall/container/string.hpp>

/// \namespace metall::container::experimental
/// \brief Namespace for Metall containers in an experimental phase.
Expand Down Expand Up @@ -42,6 +44,11 @@ class indexed_object;
template <typename allocator_type>
class compact_object;

template <typename char_t = char,
typename traits = std::char_traits<char_t>,
typename allocator = std::allocator<char_t>>
using string = metall::container::basic_string<char_t, traits, allocator>;

namespace jsndtl {
template <typename char_type, typename char_traits, typename allocator_type, typename other_key_value_pair_type>
inline bool general_key_value_pair_equal(const key_value_pair<char_type, char_traits, allocator_type> &,
Expand All @@ -55,6 +62,9 @@ inline bool general_indexed_object_equal(const indexed_object<allocator_type> &,

template <typename allocator_type, typename other_array_type>
inline bool general_array_equal(const array<allocator_type> &, const other_array_type &) noexcept;

template <typename allocator_type, typename other_string_type>
inline bool general_string_equal(const string<allocator_type> &, const other_string_type &) noexcept;
}
#endif // DOXYGEN_SKIP

Expand Down
22 changes: 22 additions & 0 deletions include/metall/container/experimental/json/string.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2022 Lawrence Livermore National Security, LLC and other Metall Project Developers.
// See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#ifndef METALL_CONTAINER_EXPERIMENT_STRING_HPP
#define METALL_CONTAINER_EXPERIMENT_STRING_HPP

#include <cstring>

namespace metall::container::experimental::json {
namespace jsndtl {

template <typename allocator_type, typename other_string_type>
inline bool general_string_equal(const string<allocator_type> &string, const other_string_type &other_string) noexcept {
return std::strcmp(string.c_str(), other_string.c_str()) == 0;
}

} // namespace jsndtl
} // namespace metall::container::experimental::json {

#endif //METALL_CONTAINER_EXPERIMENT_STRING_HPP
12 changes: 6 additions & 6 deletions include/metall/container/experimental/json/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <string_view>
#include <variant>

#include <metall/container/string.hpp>
#include <metall/container/experimental/json/json_fwd.hpp>

namespace metall::container::experimental::json {
Expand All @@ -24,7 +23,7 @@ namespace jsndtl {

/// \brief Provides 'equal' calculation for other value types that have the same interface as the value class.
template <typename allocator_type, typename other_value_type>
inline bool general_value_equal(const value<allocator_type>& value, const other_value_type& other_value) noexcept {
inline bool general_value_equal(const value<allocator_type> &value, const other_value_type &other_value) noexcept {
if (other_value.is_null()) {
return value.is_null();
} else if (other_value.is_bool()) {
Expand All @@ -34,7 +33,8 @@ inline bool general_value_equal(const value<allocator_type>& value, const other_
return value.as_int64() == other_value.as_int64();
}
if (value.is_uint64()) {
return (other_value.as_int64() < 0) ? false : value.as_uint64() == static_cast<std::uint64_t>(other_value.as_int64());
return (other_value.as_int64() < 0) ? false : value.as_uint64()
== static_cast<std::uint64_t>(other_value.as_int64());
}
return false;
} else if (other_value.is_uint64()) {
Expand Down Expand Up @@ -66,9 +66,9 @@ template <typename _allocator_type = std::allocator<std::byte>>
class value {
public:
using allocator_type = _allocator_type;
using string_type = mc::basic_string<char,
std::char_traits<char>,
typename std::allocator_traits<allocator_type>::template rebind_alloc<char>>;
using string_type = string<char,
std::char_traits<char>,
typename std::allocator_traits<allocator_type>::template rebind_alloc<char>>;
using object_type = object<_allocator_type>;
using array_type = array<_allocator_type>;

Expand Down
2 changes: 1 addition & 1 deletion include/metall/container/experimental/json/value_to.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inline void value_to_impl_helper(const mj::value<allocator_type> &input_value, b
} else if (input_value.is_double()) {
*out_bj_value = input_value.as_double();
} else if (input_value.is_string()) {
*out_bj_value = input_value.as_string();
*out_bj_value = input_value.as_string().c_str();
} else if (input_value.is_array()) {
bj::array bj_array;
for (const auto &elem : input_value.as_array()) {
Expand Down

0 comments on commit ad244e9

Please sign in to comment.