Files
allwpilib/upstream_utils/json_patches/0017-Add-operator.patch

68 lines
2.1 KiB
Diff
Raw Permalink Normal View History

2026-03-29 15:37:32 -07:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Johnson <johnson.peter@gmail.com>
Date: Fri, 3 Apr 2026 22:54:14 -0700
Subject: [PATCH 17/25] Add operator==
---
json.cpp | 26 ++++++++++++++++++++++++++
json.h | 6 ++++++
2 files changed, 32 insertions(+)
diff --git a/json.cpp b/json.cpp
2026-07-02 02:10:52 -04:00
index 84712da562ee6b1966bae788fbf32876eaec4cef..839c311017ccbb2f5ea8f85aab4965e9ce7af090 100644
2026-03-29 15:37:32 -07:00
--- a/json.cpp
+++ b/json.cpp
@@ -1361,4 +1361,30 @@ json::StatusToString(json::Status status)
}
}
+bool
+operator==(const json& lhs, const json& rhs) {
+ if (lhs.type_ != rhs.type_)
+ return false;
+ switch (lhs.type_) {
+ case json::Type::Null:
+ return true;
+ case json::Type::String:
+ return lhs.string_value == rhs.string_value;
+ case json::Type::Bool:
+ return lhs.bool_value == rhs.bool_value;
+ case json::Type::Int:
+ return lhs.long_value == rhs.long_value;
+ case json::Type::Float:
+ return lhs.float_value == rhs.float_value;
+ case json::Type::Double:
+ return lhs.double_value == rhs.double_value;
+ case json::Type::Array:
+ return lhs.array_value == rhs.array_value;
+ case json::Type::Object:
+ return lhs.object_value == rhs.object_value;
+ default:
+ ON_LOGIC_ERROR("Unhandled JSON type during equality comparison.");
+ }
+}
+
} // namespace wpi::util
diff --git a/json.h b/json.h
2026-07-02 02:10:52 -04:00
index c5f39687e68289adadb988df9cfd81c031266859..2f2bb7b3b0a265299a011e4e8011ea14065dca36 100644
2026-03-29 15:37:32 -07:00
--- a/json.h
+++ b/json.h
@@ -28,6 +28,7 @@ namespace wpi::util {
class json
{
+ friend bool operator==(const json& lhs, const json& rhs);
public:
using array_t = std::vector<json>;
using object_t = wpi::util::StringMap<json>;
@@ -241,4 +242,9 @@ class json
static Status parse(json&, const char*&, const char*, int, int);
};
+bool operator==(const json& lhs, const json& rhs);
+inline bool operator!=(const json& lhs, const json& rhs) {
+ return !(lhs == rhs);
+}
+
} // namespace wpi::util