| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Values_h | 5 #ifndef Values_h |
| 6 #define Values_h | 6 #define Values_h |
| 7 | 7 |
| 8 #include "platform/inspector_protocol/Allocator.h" | 8 #include "platform/inspector_protocol/Allocator.h" |
| 9 #include "platform/inspector_protocol/Collections.h" | 9 #include "platform/inspector_protocol/Collections.h" |
| 10 #include "platform/inspector_protocol/Platform.h" | 10 #include "platform/inspector_protocol/Platform.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 return wrapUnique(new Value()); | 31 return wrapUnique(new Value()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 enum ValueType { | 34 enum ValueType { |
| 35 TypeNull = 0, | 35 TypeNull = 0, |
| 36 TypeBoolean, | 36 TypeBoolean, |
| 37 TypeInteger, | 37 TypeInteger, |
| 38 TypeDouble, | 38 TypeDouble, |
| 39 TypeString, | 39 TypeString, |
| 40 TypeObject, | 40 TypeObject, |
| 41 TypeArray | 41 TypeArray, |
| 42 TypeSerialized |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 ValueType type() const { return m_type; } | 45 ValueType type() const { return m_type; } |
| 45 | 46 |
| 46 bool isNull() const { return m_type == TypeNull; } | 47 bool isNull() const { return m_type == TypeNull; } |
| 47 | 48 |
| 48 virtual bool asBoolean(bool* output) const; | 49 virtual bool asBoolean(bool* output) const; |
| 49 virtual bool asDouble(double* output) const; | 50 virtual bool asDouble(double* output) const; |
| 50 virtual bool asInteger(int* output) const; | 51 virtual bool asInteger(int* output) const; |
| 51 virtual bool asString(String16* output) const; | 52 virtual bool asString(String16* output) const; |
| 53 virtual bool asSerialized(String16* output) const; |
| 52 | 54 |
| 53 String16 toJSONString() const; | 55 String16 toJSONString() const; |
| 54 virtual void writeJSON(String16Builder* output) const; | 56 virtual void writeJSON(String16Builder* output) const; |
| 55 virtual std::unique_ptr<Value> clone() const; | 57 virtual std::unique_ptr<Value> clone() const; |
| 56 | 58 |
| 57 protected: | 59 protected: |
| 58 Value() : m_type(TypeNull) { } | 60 Value() : m_type(TypeNull) { } |
| 59 explicit Value(ValueType type) : m_type(type) { } | 61 explicit Value(ValueType type) : m_type(type) { } |
| 60 | 62 |
| 61 private: | 63 private: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void writeJSON(String16Builder* output) const override; | 118 void writeJSON(String16Builder* output) const override; |
| 117 std::unique_ptr<Value> clone() const override; | 119 std::unique_ptr<Value> clone() const override; |
| 118 | 120 |
| 119 private: | 121 private: |
| 120 explicit StringValue(const String16& value) : Value(TypeString), m_stringVal
ue(value) { } | 122 explicit StringValue(const String16& value) : Value(TypeString), m_stringVal
ue(value) { } |
| 121 explicit StringValue(const char* value) : Value(TypeString), m_stringValue(v
alue) { } | 123 explicit StringValue(const char* value) : Value(TypeString), m_stringValue(v
alue) { } |
| 122 | 124 |
| 123 String16 m_stringValue; | 125 String16 m_stringValue; |
| 124 }; | 126 }; |
| 125 | 127 |
| 128 class PLATFORM_EXPORT SerializedValue : public Value { |
| 129 public: |
| 130 static std::unique_ptr<SerializedValue> create(const String16& value) |
| 131 { |
| 132 return wrapUnique(new SerializedValue(value)); |
| 133 } |
| 134 |
| 135 bool asSerialized(String16* output) const override; |
| 136 void writeJSON(String16Builder* output) const override; |
| 137 std::unique_ptr<Value> clone() const override; |
| 138 |
| 139 private: |
| 140 explicit SerializedValue(const String16& value) : Value(TypeSerialized), m_s
erializedValue(value) { } |
| 141 explicit SerializedValue(const char* value) : Value(TypeSerialized), m_seria
lizedValue(value) { } |
| 142 |
| 143 String16 m_serializedValue; |
| 144 }; |
| 145 |
| 126 class PLATFORM_EXPORT DictionaryValue : public Value { | 146 class PLATFORM_EXPORT DictionaryValue : public Value { |
| 127 public: | 147 public: |
| 128 using Entry = std::pair<String16, Value*>; | 148 using Entry = std::pair<String16, Value*>; |
| 129 static std::unique_ptr<DictionaryValue> create() | 149 static std::unique_ptr<DictionaryValue> create() |
| 130 { | 150 { |
| 131 return wrapUnique(new DictionaryValue()); | 151 return wrapUnique(new DictionaryValue()); |
| 132 } | 152 } |
| 133 | 153 |
| 134 static DictionaryValue* cast(Value* value) | 154 static DictionaryValue* cast(Value* value) |
| 135 { | 155 { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 241 |
| 222 private: | 242 private: |
| 223 ListValue(); | 243 ListValue(); |
| 224 std::vector<std::unique_ptr<Value>> m_data; | 244 std::vector<std::unique_ptr<Value>> m_data; |
| 225 }; | 245 }; |
| 226 | 246 |
| 227 } // namespace protocol | 247 } // namespace protocol |
| 228 } // namespace blink | 248 } // namespace blink |
| 229 | 249 |
| 230 #endif // Values_h | 250 #endif // Values_h |
| OLD | NEW |