| 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 TracedDictionary<SelfType>& beginDictionary(const char* name) |
| 52 { | |
| 53 ASSERT(m_stack.size() == nestingLevel); | |
| 54 endCurrentDictionary(); | |
| 55 return *reinterpret_cast<OwnerType*>(this); | |
| 56 } | |
| 57 | |
| 58 TracedDictionary<TracedDictionary<OwnerType> >& beginDictionary(const char*
name) | |
| 59 { | 55 { |
| 60 beginDictionaryNamed(name); | 56 beginDictionaryNamed(name); |
| 61 return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >*
>(this); | 57 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| 62 } | 58 } |
| 63 TracedArray<TracedDictionary<OwnerType> >& beginArray(const char* name) | 59 TracedArray<SelfType>& beginArray(const char* name) |
| 64 { | 60 { |
| 65 beginArrayNamed(name); | 61 beginArrayNamed(name); |
| 66 return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >* >(th
is); | 62 return *reinterpret_cast<TracedArray<SelfType>*>(this); |
| 67 } | 63 } |
| 68 TracedDictionary<OwnerType>& setInteger(const char* name, int value) | 64 SelfType& setInteger(const char* name, int value) |
| 69 { | 65 { |
| 70 TracedValueBase::setInteger(name, value); | 66 TracedValueBase::setInteger(name, value); |
| 71 return *this; | 67 return *this; |
| 72 } | 68 } |
| 73 TracedDictionary<OwnerType>& setDouble(const char* name, double value) | 69 SelfType& setDouble(const char* name, double value) |
| 74 { | 70 { |
| 75 TracedValueBase::setDouble(name, value); | 71 TracedValueBase::setDouble(name, value); |
| 76 return *this; | 72 return *this; |
| 77 } | 73 } |
| 78 TracedDictionary<OwnerType>& setBoolean(const char* name, bool value) | 74 SelfType& setBoolean(const char* name, bool value) |
| 79 { | 75 { |
| 80 TracedValueBase::setBoolean(name, value); | 76 TracedValueBase::setBoolean(name, value); |
| 81 return *this; | 77 return *this; |
| 82 } | 78 } |
| 83 TracedDictionary<OwnerType>& setString(const char* name, const String& value
) | 79 SelfType& setString(const char* name, const String& value) |
| 84 { | 80 { |
| 85 TracedValueBase::setString(name, value); | 81 TracedValueBase::setString(name, value); |
| 86 return *this; | 82 return *this; |
| 87 } | 83 } |
| 84 private: |
| 85 TracedDictionaryBase(); |
| 86 ~TracedDictionaryBase(); |
| 87 }; |
| 88 | 88 |
| 89 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | 89 template <class OwnerType> |
| 90 class TracedDictionary : public TracedDictionaryBase { |
| 91 WTF_MAKE_NONCOPYABLE(TracedDictionary); |
| 92 private: |
| 93 typedef TracedDictionary<OwnerType> SelfType; |
| 94 public: |
| 95 OwnerType& endDictionary() |
| 96 { |
| 97 TracedValueBase::endCurrentDictionary(); |
| 98 return *reinterpret_cast<OwnerType*>(this); |
| 99 } |
| 100 |
| 101 TracedDictionary<SelfType>& beginDictionary(const char* name) |
| 102 { |
| 103 TracedDictionaryBase::beginDictionary(name); |
| 104 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| 105 } |
| 106 TracedArray<SelfType>& beginArray(const char* name) |
| 107 { |
| 108 TracedDictionaryBase::beginArray(name); |
| 109 return *reinterpret_cast<TracedArray<SelfType>*>(this); |
| 110 } |
| 111 SelfType& setInteger(const char* name, int value) |
| 112 { |
| 113 TracedDictionaryBase::setInteger(name, value); |
| 114 return *this; |
| 115 } |
| 116 SelfType& setDouble(const char* name, double value) |
| 117 { |
| 118 TracedDictionaryBase::setDouble(name, value); |
| 119 return *this; |
| 120 } |
| 121 SelfType& setBoolean(const char* name, bool value) |
| 122 { |
| 123 TracedDictionaryBase::setBoolean(name, value); |
| 124 return *this; |
| 125 } |
| 126 SelfType& setString(const char* name, const String& value) |
| 127 { |
| 128 TracedDictionaryBase::setString(name, value); |
| 129 return *this; |
| 130 } |
| 90 | 131 |
| 91 private: | 132 private: |
| 92 TracedDictionary(); | 133 TracedDictionary(); |
| 93 ~TracedDictionary(); | 134 ~TracedDictionary(); |
| 94 }; | 135 }; |
| 95 | 136 |
| 96 template <class OwnerType> | 137 class TracedArrayBase : public TracedValueBase { |
| 97 class TracedArray : public TracedValueBase { | 138 WTF_MAKE_NONCOPYABLE(TracedArrayBase); |
| 98 WTF_MAKE_NONCOPYABLE(TracedArray); | 139 private: |
| 140 typedef TracedArrayBase SelfType; |
| 99 public: | 141 public: |
| 100 TracedDictionary<TracedArray<OwnerType> >& beginDictionary() | 142 TracedDictionary<SelfType>& beginDictionary() |
| 101 { | 143 { |
| 102 pushDictionary(); | 144 pushDictionary(); |
| 103 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th
is); | 145 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| 104 } | 146 } |
| 105 TracedDictionary<TracedArray<OwnerType> >& beginArray() | 147 TracedArray<SelfType>& beginArray() |
| 106 { | 148 { |
| 107 pushArray(); | 149 pushArray(); |
| 108 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th
is); | 150 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 } | 151 } |
| 116 | 152 |
| 117 TracedArray<OwnerType>& pushInteger(int value) | 153 SelfType& pushInteger(int value) |
| 118 { | 154 { |
| 119 TracedValueBase::pushInteger(value); | 155 TracedValueBase::pushInteger(value); |
| 120 return *this; | 156 return *this; |
| 121 } | 157 } |
| 122 TracedArray<OwnerType>& pushDouble(double value) | 158 SelfType& pushDouble(double value) |
| 123 { | 159 { |
| 124 TracedValueBase::pushDouble(value); | 160 TracedValueBase::pushDouble(value); |
| 125 return *this; | 161 return *this; |
| 126 } | 162 } |
| 127 TracedArray<OwnerType>& pushBoolean(bool value) | 163 SelfType& pushBoolean(bool value) |
| 128 { | 164 { |
| 129 TracedValueBase::pushBoolean(value); | 165 TracedValueBase::pushBoolean(value); |
| 130 return *this; | 166 return *this; |
| 131 } | 167 } |
| 132 TracedArray<OwnerType>& pushString(const String& value) | 168 SelfType& pushString(const String& value) |
| 133 { | 169 { |
| 134 TracedValueBase::pushString(value); | 170 TracedValueBase::pushString(value); |
| 135 return *this; | 171 return *this; |
| 136 } | 172 } |
| 137 | 173 |
| 138 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | 174 private: |
| 175 TracedArrayBase(); |
| 176 ~TracedArrayBase(); |
| 177 }; |
| 178 |
| 179 template <class OwnerType> |
| 180 class TracedArray : public TracedArrayBase { |
| 181 WTF_MAKE_NONCOPYABLE(TracedArray); |
| 182 private: |
| 183 typedef TracedArray<OwnerType> SelfType; |
| 184 public: |
| 185 OwnerType& endArray() |
| 186 { |
| 187 TracedValueBase::endCurrentArray(); |
| 188 return *reinterpret_cast<OwnerType*>(this); |
| 189 } |
| 190 |
| 191 TracedDictionary<SelfType >& beginDictionary() |
| 192 { |
| 193 TracedArrayBase::beginDictionary(); |
| 194 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| 195 } |
| 196 TracedArray<SelfType >& beginArray() |
| 197 { |
| 198 TracedArrayBase::beginArray(); |
| 199 return *reinterpret_cast<TracedArray<SelfType>*>(this); |
| 200 } |
| 201 |
| 202 SelfType& pushInteger(int value) |
| 203 { |
| 204 TracedArrayBase::pushInteger(value); |
| 205 return *this; |
| 206 } |
| 207 SelfType& pushDouble(double value) |
| 208 { |
| 209 TracedArrayBase::pushDouble(value); |
| 210 return *this; |
| 211 } |
| 212 SelfType& pushBoolean(bool value) |
| 213 { |
| 214 TracedArrayBase::pushBoolean(value); |
| 215 return *this; |
| 216 } |
| 217 SelfType& pushString(const String& value) |
| 218 { |
| 219 TracedArrayBase::pushString(value); |
| 220 return *this; |
| 221 } |
| 139 | 222 |
| 140 private: | 223 private: |
| 141 TracedArray(); | 224 TracedArray(); |
| 142 ~TracedArray(); | 225 ~TracedArray(); |
| 143 }; | 226 }; |
| 144 | 227 |
| 145 class PLATFORM_EXPORT TracedValue : public TracedValueBase { | 228 class PLATFORM_EXPORT TracedValue : public TracedValueBase { |
| 146 WTF_MAKE_NONCOPYABLE(TracedValue); | 229 WTF_MAKE_NONCOPYABLE(TracedValue); |
| 230 private: |
| 231 typedef TracedValue SelfType; |
| 147 public: | 232 public: |
| 148 TracedValue(); | 233 TracedValue(); |
| 149 ~TracedValue(); | 234 ~TracedValue(); |
| 150 | 235 |
| 151 TracedDictionary<TracedValue>& beginDictionary(const char* name); | 236 TracedDictionary<SelfType>& beginDictionary(const char* name); |
| 152 TracedArray<TracedValue>& beginArray(const char* name); | 237 TracedArray<SelfType>& beginArray(const char* name); |
| 153 TracedValue& setInteger(const char* name, int value) | 238 |
| 239 SelfType& setInteger(const char* name, int value) |
| 154 { | 240 { |
| 155 TracedValueBase::setInteger(name, value); | 241 TracedValueBase::setInteger(name, value); |
| 156 return *this; | 242 return *this; |
| 157 } | 243 } |
| 158 TracedValue& setDouble(const char* name, double value) | 244 SelfType& setDouble(const char* name, double value) |
| 159 { | 245 { |
| 160 TracedValueBase::setDouble(name, value); | 246 TracedValueBase::setDouble(name, value); |
| 161 return *this; | 247 return *this; |
| 162 } | 248 } |
| 163 TracedValue& setBoolean(const char* name, bool value) | 249 SelfType& setBoolean(const char* name, bool value) |
| 164 { | 250 { |
| 165 TracedValueBase::setBoolean(name, value); | 251 TracedValueBase::setBoolean(name, value); |
| 166 return *this; | 252 return *this; |
| 167 } | 253 } |
| 168 TracedValue& setString(const char* name, const String& value) | 254 SelfType& setString(const char* name, const String& value) |
| 169 { | 255 { |
| 170 TracedValueBase::setString(name, value); | 256 TracedValueBase::setString(name, value); |
| 171 return *this; | 257 return *this; |
| 172 } | 258 } |
| 259 |
| 173 PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish(); | 260 PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish(); |
| 174 | |
| 175 static const size_t nestingLevel = 1; | |
| 176 }; | 261 }; |
| 177 | 262 |
| 178 } // namespace WebCore | 263 } // namespace WebCore |
| 179 | 264 |
| 180 #endif // TracedValue_h | 265 #endif // TracedValue_h |
| OLD | NEW |