12 #ifndef __JSONV_ALGORITHM_HPP_INCLUDED__ 13 #define __JSONV_ALGORITHM_HPP_INCLUDED__ 48 return va == vb ? 0 : va < vb ? -1 : 1;
70 return (std::abs(a - b) < (std::numeric_limits<double>::denorm_min() * 10.0)) ? 0
96 static int kindval(
kind k)
100 case jsonv::kind::null:
102 case jsonv::kind::boolean:
104 case jsonv::kind::integer:
105 case jsonv::kind::decimal:
107 case jsonv::kind::string:
109 case jsonv::kind::array:
111 case jsonv::kind::object:
123 template <
typename TCompareTraits>
129 if (
int kindcmp = traits.compare_kinds(a.
kind(), b.
kind()))
134 case jsonv::kind::null:
136 case jsonv::kind::boolean:
138 case jsonv::kind::integer:
140 if (b.
kind() == jsonv::kind::integer)
143 case jsonv::kind::decimal:
145 case jsonv::kind::string:
147 case jsonv::kind::array:
152 if (
int cmp =
compare(*aiter, *biter, traits))
157 case jsonv::kind::object:
159 if (
int objmetacmp = traits.compare_objects_meta(a, b))
166 if (
int cmp = traits.compare_object_keys(aiter->first, biter->first))
168 if (
int cmp =
compare(aiter->second, biter->second, traits))
258 const std::function<
void (
const path&,
const value&)>& func,
259 const path& base_path,
260 bool leafs_only =
false 272 const std::function<
void (
const path&,
const value&)>& func,
273 bool leafs_only =
false 306 using same_key_function = std::function<value (path&&, value&&, value&&)>;
308 using type_conflict_function = std::function<value (path&&, value&&, value&&)>;
312 type_conflict_function type_conflict
317 same_key_function same_key;
319 type_conflict_function type_conflict;
325 virtual value resolve_type_conflict(
path&& current_path,
value&& a,
value&& b)
const override;
337 virtual value resolve_type_conflict(
path&& current_path,
value&& a,
value&& b)
const override;
349 virtual value resolve_type_conflict(
path&& current_path,
value&& a,
value&& b)
const override;
383 template <
typename... TValue>
386 value ab = merge_explicit(rules, current_path, std::move(a), std::move(b));
387 return merge_explicit(rules,
388 std::move(current_path),
391 std::forward<TValue>(rest)...
398 template <
typename... TValue>
403 std::forward<TValue>(values)...
410 template <
typename... TValue>
415 std::forward<TValue>(values)...
424 public std::runtime_error
440 code error_code()
const;
value same
Elements that were the same between the two halves of the diff.
JSONV_PUBLIC int compare(const value &a, const value &b)
Compare the values a and b with strict comparison traits.
value merge_recursive(TValue &&...values)
Merges all the provided values into a single value.
static int compare_kinds(kind a, kind b)
Compare two kinds a and b.
object_iterator end_object()
Get an iterator to the one past the end of this object.
bool as_boolean() const
Get this value as a boolean.
These rules throw an exception on all conflicts.
int64_t as_integer() const
Get this value as an integer.
static int compare_objects_meta(const value &, const value &)
Compare two objects before comparing the values.
Traits describing how to perform various aspects of comparison.
static int compare_object_keys(const std::string &a, const std::string &b)
Compare two strings used for the keys of objects.
value merge(TValue &&...values)
Merges all the provided values into a single value.
These rules will recursively merge everything they can and coerce all values.
array_iterator end_array()
Get an iterator to the end of this array.
Copyright (c) 2014-2019 by Travis Gockel.
const std::string & as_string() const
Get this value as a string.
JSONV_PUBLIC diff_result diff(value left, value right)
Find the differences and similarities between the structures of left and right.
JSONV_PUBLIC int compare_icase(const value &a, const value &b)
Compare the values a and b, but use case-insensitive matching on kind::string values.
static int compare_decimals(double a, double b)
Compare two decimal values.
Represents an exact path in some JSON structure.
value left
Elements that were unique to the left hand side of the diff.
JSONV_PUBLIC void validate(const value &val)
Check that the provided val is perfectly representable as a JSON string.
JSONV_PUBLIC void traverse(const value &tree, const std::function< void(const path &, const value &)> &func, bool leafs_only=false)
Recursively walk the provided tree and call func for each item in the tree.
object_iterator begin_object()
Get an iterator to the first key-value pair in this object.
The results of the diff operation.
static int compare_strings(const std::string &a, const std::string &b)
Compare two string values.
jsonv::kind kind() const
Get this value's kind.
kind
Describes the kind of data a value holds.
array_iterator begin_array()
Get an iterator to the beginning of this array.
Error thrown when an unrepresentable value is encountered in a JSON AST.
value right
Elements that were unique to the right hand side of the diff.
This class is used in merge_explicit for defining what the function should do in the cases of conflic...
An implementation of merge_rules that allows you to bind whatever functions you want to resolve confl...
JSONV_PUBLIC value map(const std::function< value(value)> &func, value &&input)
Run a function over the values in the input.
code
Special code for describing the error encountered.
JSONV_PUBLIC value merge_explicit(const merge_rules &rules, path current_path, value a, value b)
Merges two values, a and b into a single value.
double as_decimal() const
Get this value as a decimal.
static int compare_integers(std::int64_t a, std::int64_t b)
Compare two integer values.
#define JSONV_PUBLIC
This function or class is part of the public API for JsonVoorhees.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
static int compare_booleans(bool a, bool b)
Compare two boolean values.
Copyright (c) 2012-2018 by Travis Gockel.