-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson-value.cpp
More file actions
81 lines (67 loc) · 1.39 KB
/
json-value.cpp
File metadata and controls
81 lines (67 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "json-value.h"
#include <iomanip>
#include <iostream>
#include <boost/range/algorithm/equal.hpp>
namespace pyjamas
{
namespace {
struct JsonValueEqualityComparator
{
template<class T>
bool operator()( const T& a, const T& b ) const
{
return a == b;
}
};
}
bool operator==( const JsonValue& a, const JsonValue& b )
{
return a.value == b.value;
}
bool operator==( const array& a, const array& b )
{
return boost::equal( a.children, b.children );
}
bool operator!=( const array& a, const array& b )
{
return !(a == b);
}
std::ostream& operator<<( std::ostream& os, null )
{
return os << "null";
}
std::ostream& operator<<( std::ostream& os, const boolean& b )
{
return os << std::boolalpha << b.value;
}
std::ostream& operator<<( std::ostream& os, const array& arr )
{
os << "[";
bool first = true;
for (const auto& v : arr.children)
{
if (first)
first = false;
else
os << ", ";
os << v;
}
return os << "]";
}
namespace {
struct JsonValuePrinter
{
template< class T >
void operator()( const T& v ) const
{
*out << v;
}
std::ostream* out;
};
}
std::ostream& operator<<( std::ostream& os, const JsonValue& v )
{
boost::apply_visitor( JsonValuePrinter{ &os }, v.value );
return os;
}
}