Skip to content

Commit 4b9d903

Browse files
committed
Continue comparison operators.
1 parent 36c4416 commit 4b9d903

File tree

16 files changed

+588
-329
lines changed

16 files changed

+588
-329
lines changed

include/tao/json.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#include "json/from_string.hh"
1313
#include "json/parse_file.hh"
1414

15+
#include "json/compare_null.hh"
16+
#include "json/compare_bool.hh"
17+
#include "json/compare_int64.hh"
18+
#include "json/compare_double.hh"
19+
#include "json/compare_string.hh"
20+
#include "json/compare_array.hh"
21+
#include "json/compare_object.hh"
22+
1523
// Include this if required to enable
1624
// C++11 user defined JSON literals that
1725
// can be used like "[null]"_json .

include/tao/json/compare.hh

Lines changed: 0 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -40,166 +40,6 @@ namespace tao
4040
return ! ( l == r );
4141
}
4242

43-
inline bool operator== ( const value & l, const std::nullptr_t )
44-
{
45-
return l.is_null();
46-
}
47-
48-
inline bool operator== ( const std::nullptr_t, const value & r )
49-
{
50-
return r.is_null();
51-
}
52-
53-
inline bool operator!= ( const value & l, const std::nullptr_t )
54-
{
55-
return ! l.is_null();
56-
}
57-
58-
inline bool operator!= ( const std::nullptr_t, const value & r )
59-
{
60-
return ! r.is_null();
61-
}
62-
63-
inline bool operator== ( const value & l, const bool b )
64-
{
65-
return l.is_bool() && ( l.unsafe_bool() == b );
66-
}
67-
68-
inline bool operator== ( const bool b, const value & r )
69-
{
70-
return r == b;
71-
}
72-
73-
inline bool operator== ( const value & l, const signed char i )
74-
{
75-
return l.is_int64() && ( l.unsafe_int64() == i );
76-
}
77-
78-
inline bool operator== ( const signed char i, const value & r )
79-
{
80-
return r == i;
81-
}
82-
83-
inline bool operator== ( const value & l, const unsigned char i )
84-
{
85-
return l.is_int64() && ( l.unsafe_int64() == i );
86-
}
87-
88-
inline bool operator== ( const unsigned char i, const value & r )
89-
{
90-
return r == i;
91-
}
92-
93-
inline bool operator== ( const value & l, const signed short i )
94-
{
95-
return l.is_int64() && ( l.unsafe_int64() == i );
96-
}
97-
98-
inline bool operator== ( const signed short i, const value & r )
99-
{
100-
return r == i;
101-
}
102-
103-
inline bool operator== ( const value & l, const unsigned short i )
104-
{
105-
return l.is_int64() && ( l.unsafe_int64() == i );
106-
}
107-
108-
inline bool operator== ( const unsigned short i, const value & r )
109-
{
110-
return r == i;
111-
}
112-
113-
inline bool operator== ( const value & l, const signed int i )
114-
{
115-
return l.is_int64() && ( l.unsafe_int64() == i );
116-
}
117-
118-
inline bool operator== ( const signed int i, const value & r )
119-
{
120-
return r == i;
121-
}
122-
123-
inline bool operator== ( const value & l, const unsigned int i )
124-
{
125-
return l.is_int64() && ( l.unsafe_int64() == i );
126-
}
127-
128-
inline bool operator== ( const unsigned int i, const value & r )
129-
{
130-
return r == i;
131-
}
132-
133-
inline bool operator== ( const value & l, const signed long i )
134-
{
135-
return l.is_int64() && ( l.unsafe_int64() == i );
136-
}
137-
138-
inline bool operator== ( const signed long i, const value & r )
139-
{
140-
return r == i;
141-
}
142-
143-
inline bool operator== ( const value & l, const signed long long i )
144-
{
145-
return l.is_int64() && ( l.unsafe_int64() == i );
146-
}
147-
148-
inline bool operator== ( const signed long long i, const value & r )
149-
{
150-
return r == i;
151-
}
152-
153-
inline bool operator== ( const value & l, const double d )
154-
{
155-
return l.is_double() && ( l.unsafe_double() == d );
156-
}
157-
158-
inline bool operator== ( const double d, const value & r )
159-
{
160-
return r == d;
161-
}
162-
163-
inline bool operator== ( const value & l, const char * s )
164-
{
165-
return l.is_string() && ( l.unsafe_string() == s );
166-
}
167-
168-
inline bool operator== ( const char * s, const value & r )
169-
{
170-
return r == s;
171-
}
172-
173-
inline bool operator== ( const value & l, const std::string & s )
174-
{
175-
return l.is_string() && ( l.unsafe_string() == s );
176-
}
177-
178-
inline bool operator== ( const std::string & s, const value & r )
179-
{
180-
return r == s;
181-
}
182-
183-
inline bool operator== ( const value & l, const std::vector< value > & v )
184-
{
185-
return l.is_array() && ( l.unsafe_array() == v );
186-
}
187-
188-
inline bool operator== ( const std::vector< value > & v, const value & r )
189-
{
190-
return r == v;
191-
}
192-
193-
inline bool operator== ( const value & l, const std::map< std::string, value > & v )
194-
{
195-
return l.is_object() && ( l.unsafe_object() == v );
196-
}
197-
198-
inline bool operator== ( const std::map< std::string, value > & v, const value & r )
199-
{
200-
return r == v;
201-
}
202-
20343
} // json
20444

20545
} // tao

include/tao/json/compare_array.hh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2015 Dr. Colin Hirsch
2+
// Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+
#ifndef TAOCPP_JSON_INCLUDE_COMPARE_ARRAY_HH
5+
#define TAOCPP_JSON_INCLUDE_COMPARE_ARRAY_HH
6+
7+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::ARRAY
8+
#define TAOCPP_JSON_COMPARE_DATA_TYPE std::vector< value >
9+
10+
#include "internal/compare_impl.hh"
11+
12+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
13+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
14+
15+
#endif

include/tao/json/compare_bool.hh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2015 Dr. Colin Hirsch
2+
// Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+
#ifndef TAOCPP_JSON_INCLUDE_COMPARE_BOOL_HH
5+
#define TAOCPP_JSON_INCLUDE_COMPARE_BOOL_HH
6+
7+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::BOOL_
8+
#define TAOCPP_JSON_COMPARE_DATA_TYPE bool
9+
10+
#include "internal/compare_impl.hh"
11+
12+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
13+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
14+
15+
#endif

include/tao/json/compare_double.hh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2015 Dr. Colin Hirsch
2+
// Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+
#ifndef TAOCPP_JSON_INCLUDE_COMPARE_DOUBLE_HH
5+
#define TAOCPP_JSON_INCLUDE_COMPARE_DOUBLE_HH
6+
7+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::DOUBLE
8+
#define TAOCPP_JSON_COMPARE_DATA_TYPE double
9+
10+
#include "internal/compare_impl.hh"
11+
12+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
13+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
14+
15+
#endif

include/tao/json/compare_int64.hh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2015 Dr. Colin Hirsch
2+
// Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+
#ifndef TAOCPP_JSON_INCLUDE_COMPARE_INT64_HH
5+
#define TAOCPP_JSON_INCLUDE_COMPARE_INT64_HH
6+
7+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
8+
#define TAOCPP_JSON_COMPARE_DATA_TYPE signed char
9+
10+
#include "internal/compare_impl.hh"
11+
12+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
13+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
14+
15+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
16+
#define TAOCPP_JSON_COMPARE_DATA_TYPE unsigned char
17+
18+
#include "internal/compare_impl.hh"
19+
20+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
21+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
22+
23+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
24+
#define TAOCPP_JSON_COMPARE_DATA_TYPE signed short
25+
26+
#include "internal/compare_impl.hh"
27+
28+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
29+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
30+
31+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
32+
#define TAOCPP_JSON_COMPARE_DATA_TYPE unsigned short
33+
34+
#include "internal/compare_impl.hh"
35+
36+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
37+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
38+
39+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
40+
#define TAOCPP_JSON_COMPARE_DATA_TYPE signed int
41+
42+
#include "internal/compare_impl.hh"
43+
44+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
45+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
46+
47+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
48+
#define TAOCPP_JSON_COMPARE_DATA_TYPE unsigned int
49+
50+
#include "internal/compare_impl.hh"
51+
52+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
53+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
54+
55+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
56+
#define TAOCPP_JSON_COMPARE_DATA_TYPE signed long
57+
58+
#include "internal/compare_impl.hh"
59+
60+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
61+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
62+
63+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::INT64
64+
#define TAOCPP_JSON_COMPARE_DATA_TYPE signed long long
65+
66+
#include "internal/compare_impl.hh"
67+
68+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
69+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
70+
71+
#endif

include/tao/json/compare_null.hh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2015 Dr. Colin Hirsch
2+
// Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+
#ifndef TAOCPP_JSON_INCLUDE_COMPARE_NULL_HH
5+
#define TAOCPP_JSON_INCLUDE_COMPARE_NULL_HH
6+
7+
namespace tao
8+
{
9+
namespace json
10+
{
11+
inline bool operator< ( const value & l, const std::nullptr_t )
12+
{
13+
return l.type() < type::NULL_;
14+
}
15+
16+
inline bool operator< ( const std::nullptr_t, const value & r )
17+
{
18+
return type::NULL_ < r.type();
19+
}
20+
21+
inline bool operator> ( const value & l, const std::nullptr_t )
22+
{
23+
return l.type() > type::NULL_;
24+
}
25+
26+
inline bool operator> ( const std::nullptr_t, const value & r )
27+
{
28+
return type::NULL_ > r.type();
29+
}
30+
31+
inline bool operator== ( const value & l, const std::nullptr_t )
32+
{
33+
return l.type() == type::NULL_;
34+
}
35+
36+
inline bool operator== ( const std::nullptr_t, const value & r )
37+
{
38+
return r.type() == type::NULL_;
39+
}
40+
41+
inline bool operator!= ( const value & l, const std::nullptr_t )
42+
{
43+
return l.type() != type::NULL_;
44+
}
45+
46+
inline bool operator!= ( const std::nullptr_t, const value & r )
47+
{
48+
return r.type() != type::NULL_;
49+
}
50+
51+
inline bool operator<= ( const value & l, const std::nullptr_t )
52+
{
53+
return l.type() <= type::NULL_;
54+
}
55+
56+
inline bool operator<= ( const std::nullptr_t, const value & r )
57+
{
58+
return r.type() <= type::NULL_;
59+
}
60+
61+
inline bool operator>= ( const value & l, const std::nullptr_t )
62+
{
63+
return l.type() >= type::NULL_;
64+
}
65+
66+
inline bool operator>= ( const std::nullptr_t, const value & r )
67+
{
68+
return r.type() >= type::NULL_;
69+
}
70+
71+
} // json
72+
73+
} // tao
74+
75+
#endif

include/tao/json/compare_object.hh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2015 Dr. Colin Hirsch
2+
// Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+
#ifndef TAOCPP_JSON_INCLUDE_COMPARE_OBJECT_HH
5+
#define TAOCPP_JSON_INCLUDE_COMPARE_OBJECT_HH
6+
7+
#define TAOCPP_JSON_COMPARE_ENUM_TYPE type::OBJECT
8+
#define TAOCPP_JSON_COMPARE_DATA_TYPE std::map< std::string, value >
9+
10+
#include "internal/compare_impl.hh"
11+
12+
#undef TAOCPP_JSON_COMPARE_ENUM_TYPE
13+
#undef TAOCPP_JSON_COMPARE_DATA_TYPE
14+
15+
#endif

0 commit comments

Comments
 (0)