Skip to content

Commit b5e1fe8

Browse files
committed
Apply the formatting specified in .clang-format file.
$ clang-format --version clang-format version 7.0.0 (tags/google/stable/2018-01-11) $ clang-format -i --style=file $(find . -name '*.cpp' -o -name '*.h')
1 parent abd39e7 commit b5e1fe8

File tree

16 files changed

+1188
-1297
lines changed

16 files changed

+1188
-1297
lines changed

include/json/allocator.h

Lines changed: 63 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -12,86 +12,77 @@
1212
#pragma pack(push, 8)
1313

1414
namespace Json {
15-
template<typename T>
16-
class SecureAllocator {
17-
public:
18-
// Type definitions
19-
using value_type = T;
20-
using pointer = T*;
21-
using const_pointer = const T*;
22-
using reference = T&;
23-
using const_reference = const T&;
24-
using size_type = std::size_t;
25-
using difference_type = std::ptrdiff_t;
26-
27-
/**
28-
* Allocate memory for N items using the standard allocator.
29-
*/
30-
pointer allocate(size_type n) {
31-
// allocate using "global operator new"
32-
return static_cast<pointer>(::operator new(n * sizeof(T)));
33-
}
34-
35-
/**
36-
* Release memory which was allocated for N items at pointer P.
37-
*
38-
* The memory block is filled with zeroes before being released.
39-
* The pointer argument is tagged as "volatile" to prevent the
40-
* compiler optimizing out this critical step.
41-
*/
42-
void deallocate(volatile pointer p, size_type n) {
43-
std::memset(p, 0, n * sizeof(T));
44-
// free using "global operator delete"
45-
::operator delete(p);
46-
}
47-
48-
/**
49-
* Construct an item in-place at pointer P.
50-
*/
51-
template<typename... Args>
52-
void construct(pointer p, Args&&... args) {
53-
// construct using "placement new" and "perfect forwarding"
54-
::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
55-
}
56-
57-
size_type max_size() const {
58-
return size_t(-1) / sizeof(T);
59-
}
60-
61-
pointer address( reference x ) const {
62-
return std::addressof(x);
63-
}
64-
65-
const_pointer address( const_reference x ) const {
66-
return std::addressof(x);
67-
}
68-
69-
/**
70-
* Destroy an item in-place at pointer P.
71-
*/
72-
void destroy(pointer p) {
73-
// destroy using "explicit destructor"
74-
p->~T();
75-
}
76-
77-
// Boilerplate
78-
SecureAllocator() {}
79-
template<typename U> SecureAllocator(const SecureAllocator<U>&) {}
80-
template<typename U> struct rebind { using other = SecureAllocator<U>; };
15+
template <typename T> class SecureAllocator {
16+
public:
17+
// Type definitions
18+
using value_type = T;
19+
using pointer = T*;
20+
using const_pointer = const T*;
21+
using reference = T&;
22+
using const_reference = const T&;
23+
using size_type = std::size_t;
24+
using difference_type = std::ptrdiff_t;
25+
26+
/**
27+
* Allocate memory for N items using the standard allocator.
28+
*/
29+
pointer allocate(size_type n) {
30+
// allocate using "global operator new"
31+
return static_cast<pointer>(::operator new(n * sizeof(T)));
32+
}
33+
34+
/**
35+
* Release memory which was allocated for N items at pointer P.
36+
*
37+
* The memory block is filled with zeroes before being released.
38+
* The pointer argument is tagged as "volatile" to prevent the
39+
* compiler optimizing out this critical step.
40+
*/
41+
void deallocate(volatile pointer p, size_type n) {
42+
std::memset(p, 0, n * sizeof(T));
43+
// free using "global operator delete"
44+
::operator delete(p);
45+
}
46+
47+
/**
48+
* Construct an item in-place at pointer P.
49+
*/
50+
template <typename... Args> void construct(pointer p, Args&&... args) {
51+
// construct using "placement new" and "perfect forwarding"
52+
::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
53+
}
54+
55+
size_type max_size() const { return size_t(-1) / sizeof(T); }
56+
57+
pointer address(reference x) const { return std::addressof(x); }
58+
59+
const_pointer address(const_reference x) const { return std::addressof(x); }
60+
61+
/**
62+
* Destroy an item in-place at pointer P.
63+
*/
64+
void destroy(pointer p) {
65+
// destroy using "explicit destructor"
66+
p->~T();
67+
}
68+
69+
// Boilerplate
70+
SecureAllocator() {}
71+
template <typename U> SecureAllocator(const SecureAllocator<U>&) {}
72+
template <typename U> struct rebind { using other = SecureAllocator<U>; };
8173
};
8274

83-
84-
template<typename T, typename U>
75+
template <typename T, typename U>
8576
bool operator==(const SecureAllocator<T>&, const SecureAllocator<U>&) {
86-
return true;
77+
return true;
8778
}
8879

89-
template<typename T, typename U>
80+
template <typename T, typename U>
9081
bool operator!=(const SecureAllocator<T>&, const SecureAllocator<U>&) {
91-
return false;
82+
return false;
9283
}
9384

94-
} //namespace Json
85+
} // namespace Json
9586

9687
#pragma pack(pop)
9788

include/json/assertions.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
77
#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
88

9-
#include <stdlib.h>
109
#include <sstream>
10+
#include <stdlib.h>
1111

1212
#if !defined(JSON_IS_AMALGAMATION)
1313
#include "config.h"
@@ -20,30 +20,35 @@
2020
#if JSON_USE_EXCEPTION
2121

2222
// @todo <= add detail about condition in exception
23-
# define JSON_ASSERT(condition) \
24-
{if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
23+
#define JSON_ASSERT(condition) \
24+
{ \
25+
if (!(condition)) { \
26+
Json::throwLogicError("assert json failed"); \
27+
} \
28+
}
2529

26-
# define JSON_FAIL_MESSAGE(message) \
30+
#define JSON_FAIL_MESSAGE(message) \
2731
{ \
28-
JSONCPP_OSTRINGSTREAM oss; oss << message; \
32+
JSONCPP_OSTRINGSTREAM oss; \
33+
oss << message; \
2934
Json::throwLogicError(oss.str()); \
3035
abort(); \
3136
}
3237

3338
#else // JSON_USE_EXCEPTION
3439

35-
# define JSON_ASSERT(condition) assert(condition)
40+
#define JSON_ASSERT(condition) assert(condition)
3641

3742
// The call to assert() will show the failure message in debug builds. In
3843
// release builds we abort, for a core-dump or debugger.
39-
# define JSON_FAIL_MESSAGE(message) \
44+
#define JSON_FAIL_MESSAGE(message) \
4045
{ \
41-
JSONCPP_OSTRINGSTREAM oss; oss << message; \
46+
JSONCPP_OSTRINGSTREAM oss; \
47+
oss << message; \
4248
assert(false && oss.str().c_str()); \
4349
abort(); \
4450
}
4551

46-
4752
#endif
4853

4954
#define JSON_ASSERT_MESSAGE(condition, message) \

include/json/config.h

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#ifndef JSON_CONFIG_H_INCLUDED
77
#define JSON_CONFIG_H_INCLUDED
88
#include <stddef.h>
9-
#include <string> //typedef String
109
#include <stdint.h> //typedef int64_t, uint64_t
10+
#include <string> //typedef String
1111

1212
/// If defined, indicates that json library is embedded in CppTL library.
1313
//# define JSON_IN_CPPTL 1
@@ -60,47 +60,47 @@
6060
// #define JSON_NO_INT64 1
6161

6262
#if defined(_MSC_VER) // MSVC
63-
# if _MSC_VER <= 1200 // MSVC 6
64-
// Microsoft Visual Studio 6 only support conversion from __int64 to double
65-
// (no conversion from unsigned __int64).
66-
# define JSON_USE_INT64_DOUBLE_CONVERSION 1
67-
// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
68-
// characters in the debug information)
69-
// All projects I've ever seen with VS6 were using this globally (not bothering
70-
// with pragma push/pop).
71-
# pragma warning(disable : 4786)
72-
# endif // MSVC 6
73-
74-
# if _MSC_VER >= 1500 // MSVC 2008
75-
/// Indicates that the following function is deprecated.
76-
# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
77-
# endif
63+
#if _MSC_VER <= 1200 // MSVC 6
64+
// Microsoft Visual Studio 6 only support conversion from __int64 to double
65+
// (no conversion from unsigned __int64).
66+
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
67+
// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
68+
// characters in the debug information)
69+
// All projects I've ever seen with VS6 were using this globally (not bothering
70+
// with pragma push/pop).
71+
#pragma warning(disable : 4786)
72+
#endif // MSVC 6
73+
74+
#if _MSC_VER >= 1500 // MSVC 2008
75+
/// Indicates that the following function is deprecated.
76+
#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
77+
#endif
7878

7979
#endif // defined(_MSC_VER)
8080

8181
// In c++11 the override keyword allows you to explicitly define that a function
8282
// is intended to override the base-class version. This makes the code more
8383
// manageable and fixes a set of common hard-to-find bugs.
8484
#if __cplusplus >= 201103L
85-
# define JSONCPP_OVERRIDE override
86-
# define JSONCPP_NOEXCEPT noexcept
87-
# define JSONCPP_OP_EXPLICIT explicit
85+
#define JSONCPP_OVERRIDE override
86+
#define JSONCPP_NOEXCEPT noexcept
87+
#define JSONCPP_OP_EXPLICIT explicit
8888
#elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900
89-
# define JSONCPP_OVERRIDE override
90-
# define JSONCPP_NOEXCEPT throw()
91-
# if _MSC_VER >= 1800 // MSVC 2013
92-
# define JSONCPP_OP_EXPLICIT explicit
93-
# else
94-
# define JSONCPP_OP_EXPLICIT
95-
# endif
89+
#define JSONCPP_OVERRIDE override
90+
#define JSONCPP_NOEXCEPT throw()
91+
#if _MSC_VER >= 1800 // MSVC 2013
92+
#define JSONCPP_OP_EXPLICIT explicit
93+
#else
94+
#define JSONCPP_OP_EXPLICIT
95+
#endif
9696
#elif defined(_MSC_VER) && _MSC_VER >= 1900
97-
# define JSONCPP_OVERRIDE override
98-
# define JSONCPP_NOEXCEPT noexcept
99-
# define JSONCPP_OP_EXPLICIT explicit
97+
#define JSONCPP_OVERRIDE override
98+
#define JSONCPP_NOEXCEPT noexcept
99+
#define JSONCPP_OP_EXPLICIT explicit
100100
#else
101-
# define JSONCPP_OVERRIDE
102-
# define JSONCPP_NOEXCEPT throw()
103-
# define JSONCPP_OP_EXPLICIT
101+
#define JSONCPP_OVERRIDE
102+
#define JSONCPP_NOEXCEPT throw()
103+
#define JSONCPP_OP_EXPLICIT
104104
#endif
105105

106106
#ifndef JSON_HAS_RVALUE_REFERENCES
@@ -112,12 +112,12 @@
112112
#ifdef __clang__
113113
#if __has_feature(cxx_rvalue_references)
114114
#define JSON_HAS_RVALUE_REFERENCES 1
115-
#endif // has_feature
115+
#endif // has_feature
116116

117117
#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
118118
#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
119119
#define JSON_HAS_RVALUE_REFERENCES 1
120-
#endif // GXX_EXPERIMENTAL
120+
#endif // GXX_EXPERIMENTAL
121121

122122
#endif // __clang__ || __GNUC__
123123

@@ -128,32 +128,32 @@
128128
#endif
129129

130130
#ifdef __clang__
131-
# if __has_extension(attribute_deprecated_with_message)
132-
# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
133-
# endif
131+
#if __has_extension(attribute_deprecated_with_message)
132+
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
133+
#endif
134134
#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
135-
# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
136-
# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
137-
# elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
138-
# define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
139-
# endif // GNUC version
135+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
136+
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
137+
#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
138+
#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
139+
#endif // GNUC version
140140
#endif // __clang__ || __GNUC__
141141

142142
#if !defined(JSONCPP_DEPRECATED)
143143
#define JSONCPP_DEPRECATED(message)
144144
#endif // if !defined(JSONCPP_DEPRECATED)
145145

146146
#if __GNUC__ >= 6
147-
# define JSON_USE_INT64_DOUBLE_CONVERSION 1
147+
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
148148
#endif
149149

150150
#if !defined(JSON_IS_AMALGAMATION)
151151

152-
# include "version.h"
152+
#include "version.h"
153153

154-
# if JSONCPP_USING_SECURE_MEMORY
155-
# include "allocator.h" //typedef Allocator
156-
# endif
154+
#if JSONCPP_USING_SECURE_MEMORY
155+
#include "allocator.h" //typedef Allocator
156+
#endif
157157

158158
#endif // if !defined(JSON_IS_AMALGAMATION)
159159

@@ -172,23 +172,28 @@ typedef unsigned __int64 UInt64;
172172
#else // if defined(_MSC_VER) // Other platforms, use long long
173173
typedef int64_t Int64;
174174
typedef uint64_t UInt64;
175-
#endif // if defined(_MSC_VER)
175+
#endif // if defined(_MSC_VER)
176176
typedef Int64 LargestInt;
177177
typedef UInt64 LargestUInt;
178178
#define JSON_HAS_INT64
179179
#endif // if defined(JSON_NO_INT64)
180180
#if JSONCPP_USING_SECURE_MEMORY
181-
#define JSONCPP_STRING std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
182-
#define JSONCPP_OSTRINGSTREAM std::basic_ostringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
183-
#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char>>
184-
#define JSONCPP_ISTRINGSTREAM std::basic_istringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
185-
#define JSONCPP_ISTREAM std::istream
181+
#define JSONCPP_STRING \
182+
std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
183+
#define JSONCPP_OSTRINGSTREAM \
184+
std::basic_ostringstream<char, std::char_traits<char>, \
185+
Json::SecureAllocator<char> >
186+
#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char> >
187+
#define JSONCPP_ISTRINGSTREAM \
188+
std::basic_istringstream<char, std::char_traits<char>, \
189+
Json::SecureAllocator<char> >
190+
#define JSONCPP_ISTREAM std::istream
186191
#else
187-
#define JSONCPP_STRING std::string
192+
#define JSONCPP_STRING std::string
188193
#define JSONCPP_OSTRINGSTREAM std::ostringstream
189-
#define JSONCPP_OSTREAM std::ostream
194+
#define JSONCPP_OSTREAM std::ostream
190195
#define JSONCPP_ISTRINGSTREAM std::istringstream
191-
#define JSONCPP_ISTREAM std::istream
196+
#define JSONCPP_ISTREAM std::istream
192197
#endif // if JSONCPP_USING_SECURE_MEMORY
193198
} // end namespace Json
194199

0 commit comments

Comments
 (0)