JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
functional.hpp
Go to the documentation of this file.
1
/** \file jsonv/functional.hpp
2
* A collection of function objects a la `<functional>`.
3
*
4
* Copyright (c) 2015 by Travis Gockel. All rights reserved.
5
*
6
* This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
7
* as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
8
* version.
9
*
10
* \author Travis Gockel (travis@gockelhut.com)
11
**/
12
#pragma once
13
14
#include <
jsonv/config.hpp
>
15
16
#include <functional>
17
#include <string_view>
18
19
namespace
jsonv
20
{
21
22
class
value;
23
24
/** \addtogroup Algorithm
25
* \{
26
**/
27
28
/** Compares a \c value to another using the standard-issue \c value::compare function. **/
29
struct
value_compare
30
{
31
using
first_argument_type
=
value
;
32
using
second_argument_type
=
value
;
33
using
result_type = int;
34
35
JSONV_NODISCARD
36
int
operator()(
const
value
& a,
const
value
& b)
const
;
37
};
38
39
/** Compares two values, ignoring the case for any \c value with \c kind::string. This does \e not ignore case for the
40
* keys of objects.
41
**/
42
struct
value_compare_icase
43
{
44
using
first_argument_type
=
value
;
45
using
second_argument_type
=
value
;
46
using
result_type = int;
47
48
JSONV_NODISCARD
49
int
operator()(
const
value
& a,
const
value
& b)
const
;
50
};
51
52
template
<
typename
FCompare,
typename
FResult>
53
struct
basic_value_binary_predicate
:
54
private
FCompare,
55
private
FResult
56
{
57
using
first_argument_type
=
value
;
58
using
second_argument_type
=
value
;
59
using
result_type = bool;
60
61
JSONV_NODISCARD
62
bool
operator()(
const
value
& a,
const
value
& b)
const
63
{
64
return
FResult::operator()(FCompare::operator()(a, b), 0);
65
}
66
};
67
68
using
value_equal_to
=
basic_value_binary_predicate<value_compare, std::equal_to<int>
>;
69
using
value_equal_to_icase
=
basic_value_binary_predicate<value_compare_icase, std::equal_to<int>
>;
70
using
value_not_equal_to
=
basic_value_binary_predicate<value_compare, std::not_equal_to<int>
>;
71
using
value_not_equal_to_icase
=
basic_value_binary_predicate<value_compare_icase, std::not_equal_to<int>
>;
72
using
value_less
=
basic_value_binary_predicate<value_compare, std::less<int>
>;
73
using
value_less_icase
=
basic_value_binary_predicate<value_compare_icase, std::less<int>
>;
74
using
value_less_equal
=
basic_value_binary_predicate<value_compare, std::less_equal<int>
>;
75
using
value_less_equal_icase
=
basic_value_binary_predicate<value_compare_icase, std::less_equal<int>
>;
76
using
value_greater
=
basic_value_binary_predicate<value_compare, std::greater<int>
>;
77
using
value_greater_icase
=
basic_value_binary_predicate<value_compare_icase, std::greater<int>
>;
78
using
value_greater_equal
=
basic_value_binary_predicate<value_compare, std::greater_equal<int>
>;
79
using
value_greater_equal_icase
=
basic_value_binary_predicate<value_compare_icase, std::greater_equal<int>
>;
80
81
/** \} **/
82
83
namespace
detail
84
{
85
86
/// Compare \a a with a \c kind::string holding \a b, exactly as \c compare would compare the two -- without building a
87
/// \c value to hold \a b. Against any other kind the kinds alone decide, and against a string the text does.
88
///
89
/// This is how \c enum_adapter looks up a string read from JSON text in a table ordered by \c value_less, which is why
90
/// it has to agree with \c compare on every pair rather than merely on equality.
91
JSONV_NODISCARD
JSONV_PUBLIC
int
compare_text(
const
value
& a, std::string_view b);
92
93
/// \c compare_text with the case folding of \c compare_icase, for a table ordered by \c value_less_icase.
94
JSONV_NODISCARD
JSONV_PUBLIC
int
compare_text_icase(
const
value
& a, std::string_view b);
95
96
}
97
98
}
jsonv::value
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition
value.hpp:113
config.hpp
Copyright (c) 2014-2020 by Travis Gockel.
JSONV_NODISCARD
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
Definition
config.hpp:143
JSONV_PUBLIC
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
Definition
config.hpp:124
jsonv::basic_value_binary_predicate
Definition
functional.hpp:56
jsonv::value_compare_icase
Compares two values, ignoring the case for any value with kind::string.
Definition
functional.hpp:43
jsonv::value_compare
Compares a value to another using the standard-issue value::compare function.
Definition
functional.hpp:30
jsonv
functional.hpp
Generated by
1.9.8