aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/json.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-01-22 12:02:54 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-01-22 12:02:54 +0200
commit7d5c863e01b4a70d5ef3614b91694cf080a420c9 (patch)
treeec6bd062bb7ca65770ddfe24628c4f7b0f24dc46 /libbuild2/json.hxx
parent677eb1e1017630a1d1abbb528d28b90110990ef4 (diff)
Add comparison
Diffstat (limited to 'libbuild2/json.hxx')
-rw-r--r--libbuild2/json.hxx24
1 files changed, 22 insertions, 2 deletions
diff --git a/libbuild2/json.hxx b/libbuild2/json.hxx
index 816b55c..6fc633c 100644
--- a/libbuild2/json.hxx
+++ b/libbuild2/json.hxx
@@ -26,9 +26,14 @@ namespace build2
// string and value. The latter allows us to use the JSON value itself as an
// element of a container.
//
- enum class json_type
+ // Note also that we don't assume that object members are in a sorted order
+ // (but do assume there are no duplicates). However, we could add an
+ // argument to signal that this is the case to speed up some functions, for
+ // example, compare().
+ //
+ enum class json_type: uint8_t
{
- null,
+ null, // Note: keep first for comparison.
boolean,
signed_number,
unsigned_number,
@@ -222,6 +227,21 @@ namespace build2
case json_type::object: container.~container_type (); break;
}
}
+
+ // Note that values of different types are never equal, except for
+ // signed/unsigned numbers. Null is equal to null and is less than any
+ // other value. Arrays are compared lexicographically. Object members are
+ // considered in the lexicographically-compared name-ascending order (see
+ // RFC8785). An absent member is less than a present member (even if it's
+ // null).
+ //
+ // Note that while it doesn't make much sense to compare members to
+ // non-members, we allow it with a non-member always being less than a
+ // member (even if null), unless ignore_name is true, in which case member
+ // names are ignored.
+ //
+ int
+ compare (const json_value&, bool ignore_name = false) const;
};
// Throws invalid_json_output.