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 {{"_".join(config.protocol.namespace)}}_Values_h | 5 #ifndef {{"_".join(config.protocol.namespace)}}_Values_h |
6 #define {{"_".join(config.protocol.namespace)}}_Values_h | 6 #define {{"_".join(config.protocol.namespace)}}_Values_h |
7 | 7 |
8 //#include "Allocator.h" | 8 //#include "Allocator.h" |
9 //#include "Collections.h" | 9 //#include "Collections.h" |
10 //#include "Forward.h" | 10 //#include "Forward.h" |
11 | 11 |
12 {% for namespace in config.protocol.namespace %} | 12 {% for namespace in config.protocol.namespace %} |
13 namespace {{namespace}} { | 13 namespace {{namespace}} { |
14 {% endfor %} | 14 {% endfor %} |
15 | 15 |
16 class ListValue; | 16 class ListValue; |
17 class DictionaryValue; | 17 class DictionaryValue; |
18 class Value; | 18 class Value; |
19 | 19 |
20 class {{config.lib.export_macro}} Value { | 20 class {{config.lib.export_macro}} Value : public Serializable { |
21 PROTOCOL_DISALLOW_COPY(Value); | 21 PROTOCOL_DISALLOW_COPY(Value); |
22 public: | 22 public: |
23 virtual ~Value() { } | 23 virtual ~Value() { } |
24 | 24 |
25 static std::unique_ptr<Value> null() | 25 static std::unique_ptr<Value> null() |
26 { | 26 { |
27 return std::unique_ptr<Value>(new Value()); | 27 return std::unique_ptr<Value>(new Value()); |
28 } | 28 } |
29 | 29 |
30 enum ValueType { | 30 enum ValueType { |
(...skipping 13 matching lines...) Expand all Loading... |
44 | 44 |
45 virtual bool asBoolean(bool* output) const; | 45 virtual bool asBoolean(bool* output) const; |
46 virtual bool asDouble(double* output) const; | 46 virtual bool asDouble(double* output) const; |
47 virtual bool asInteger(int* output) const; | 47 virtual bool asInteger(int* output) const; |
48 virtual bool asString(String* output) const; | 48 virtual bool asString(String* output) const; |
49 virtual bool asSerialized(String* output) const; | 49 virtual bool asSerialized(String* output) const; |
50 | 50 |
51 String toJSONString() const; | 51 String toJSONString() const; |
52 virtual void writeJSON(StringBuilder* output) const; | 52 virtual void writeJSON(StringBuilder* output) const; |
53 virtual std::unique_ptr<Value> clone() const; | 53 virtual std::unique_ptr<Value> clone() const; |
| 54 String serialize() { return toJSONString(); } |
54 | 55 |
55 protected: | 56 protected: |
56 Value() : m_type(TypeNull) { } | 57 Value() : m_type(TypeNull) { } |
57 explicit Value(ValueType type) : m_type(type) { } | 58 explicit Value(ValueType type) : m_type(type) { } |
58 | 59 |
59 private: | 60 private: |
60 friend class DictionaryValue; | 61 friend class DictionaryValue; |
61 friend class ListValue; | 62 friend class ListValue; |
62 | 63 |
63 ValueType m_type; | 64 ValueType m_type; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 private: | 238 private: |
238 ListValue(); | 239 ListValue(); |
239 std::vector<std::unique_ptr<Value>> m_data; | 240 std::vector<std::unique_ptr<Value>> m_data; |
240 }; | 241 }; |
241 | 242 |
242 {% for namespace in config.protocol.namespace %} | 243 {% for namespace in config.protocol.namespace %} |
243 } // namespace {{namespace}} | 244 } // namespace {{namespace}} |
244 {% endfor %} | 245 {% endfor %} |
245 | 246 |
246 #endif // {{"_".join(config.protocol.namespace)}}_Values_h | 247 #endif // {{"_".join(config.protocol.namespace)}}_Values_h |
OLD | NEW |