| 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() override { } |
| 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 { |
| 31 TypeNull = 0, | 31 TypeNull = 0, |
| 32 TypeBoolean, | 32 TypeBoolean, |
| 33 TypeInteger, | 33 TypeInteger, |
| 34 TypeDouble, | 34 TypeDouble, |
| 35 TypeString, | 35 TypeString, |
| 36 TypeObject, | 36 TypeObject, |
| 37 TypeArray, | 37 TypeArray, |
| 38 TypeSerialized | 38 TypeSerialized |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 ValueType type() const { return m_type; } | 41 ValueType type() const { return m_type; } |
| 42 | 42 |
| 43 bool isNull() const { return m_type == TypeNull; } | 43 bool isNull() const { return m_type == TypeNull; } |
| 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; | |
| 52 virtual void writeJSON(StringBuilder* output) const; | 51 virtual void writeJSON(StringBuilder* output) const; |
| 53 virtual std::unique_ptr<Value> clone() const; | 52 virtual std::unique_ptr<Value> clone() const; |
| 53 String serialize() override; |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 Value() : m_type(TypeNull) { } | 56 Value() : m_type(TypeNull) { } |
| 57 explicit Value(ValueType type) : m_type(type) { } | 57 explicit Value(ValueType type) : m_type(type) { } |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 friend class DictionaryValue; | 60 friend class DictionaryValue; |
| 61 friend class ListValue; | 61 friend class ListValue; |
| 62 | 62 |
| 63 ValueType m_type; | 63 ValueType m_type; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 private: | 237 private: |
| 238 ListValue(); | 238 ListValue(); |
| 239 std::vector<std::unique_ptr<Value>> m_data; | 239 std::vector<std::unique_ptr<Value>> m_data; |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 {% for namespace in config.protocol.namespace %} | 242 {% for namespace in config.protocol.namespace %} |
| 243 } // namespace {{namespace}} | 243 } // namespace {{namespace}} |
| 244 {% endfor %} | 244 {% endfor %} |
| 245 | 245 |
| 246 #endif // {{"_".join(config.protocol.namespace)}}_Values_h | 246 #endif // {{"_".join(config.protocol.namespace)}}_Values_h |
| OLD | NEW |