| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_JSON_STREAM_H_ | 5 #ifndef VM_JSON_STREAM_H_ |
| 6 #define VM_JSON_STREAM_H_ | 6 #define VM_JSON_STREAM_H_ |
| 7 | 7 |
| 8 #include "platform/json.h" | 8 #include "platform/json.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 | 10 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 friend class JSONObject; | 78 friend class JSONObject; |
| 79 friend class JSONArray; | 79 friend class JSONArray; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 | 82 |
| 83 class JSONObject : public ValueObject { | 83 class JSONObject : public ValueObject { |
| 84 public: | 84 public: |
| 85 explicit JSONObject(JSONStream* stream) : stream_(stream) { | 85 explicit JSONObject(JSONStream* stream) : stream_(stream) { |
| 86 stream_->OpenObject(); | 86 stream_->OpenObject(); |
| 87 } | 87 } |
| 88 JSONObject(const JSONObject& obj, const char* name) : stream_(obj.stream_) { | 88 JSONObject(const JSONObject* obj, const char* name) : stream_(obj->stream_) { |
| 89 stream_->OpenObject(name); | 89 stream_->OpenObject(name); |
| 90 } | 90 } |
| 91 explicit JSONObject(const JSONArray& arr); | 91 explicit JSONObject(const JSONArray* arr); |
| 92 | 92 |
| 93 ~JSONObject() { | 93 ~JSONObject() { |
| 94 stream_->CloseObject(); | 94 stream_->CloseObject(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void AddProperty(const char* name, bool b) const { | 97 void AddProperty(const char* name, bool b) const { |
| 98 stream_->PrintPropertyBool(name, b); | 98 stream_->PrintPropertyBool(name, b); |
| 99 } | 99 } |
| 100 void AddProperty(const char* name, intptr_t i) const { | 100 void AddProperty(const char* name, intptr_t i) const { |
| 101 stream_->PrintProperty(name, i); | 101 stream_->PrintProperty(name, i); |
| 102 } | 102 } |
| 103 void AddProperty(const char* name, double d) const { | 103 void AddProperty(const char* name, double d) const { |
| 104 stream_->PrintProperty(name, d); | 104 stream_->PrintProperty(name, d); |
| 105 } | 105 } |
| 106 void AddProperty(const char* name, const Object& obj, bool ref = true) const { | 106 void AddProperty(const char* name, const Object& obj, bool ref = true) const { |
| 107 stream_->PrintProperty(name, obj, ref); | 107 stream_->PrintProperty(name, obj, ref); |
| 108 } | 108 } |
| 109 void AddPropertyF(const char* name, const char* format, ...) const | 109 void AddPropertyF(const char* name, const char* format, ...) const |
| 110 PRINTF_ATTRIBUTE(3, 4); | 110 PRINTF_ATTRIBUTE(3, 4); |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 JSONStream* stream_; | 113 JSONStream* stream_; |
| 114 | 114 |
| 115 friend class JSONArray; | 115 friend class JSONArray; |
| 116 |
| 117 DISALLOW_ALLOCATION(); |
| 118 DISALLOW_COPY_AND_ASSIGN(JSONObject); |
| 116 }; | 119 }; |
| 117 | 120 |
| 118 | 121 |
| 119 class JSONArray : public ValueObject { | 122 class JSONArray : public ValueObject { |
| 120 public: | 123 public: |
| 121 explicit JSONArray(JSONStream* stream) : stream_(stream) { | 124 explicit JSONArray(JSONStream* stream) : stream_(stream) { |
| 122 stream_->OpenArray(); | 125 stream_->OpenArray(); |
| 123 } | 126 } |
| 124 JSONArray(const JSONObject& obj, const char* name) : stream_(obj.stream_) { | 127 JSONArray(const JSONObject* obj, const char* name) : stream_(obj->stream_) { |
| 125 stream_->OpenArray(name); | 128 stream_->OpenArray(name); |
| 126 } | 129 } |
| 127 explicit JSONArray(const JSONArray& arr) : stream_(arr.stream_) { | 130 explicit JSONArray(const JSONArray* arr) : stream_(arr->stream_) { |
| 128 stream_->OpenArray(); | 131 stream_->OpenArray(); |
| 129 } | 132 } |
| 130 ~JSONArray() { | 133 ~JSONArray() { |
| 131 stream_->CloseArray(); | 134 stream_->CloseArray(); |
| 132 } | 135 } |
| 133 | 136 |
| 134 void AddValue(bool b) const { stream_->PrintValueBool(b); } | 137 void AddValue(bool b) const { stream_->PrintValueBool(b); } |
| 135 void AddValue(intptr_t i) const { stream_->PrintValue(i); } | 138 void AddValue(intptr_t i) const { stream_->PrintValue(i); } |
| 136 void AddValue(double d) const { stream_->PrintValue(d); } | 139 void AddValue(double d) const { stream_->PrintValue(d); } |
| 137 void AddValue(const char* s) const { stream_->PrintValue(s); } | 140 void AddValue(const char* s) const { stream_->PrintValue(s); } |
| 138 void AddValue(const Object& obj, bool ref = true) const { | 141 void AddValue(const Object& obj, bool ref = true) const { |
| 139 stream_->PrintValue(obj, ref); | 142 stream_->PrintValue(obj, ref); |
| 140 } | 143 } |
| 141 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); | 144 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); |
| 142 | 145 |
| 143 private: | 146 private: |
| 144 JSONStream* stream_; | 147 JSONStream* stream_; |
| 145 | 148 |
| 146 friend class JSONObject; | 149 friend class JSONObject; |
| 150 |
| 151 DISALLOW_ALLOCATION(); |
| 152 DISALLOW_COPY_AND_ASSIGN(JSONArray); |
| 147 }; | 153 }; |
| 148 | 154 |
| 149 } // namespace dart | 155 } // namespace dart |
| 150 | 156 |
| 151 #endif // VM_JSON_STREAM_H_ | 157 #endif // VM_JSON_STREAM_H_ |
| OLD | NEW |