Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: third_party/WebKit/Source/wtf/PrintStream.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 20 matching lines...) Expand all
31 #include "wtf/StdLibExtras.h" 31 #include "wtf/StdLibExtras.h"
32 #include "wtf/WTFExport.h" 32 #include "wtf/WTFExport.h"
33 #include <stdarg.h> 33 #include <stdarg.h>
34 34
35 namespace WTF { 35 namespace WTF {
36 36
37 class CString; 37 class CString;
38 class String; 38 class String;
39 39
40 class WTF_EXPORT PrintStream { 40 class WTF_EXPORT PrintStream {
41 USING_FAST_MALLOC(PrintStream); WTF_MAKE_NONCOPYABLE(PrintStream); 41 USING_FAST_MALLOC(PrintStream);
42 public: 42 WTF_MAKE_NONCOPYABLE(PrintStream);
43 PrintStream();
44 virtual ~PrintStream();
45 43
46 void printf(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3); 44 public:
47 virtual void vprintf(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(2, 0) = 0; 45 PrintStream();
46 virtual ~PrintStream();
48 47
49 // Typically a no-op for many subclasses of PrintStream, this is a hint that 48 void printf(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
50 // the implementation should flush its buffers if it had not done so already . 49 virtual void vprintf(const char* format, va_list)
51 virtual void flush(); 50 WTF_ATTRIBUTE_PRINTF(2, 0) = 0;
52 51
53 template <typename T> 52 // Typically a no-op for many subclasses of PrintStream, this is a hint that
54 void print(const T& value) 53 // the implementation should flush its buffers if it had not done so already.
55 { 54 virtual void flush();
56 printInternal(*this, value);
57 }
58 55
59 template <typename T1, typename... RemainingTypes> 56 template <typename T>
60 void print(const T1& value1, const RemainingTypes&... values) 57 void print(const T& value) {
61 { 58 printInternal(*this, value);
62 print(value1); 59 }
63 print(values...); 60
64 } 61 template <typename T1, typename... RemainingTypes>
62 void print(const T1& value1, const RemainingTypes&... values) {
63 print(value1);
64 print(values...);
65 }
65 }; 66 };
66 67
67 WTF_EXPORT void printInternal(PrintStream&, const char*); 68 WTF_EXPORT void printInternal(PrintStream&, const char*);
68 WTF_EXPORT void printInternal(PrintStream&, const CString&); 69 WTF_EXPORT void printInternal(PrintStream&, const CString&);
69 WTF_EXPORT void printInternal(PrintStream&, const String&); 70 WTF_EXPORT void printInternal(PrintStream&, const String&);
70 inline void printInternal(PrintStream& out, char* value) { printInternal(out, st atic_cast<const char*>(value)); } 71 inline void printInternal(PrintStream& out, char* value) {
71 inline void printInternal(PrintStream& out, CString& value) { printInternal(out, static_cast<const CString&>(value)); } 72 printInternal(out, static_cast<const char*>(value));
72 inline void printInternal(PrintStream& out, String& value) { printInternal(out, static_cast<const String&>(value)); } 73 }
74 inline void printInternal(PrintStream& out, CString& value) {
75 printInternal(out, static_cast<const CString&>(value));
76 }
77 inline void printInternal(PrintStream& out, String& value) {
78 printInternal(out, static_cast<const String&>(value));
79 }
73 WTF_EXPORT void printInternal(PrintStream&, bool); 80 WTF_EXPORT void printInternal(PrintStream&, bool);
74 WTF_EXPORT void printInternal(PrintStream&, int); 81 WTF_EXPORT void printInternal(PrintStream&, int);
75 WTF_EXPORT void printInternal(PrintStream&, unsigned); 82 WTF_EXPORT void printInternal(PrintStream&, unsigned);
76 WTF_EXPORT void printInternal(PrintStream&, long); 83 WTF_EXPORT void printInternal(PrintStream&, long);
77 WTF_EXPORT void printInternal(PrintStream&, unsigned long); 84 WTF_EXPORT void printInternal(PrintStream&, unsigned long);
78 WTF_EXPORT void printInternal(PrintStream&, long long); 85 WTF_EXPORT void printInternal(PrintStream&, long long);
79 WTF_EXPORT void printInternal(PrintStream&, unsigned long long); 86 WTF_EXPORT void printInternal(PrintStream&, unsigned long long);
80 WTF_EXPORT void printInternal(PrintStream&, float); 87 WTF_EXPORT void printInternal(PrintStream&, float);
81 WTF_EXPORT void printInternal(PrintStream&, double); 88 WTF_EXPORT void printInternal(PrintStream&, double);
82 89
83 template <typename T> 90 template <typename T>
84 void printInternal(PrintStream& out, const T& value) 91 void printInternal(PrintStream& out, const T& value) {
85 { 92 value.dump(out);
86 value.dump(out);
87 } 93 }
88 94
89 #define MAKE_PRINT_ADAPTOR(Name, Type, function) \ 95 #define MAKE_PRINT_ADAPTOR(Name, Type, function) \
90 class Name final { \ 96 class Name final { \
91 STACK_ALLOCATED(); \ 97 STACK_ALLOCATED(); \
92 public: \ 98 \
93 Name(const Type& value) \ 99 public: \
94 : m_value(value) \ 100 Name(const Type& value) : m_value(value) {} \
95 { \ 101 void dump(PrintStream& out) const { function(out, m_value); } \
96 } \ 102 \
97 void dump(PrintStream& out) const \ 103 private: \
98 { \ 104 Type m_value; \
99 function(out, m_value); \ 105 }
100 } \
101 private: \
102 Type m_value; \
103 }
104 106
105 #define MAKE_PRINT_METHOD_ADAPTOR(Name, Type, method) \ 107 #define MAKE_PRINT_METHOD_ADAPTOR(Name, Type, method) \
106 class Name final { \ 108 class Name final { \
107 STACK_ALLOCATED(); \ 109 STACK_ALLOCATED(); \
108 public: \ 110 \
109 Name(const Type& value) \ 111 public: \
110 : m_value(value) \ 112 Name(const Type& value) : m_value(value) {} \
111 { \ 113 void dump(PrintStream& out) const { m_value.method(out); } \
112 } \ 114 \
113 void dump(PrintStream& out) const \ 115 private: \
114 { \ 116 const Type& m_value; \
115 m_value.method(out); \ 117 }
116 } \
117 private: \
118 const Type& m_value; \
119 }
120 118
121 #define MAKE_PRINT_METHOD(Type, dumpMethod, method) \ 119 #define MAKE_PRINT_METHOD(Type, dumpMethod, method) \
122 MAKE_PRINT_METHOD_ADAPTOR(DumperFor_##method, Type, dumpMethod); \ 120 MAKE_PRINT_METHOD_ADAPTOR(DumperFor_##method, Type, dumpMethod); \
123 DumperFor_##method method() const { return DumperFor_##method(*this); } 121 DumperFor_##method method() const { return DumperFor_##method(*this); }
124 122
125 // Use an adaptor-based dumper for characters to avoid situations where 123 // Use an adaptor-based dumper for characters to avoid situations where
126 // you've "compressed" an integer to a character and it ends up printing 124 // you've "compressed" an integer to a character and it ends up printing
127 // as ASCII when you wanted it to print as a number. 125 // as ASCII when you wanted it to print as a number.
128 void dumpCharacter(PrintStream&, char); 126 void dumpCharacter(PrintStream&, char);
129 MAKE_PRINT_ADAPTOR(CharacterDump, char, dumpCharacter); 127 MAKE_PRINT_ADAPTOR(CharacterDump, char, dumpCharacter);
130 128
131 template <typename T> 129 template <typename T>
132 class PointerDump final { 130 class PointerDump final {
133 STACK_ALLOCATED(); 131 STACK_ALLOCATED();
134 public:
135 PointerDump(const T* ptr)
136 : m_ptr(ptr)
137 {
138 }
139 132
140 void dump(PrintStream& out) const 133 public:
141 { 134 PointerDump(const T* ptr) : m_ptr(ptr) {}
142 if (m_ptr)
143 printInternal(out, *m_ptr);
144 else
145 out.print("(null)");
146 }
147 135
148 private: 136 void dump(PrintStream& out) const {
149 const T* m_ptr; 137 if (m_ptr)
138 printInternal(out, *m_ptr);
139 else
140 out.print("(null)");
141 }
142
143 private:
144 const T* m_ptr;
150 }; 145 };
151 146
152 template <typename T> 147 template <typename T>
153 PointerDump<T> pointerDump(const T* ptr) { return PointerDump<T>(ptr); } 148 PointerDump<T> pointerDump(const T* ptr) {
149 return PointerDump<T>(ptr);
150 }
154 151
155 } // namespace WTF 152 } // namespace WTF
156 153
157 using WTF::CharacterDump; 154 using WTF::CharacterDump;
158 using WTF::PointerDump; 155 using WTF::PointerDump;
159 using WTF::PrintStream; 156 using WTF::PrintStream;
160 using WTF::pointerDump; 157 using WTF::pointerDump;
161 158
162 #endif // PrintStream_h 159 #endif // PrintStream_h
163
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/PassRefPtr.h ('k') | third_party/WebKit/Source/wtf/PrintStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698