|
5 | 5 | #include <ostream> |
6 | 6 | #include <vector> |
7 | 7 |
|
8 | | - |
9 | | -struct scope_counter |
10 | | -{ |
| 8 | +struct scope_counter { |
11 | 9 | static std::size_t scope; |
12 | 10 |
|
13 | | - scope_counter () |
14 | | - { scope++; } |
| 11 | + scope_counter() { scope++; } |
15 | 12 |
|
16 | | - ~scope_counter () |
17 | | - { scope--; } |
| 13 | + ~scope_counter() { scope--; } |
18 | 14 |
|
19 | | - scope_counter (scope_counter const &rhs) = delete; |
| 15 | + scope_counter(scope_counter const &rhs) = delete; |
20 | 16 | }; |
21 | 17 |
|
22 | | -std::ostream &scope_indent (std::ostream &os, int line); |
| 18 | +std::ostream &scope_indent(std::ostream &os, int line); |
23 | 19 |
|
24 | 20 | #define SCOPE scope_counter const _scope |
25 | 21 |
|
26 | | - |
27 | 22 | #ifdef HAVE_GLOG |
28 | | -# include <glog/logging.h> |
29 | | -# undef LOG |
30 | | -# define LOG(KIND) scope_indent (COMPACT_GOOGLE_LOG_##KIND.stream(), __LINE__) |
| 23 | +#include <glog/logging.h> |
| 24 | +#undef LOG |
| 25 | +#define LOG(KIND) scope_indent(COMPACT_GOOGLE_LOG_##KIND.stream(), __LINE__) |
31 | 26 | #else |
32 | | -namespace google |
33 | | -{ |
34 | | - inline void InitGoogleLogging (char const *) { } |
35 | | - inline void ShutdownGoogleLogging () { } |
36 | | - inline void LogToStderr () { } |
37 | | -} |
| 27 | +namespace google { |
| 28 | +inline void InitGoogleLogging(char const *) {} |
| 29 | +inline void ShutdownGoogleLogging() {} |
| 30 | +inline void LogToStderr() {} |
| 31 | +} // namespace google |
38 | 32 |
|
39 | | -struct null_ostream |
40 | | - : std::ostream |
41 | | -{ |
42 | | -}; |
| 33 | +struct null_ostream : std::ostream {}; |
43 | 34 |
|
44 | | -# define LOG(LEVEL) (null_ostream ()) |
45 | | -# define LOG_ASSERT(cond) assert (cond) |
| 35 | +#define LOG(LEVEL) (null_ostream()) |
| 36 | +#define LOG_ASSERT(cond) assert(cond) |
46 | 37 | #endif |
47 | 38 |
|
48 | | -void output_hex (std::ostream &os, uint8_t const *data, size_t length); |
49 | | - |
| 39 | +void output_hex(std::ostream &os, uint8_t const *data, size_t length); |
50 | 40 |
|
51 | | -struct formatter |
52 | | -{ |
53 | | - formatter (formatter &&fmt) |
54 | | - : text_ (std::move (fmt.text_)) |
55 | | - { } |
| 41 | +struct formatter { |
| 42 | + formatter(formatter &&fmt) : text_(std::move(fmt.text_)) {} |
56 | 43 |
|
57 | | - explicit formatter (std::vector<char> text) |
58 | | - : text_ (std::move (text)) |
59 | | - { } |
| 44 | + explicit formatter(std::vector<char> text) : text_(std::move(text)) {} |
60 | 45 |
|
61 | | - friend std::ostream &operator << (std::ostream &os, formatter const &fmt); |
| 46 | + friend std::ostream &operator<<(std::ostream &os, formatter const &fmt); |
62 | 47 |
|
63 | 48 | private: |
64 | 49 | std::vector<char> const text_; |
65 | 50 | }; |
66 | 51 |
|
| 52 | +template <size_t N, typename... Args> |
| 53 | +formatter format(char const (&fmt)[N], Args const &...args) { |
| 54 | + std::vector<char> text(snprintf(nullptr, 0, fmt, args...) + 1); |
| 55 | + snprintf(text.data(), text.size(), fmt, args...); |
67 | 56 |
|
68 | | -template<size_t N, typename ...Args> |
69 | | -formatter |
70 | | -format (char const (&fmt)[N], Args const &...args) |
71 | | -{ |
72 | | - std::vector<char> text (snprintf (nullptr, 0, fmt, args...) + 1); |
73 | | - snprintf (text.data (), text.size (), fmt, args...); |
74 | | - |
75 | | - return formatter (std::move (text)); |
| 57 | + return formatter(std::move(text)); |
76 | 58 | } |
77 | 59 |
|
78 | | -template<std::size_t N> |
79 | | -std::ostream & |
80 | | -operator << (std::ostream &os, std::array<uint8_t, N> const &array) |
81 | | -{ |
82 | | - output_hex (os, array.data (), array.size ()); |
| 60 | +template <std::size_t N> |
| 61 | +std::ostream &operator<<(std::ostream &os, |
| 62 | + std::array<uint8_t, N> const &array) { |
| 63 | + output_hex(os, array.data(), array.size()); |
83 | 64 | return os; |
84 | 65 | } |
0 commit comments