OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TracedValue_h | 5 #ifndef TracedValue_h |
6 #define TracedValue_h | 6 #define TracedValue_h |
7 | 7 |
8 #include "platform/EventTracer.h" | 8 #include "platform/EventTracer.h" |
9 | 9 |
10 #include "wtf/PassRefPtr.h" | 10 #include "wtf/PassRefPtr.h" |
11 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
12 | 12 |
13 namespace WebCore { | 13 namespace WebCore { |
14 class JSONArray; | 14 class JSONArray; |
15 class JSONObject; | 15 class JSONObject; |
16 class JSONValue; | 16 class JSONValue; |
17 class TracedArrayBase; | |
17 template<class T> class TracedArray; | 18 template<class T> class TracedArray; |
19 template<class T> class TracedDictionary; | |
18 | 20 |
19 class PLATFORM_EXPORT TracedValueBase { | 21 class PLATFORM_EXPORT TracedValueBase { |
20 WTF_MAKE_NONCOPYABLE(TracedValueBase); | 22 WTF_MAKE_NONCOPYABLE(TracedValueBase); |
21 protected: | 23 protected: |
22 TracedValueBase(); | 24 TracedValueBase(); |
23 ~TracedValueBase(); | 25 ~TracedValueBase(); |
24 | 26 |
25 void setInteger(const char* name, int value); | 27 void setInteger(const char* name, int value); |
26 void setDouble(const char* name, double); | 28 void setDouble(const char* name, double); |
27 void setBoolean(const char* name, bool value); | 29 void setBoolean(const char* name, bool value); |
28 void setString(const char* name, const String& value); | 30 void setString(const char* name, const String& value); |
29 void beginDictionaryNamed(const char* name); | 31 void beginDictionaryNamed(const char* name); |
30 void beginArrayNamed(const char* name); | 32 void beginArrayNamed(const char* name); |
31 void endCurrentDictionary(); | 33 void endCurrentDictionary(); |
32 | 34 |
33 void pushInteger(int); | 35 void pushInteger(int); |
34 void pushDouble(double); | 36 void pushDouble(double); |
35 void pushBoolean(bool); | 37 void pushBoolean(bool); |
36 void pushString(const String&); | 38 void pushString(const String&); |
37 void pushArray(); | 39 void pushArray(); |
38 void pushDictionary(); | 40 void pushDictionary(); |
39 void endCurrentArray(); | 41 void endCurrentArray(); |
40 | 42 |
41 JSONObject* currentDictionary() const; | 43 JSONObject* currentDictionary() const; |
42 JSONArray* currentArray() const; | 44 JSONArray* currentArray() const; |
43 | 45 |
44 Vector<RefPtr<JSONValue> > m_stack; | 46 Vector<RefPtr<JSONValue> > m_stack; |
45 }; | 47 }; |
46 | 48 |
47 template <class OwnerType> | 49 class TracedDictionaryBase : public TracedValueBase { |
48 class TracedDictionary : public TracedValueBase { | 50 WTF_MAKE_NONCOPYABLE(TracedDictionaryBase); |
49 WTF_MAKE_NONCOPYABLE(TracedDictionary); | 51 private: |
52 typedef TracedDictionaryBase SelfType; | |
50 public: | 53 public: |
51 OwnerType& endDictionary() | 54 void endDictionary() |
yurys
2014/07/11 12:21:50
It seems that this method can be removed since cre
zerny-chromium
2014/07/11 12:37:18
Good point, I'll get that change it right away.
| |
52 { | 55 { |
53 ASSERT(m_stack.size() == nestingLevel); | |
54 endCurrentDictionary(); | 56 endCurrentDictionary(); |
55 return *reinterpret_cast<OwnerType*>(this); | |
56 } | 57 } |
57 | 58 |
58 TracedDictionary<TracedDictionary<OwnerType> >& beginDictionary(const char* name) | 59 TracedDictionary<SelfType>& beginDictionary(const char* name) |
59 { | 60 { |
60 beginDictionaryNamed(name); | 61 beginDictionaryNamed(name); |
61 return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >* >(this); | 62 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
62 } | 63 } |
63 TracedArray<TracedDictionary<OwnerType> >& beginArray(const char* name) | 64 TracedArray<SelfType>& beginArray(const char* name) |
64 { | 65 { |
65 beginArrayNamed(name); | 66 beginArrayNamed(name); |
66 return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >* >(th is); | 67 return *reinterpret_cast<TracedArray<SelfType>*>(this); |
67 } | 68 } |
68 TracedDictionary<OwnerType>& setInteger(const char* name, int value) | 69 SelfType& setInteger(const char* name, int value) |
69 { | 70 { |
70 TracedValueBase::setInteger(name, value); | 71 TracedValueBase::setInteger(name, value); |
71 return *this; | 72 return *this; |
72 } | 73 } |
73 TracedDictionary<OwnerType>& setDouble(const char* name, double value) | 74 SelfType& setDouble(const char* name, double value) |
74 { | 75 { |
75 TracedValueBase::setDouble(name, value); | 76 TracedValueBase::setDouble(name, value); |
76 return *this; | 77 return *this; |
77 } | 78 } |
78 TracedDictionary<OwnerType>& setBoolean(const char* name, bool value) | 79 SelfType& setBoolean(const char* name, bool value) |
79 { | 80 { |
80 TracedValueBase::setBoolean(name, value); | 81 TracedValueBase::setBoolean(name, value); |
81 return *this; | 82 return *this; |
82 } | 83 } |
83 TracedDictionary<OwnerType>& setString(const char* name, const String& value ) | 84 SelfType& setString(const char* name, const String& value) |
84 { | 85 { |
85 TracedValueBase::setString(name, value); | 86 TracedValueBase::setString(name, value); |
86 return *this; | 87 return *this; |
87 } | 88 } |
89 private: | |
90 TracedDictionaryBase(); | |
91 ~TracedDictionaryBase(); | |
92 }; | |
88 | 93 |
89 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | 94 template <class OwnerType> |
95 class TracedDictionary : public TracedDictionaryBase { | |
96 WTF_MAKE_NONCOPYABLE(TracedDictionary); | |
97 private: | |
98 typedef TracedDictionary<OwnerType> SelfType; | |
99 public: | |
100 OwnerType& endDictionary() | |
101 { | |
102 TracedDictionaryBase::endDictionary(); | |
103 return *reinterpret_cast<OwnerType*>(this); | |
104 } | |
105 | |
106 TracedDictionary<SelfType>& beginDictionary(const char* name) | |
107 { | |
108 TracedDictionaryBase::beginDictionary(name); | |
109 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); | |
110 } | |
111 TracedArray<SelfType>& beginArray(const char* name) | |
112 { | |
113 TracedDictionaryBase::beginArray(name); | |
114 return *reinterpret_cast<TracedArray<SelfType>*>(this); | |
115 } | |
116 SelfType& setInteger(const char* name, int value) | |
117 { | |
118 TracedDictionaryBase::setInteger(name, value); | |
119 return *this; | |
120 } | |
121 SelfType& setDouble(const char* name, double value) | |
122 { | |
123 TracedDictionaryBase::setDouble(name, value); | |
124 return *this; | |
125 } | |
126 SelfType& setBoolean(const char* name, bool value) | |
127 { | |
128 TracedDictionaryBase::setBoolean(name, value); | |
129 return *this; | |
130 } | |
131 SelfType& setString(const char* name, const String& value) | |
132 { | |
133 TracedDictionaryBase::setString(name, value); | |
134 return *this; | |
135 } | |
90 | 136 |
91 private: | 137 private: |
92 TracedDictionary(); | 138 TracedDictionary(); |
93 ~TracedDictionary(); | 139 ~TracedDictionary(); |
94 }; | 140 }; |
95 | 141 |
96 template <class OwnerType> | 142 class TracedArrayBase : public TracedValueBase { |
97 class TracedArray : public TracedValueBase { | 143 WTF_MAKE_NONCOPYABLE(TracedArrayBase); |
98 WTF_MAKE_NONCOPYABLE(TracedArray); | 144 private: |
145 typedef TracedArrayBase SelfType; | |
99 public: | 146 public: |
100 TracedDictionary<TracedArray<OwnerType> >& beginDictionary() | 147 void endArray() |
148 { | |
149 endCurrentArray(); | |
150 } | |
151 | |
152 TracedDictionary<SelfType>& beginDictionary() | |
101 { | 153 { |
102 pushDictionary(); | 154 pushDictionary(); |
103 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th is); | 155 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
104 } | 156 } |
105 TracedDictionary<TracedArray<OwnerType> >& beginArray() | 157 TracedArray<SelfType>& beginArray() |
106 { | 158 { |
107 pushArray(); | 159 pushArray(); |
108 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th is); | 160 return *reinterpret_cast<TracedArray<SelfType>*>(this); |
109 } | |
110 OwnerType& endArray() | |
111 { | |
112 ASSERT(m_stack.size() == nestingLevel); | |
113 endCurrentArray(); | |
114 return *reinterpret_cast<OwnerType*>(this); | |
115 } | 161 } |
116 | 162 |
117 TracedArray<OwnerType>& pushInteger(int value) | 163 SelfType& pushInteger(int value) |
118 { | 164 { |
119 TracedValueBase::pushInteger(value); | 165 TracedValueBase::pushInteger(value); |
120 return *this; | 166 return *this; |
121 } | 167 } |
122 TracedArray<OwnerType>& pushDouble(double value) | 168 SelfType& pushDouble(double value) |
123 { | 169 { |
124 TracedValueBase::pushDouble(value); | 170 TracedValueBase::pushDouble(value); |
125 return *this; | 171 return *this; |
126 } | 172 } |
127 TracedArray<OwnerType>& pushBoolean(bool value) | 173 SelfType& pushBoolean(bool value) |
128 { | 174 { |
129 TracedValueBase::pushBoolean(value); | 175 TracedValueBase::pushBoolean(value); |
130 return *this; | 176 return *this; |
131 } | 177 } |
132 TracedArray<OwnerType>& pushString(const String& value) | 178 SelfType& pushString(const String& value) |
133 { | 179 { |
134 TracedValueBase::pushString(value); | 180 TracedValueBase::pushString(value); |
135 return *this; | 181 return *this; |
136 } | 182 } |
137 | 183 |
138 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | 184 private: |
185 TracedArrayBase(); | |
186 ~TracedArrayBase(); | |
187 }; | |
188 | |
189 template <class OwnerType> | |
190 class TracedArray : public TracedArrayBase { | |
191 WTF_MAKE_NONCOPYABLE(TracedArray); | |
192 private: | |
193 typedef TracedArray<OwnerType> SelfType; | |
194 public: | |
195 OwnerType& endArray() | |
196 { | |
197 TracedArrayBase::endArray(); | |
198 return *reinterpret_cast<OwnerType*>(this); | |
199 } | |
200 | |
201 TracedDictionary<SelfType >& beginDictionary() | |
202 { | |
203 TracedArrayBase::beginDictionary(); | |
204 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); | |
205 } | |
206 TracedArray<SelfType >& beginArray() | |
207 { | |
208 TracedArrayBase::beginArray(); | |
209 return *reinterpret_cast<TracedArray<SelfType>*>(this); | |
210 } | |
211 | |
212 SelfType& pushInteger(int value) | |
213 { | |
214 TracedArrayBase::pushInteger(value); | |
215 return *this; | |
216 } | |
217 SelfType& pushDouble(double value) | |
218 { | |
219 TracedArrayBase::pushDouble(value); | |
220 return *this; | |
221 } | |
222 SelfType& pushBoolean(bool value) | |
223 { | |
224 TracedArrayBase::pushBoolean(value); | |
225 return *this; | |
226 } | |
227 SelfType& pushString(const String& value) | |
228 { | |
229 TracedArrayBase::pushString(value); | |
230 return *this; | |
231 } | |
139 | 232 |
140 private: | 233 private: |
141 TracedArray(); | 234 TracedArray(); |
142 ~TracedArray(); | 235 ~TracedArray(); |
143 }; | 236 }; |
144 | 237 |
145 class PLATFORM_EXPORT TracedValue : public TracedValueBase { | 238 class PLATFORM_EXPORT TracedValue : public TracedValueBase { |
146 WTF_MAKE_NONCOPYABLE(TracedValue); | 239 WTF_MAKE_NONCOPYABLE(TracedValue); |
240 private: | |
241 typedef TracedValue SelfType; | |
147 public: | 242 public: |
148 TracedValue(); | 243 TracedValue(); |
149 ~TracedValue(); | 244 ~TracedValue(); |
150 | 245 |
151 TracedDictionary<TracedValue>& beginDictionary(const char* name); | 246 TracedDictionary<SelfType>& beginDictionary(const char* name); |
152 TracedArray<TracedValue>& beginArray(const char* name); | 247 TracedArray<SelfType>& beginArray(const char* name); |
153 TracedValue& setInteger(const char* name, int value) | 248 |
249 SelfType& setInteger(const char* name, int value) | |
154 { | 250 { |
155 TracedValueBase::setInteger(name, value); | 251 TracedValueBase::setInteger(name, value); |
156 return *this; | 252 return *this; |
157 } | 253 } |
158 TracedValue& setDouble(const char* name, double value) | 254 SelfType& setDouble(const char* name, double value) |
159 { | 255 { |
160 TracedValueBase::setDouble(name, value); | 256 TracedValueBase::setDouble(name, value); |
161 return *this; | 257 return *this; |
162 } | 258 } |
163 TracedValue& setBoolean(const char* name, bool value) | 259 SelfType& setBoolean(const char* name, bool value) |
164 { | 260 { |
165 TracedValueBase::setBoolean(name, value); | 261 TracedValueBase::setBoolean(name, value); |
166 return *this; | 262 return *this; |
167 } | 263 } |
168 TracedValue& setString(const char* name, const String& value) | 264 SelfType& setString(const char* name, const String& value) |
169 { | 265 { |
170 TracedValueBase::setString(name, value); | 266 TracedValueBase::setString(name, value); |
171 return *this; | 267 return *this; |
172 } | 268 } |
269 | |
173 PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish(); | 270 PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish(); |
174 | |
175 static const size_t nestingLevel = 1; | |
176 }; | 271 }; |
177 | 272 |
178 } // namespace WebCore | 273 } // namespace WebCore |
179 | 274 |
180 #endif // TracedValue_h | 275 #endif // TracedValue_h |
OLD | NEW |