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:
123template <
typename TCompareTraits>
134 case jsonv::kind::null:
136 case jsonv::kind::boolean:
137 return traits.compare_booleans(
a.as_boolean(),
b.as_boolean());
138 case jsonv::kind::integer:
140 if (
b.kind() == jsonv::kind::integer)
141 return traits.compare_integers(
a.as_integer(),
b.as_integer());
143 case jsonv::kind::decimal:
144 return traits.compare_decimals(
a.as_decimal(),
b.as_decimal());
145 case jsonv::kind::string:
146 return traits.compare_strings(
a.as_string(),
b.as_string());
147 case jsonv::kind::array:
149 auto aiter =
a.begin_array();
150 auto biter =
b.begin_array();
154 return aiter ==
a.end_array() ?
biter ==
b.end_array() ? 0 : -1
157 case jsonv::kind::object:
162 auto aiter =
a.begin_object();
163 auto biter =
b.begin_object();
171 return aiter ==
a.end_object() ?
biter ==
b.end_object() ? 0 : -1
310 type_conflict_function type_conflict
315 same_key_function same_key;
317 type_conflict_function type_conflict;
381template <
typename...
TValue>
386 std::move(current_path),
389 std::forward<TValue>(
rest)...
396template <
typename... TValue>
401 std::forward<TValue>(
values)...
408template <
typename... TValue>
413 std::forward<TValue>(
values)...
422 public std::runtime_error
An implementation of merge_rules that allows you to bind whatever functions you want to resolve confl...
virtual value resolve_same_key(path &¤t_path, value &&a, value &&b) const override
virtual value resolve_type_conflict(path &¤t_path, value &&a, value &&b) const override
An adapter for enumeration types.
This class is used in merge_explicit for defining what the function should do in the cases of conflic...
virtual value resolve_same_key(path &¤t_path, value &&a, value &&b) const =0
Called when merging a kind::object and the two objects share a key.
virtual value resolve_type_conflict(path &¤t_path, value &&a, value &&b) const =0
Called when a and b have kind values which are incompatible for merging.
Represents an exact path in some JSON structure.
These rules will recursively merge everything they can and coerce all values.
virtual value resolve_type_conflict(path &¤t_path, value &&a, value &&b) const override
Calls coerce_merge to combine the values.
virtual value resolve_same_key(path &¤t_path, value &&a, value &&b) const override
Recursively calls merge_explicit with the two values.
These rules throw an exception on all conflicts.
virtual value resolve_same_key(path &¤t_path, value &&a, value &&b) const override
virtual value resolve_type_conflict(path &¤t_path, value &&a, value &&b) const override
Error thrown when an unrepresentable value is encountered in a JSON AST.
code
Special code for describing the error encountered.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
value same
Elements that were the same between the two halves of the diff.
value right
Elements that were unique to the right hand side of the diff.
value left
Elements that were unique to the left hand side of the diff.
int compare(const value &a, const value &b, const TCompareTraits &traits)
Compare the values a and b using the comparison traits.
JSONV_PUBLIC diff_result diff(value left, value right)
Find the differences and similarities between the structures of left and right.
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.
JSONV_PUBLIC value map(const std::function< value(const value &)> &func, const value &input)
Run a function over the values in the input.
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.
value merge(TValue &&... values)
Merges all the provided values into a single value.
value merge_recursive(TValue &&... values)
Merges all the provided values into a single value.
JSONV_PUBLIC void traverse(const value &tree, const std::function< void(const path &, const value &)> &func, const path &base_path, bool leafs_only=false)
Recursively walk the provided tree and call func for each item in the tree.
The results of the diff operation.
kind
Describes the kind of data a value holds.
Traits describing how to perform various aspects of comparison.
static int compare_strings(const std::string &a, const std::string &b)
Compare two string values.
static int compare_integers(std::int64_t a, std::int64_t b)
Compare two integer values.
static int compare_booleans(bool a, bool b)
Compare two boolean values.
static int compare_objects_meta(const value &, const value &)
Compare two objects before comparing the values.
static int compare_decimals(double a, double b)
Compare two decimal values.
static int compare_kinds(kind a, kind b)
Compare two kinds a and b.
static int compare_object_keys(const std::string &a, const std::string &b)
Compare two strings used for the keys of objects.
Copyright (c) 2012-2020 by Travis Gockel.