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" |
11 #include "platform/inspector_protocol/String16.h" | 11 #include "platform/inspector_protocol/String16.h" |
12 | 12 |
13 #include <vector> | |
14 | |
13 namespace blink { | 15 namespace blink { |
14 namespace protocol { | 16 namespace protocol { |
15 | 17 |
16 class ListValue; | 18 class ListValue; |
17 class DictionaryValue; | 19 class DictionaryValue; |
18 class Value; | 20 class Value; |
19 | 21 |
20 class PLATFORM_EXPORT Value { | 22 class PLATFORM_EXPORT Value { |
21 PROTOCOL_DISALLOW_COPY(Value); | 23 PROTOCOL_DISALLOW_COPY(Value); |
22 public: | 24 public: |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 Entry at(size_t index) const; | 169 Entry at(size_t index) const; |
168 | 170 |
169 bool booleanProperty(const String16& name, bool defaultValue) const; | 171 bool booleanProperty(const String16& name, bool defaultValue) const; |
170 double numberProperty(const String16& name, double defaultValue) const; | 172 double numberProperty(const String16& name, double defaultValue) const; |
171 void remove(const String16& name); | 173 void remove(const String16& name); |
172 | 174 |
173 ~DictionaryValue() override; | 175 ~DictionaryValue() override; |
174 | 176 |
175 private: | 177 private: |
176 DictionaryValue(); | 178 DictionaryValue(); |
179 template<typename T> | |
180 void set(const String16& key, std::unique_ptr<T>& value) | |
181 { | |
182 DCHECK(value); | |
183 bool isNew = m_data.find(key) == m_data.end(); | |
184 m_data[key] = std::move(value); | |
185 if (isNew) { | |
dgozman
2016/06/24 17:01:12
style: redundant {}
eostroukhov-old
2016/06/24 22:24:25
Done.
| |
186 m_order.push_back(key); | |
187 } | |
188 } | |
177 | 189 |
178 using Dictionary = protocol::HashMap<String16, std::unique_ptr<Value>>; | 190 using Dictionary = protocol::HashMap<String16, std::unique_ptr<Value>>; |
179 Dictionary m_data; | 191 Dictionary m_data; |
180 protocol::Vector<String16> m_order; | 192 std::vector<String16> m_order; |
181 }; | 193 }; |
182 | 194 |
183 class PLATFORM_EXPORT ListValue : public Value { | 195 class PLATFORM_EXPORT ListValue : public Value { |
184 public: | 196 public: |
185 static std::unique_ptr<ListValue> create() | 197 static std::unique_ptr<ListValue> create() |
186 { | 198 { |
187 return wrapUnique(new ListValue()); | 199 return wrapUnique(new ListValue()); |
188 } | 200 } |
189 | 201 |
190 static ListValue* cast(Value* value) | 202 static ListValue* cast(Value* value) |
(...skipping 13 matching lines...) Expand all Loading... | |
204 void writeJSON(String16Builder* output) const override; | 216 void writeJSON(String16Builder* output) const override; |
205 std::unique_ptr<Value> clone() const override; | 217 std::unique_ptr<Value> clone() const override; |
206 | 218 |
207 void pushValue(std::unique_ptr<Value>); | 219 void pushValue(std::unique_ptr<Value>); |
208 | 220 |
209 Value* at(size_t index); | 221 Value* at(size_t index); |
210 size_t size() const { return m_data.size(); } | 222 size_t size() const { return m_data.size(); } |
211 | 223 |
212 private: | 224 private: |
213 ListValue(); | 225 ListValue(); |
214 protocol::Vector<std::unique_ptr<Value>> m_data; | 226 std::vector<std::unique_ptr<Value>> m_data; |
215 }; | 227 }; |
216 | 228 |
217 } // namespace protocol | 229 } // namespace protocol |
218 } // namespace blink | 230 } // namespace blink |
219 | 231 |
220 #endif // Values_h | 232 #endif // Values_h |
OLD | NEW |