| 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 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 class Field; |
| 14 class Instance; |
| 15 class JSONArray; |
| 16 class JSONObject; |
| 13 class Object; | 17 class Object; |
| 14 class JSONObject; | |
| 15 class JSONArray; | |
| 16 | 18 |
| 17 class JSONStream : ValueObject { | 19 class JSONStream : ValueObject { |
| 18 public: | 20 public: |
| 19 explicit JSONStream(intptr_t buf_size = 256); | 21 explicit JSONStream(intptr_t buf_size = 256); |
| 20 ~JSONStream(); | 22 ~JSONStream(); |
| 21 | 23 |
| 22 TextBuffer* buffer() { return &buffer_; } | 24 TextBuffer* buffer() { return &buffer_; } |
| 23 const char* ToCString() { return buffer_.buf(); } | 25 const char* ToCString() { return buffer_.buf(); } |
| 24 | 26 |
| 25 void SetArguments(const char** arguments, intptr_t num_arguments); | 27 void SetArguments(const char** arguments, intptr_t num_arguments); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 46 | 48 |
| 47 void OpenArray(const char* property_name = NULL); | 49 void OpenArray(const char* property_name = NULL); |
| 48 void CloseArray(); | 50 void CloseArray(); |
| 49 | 51 |
| 50 void PrintValueBool(bool b); | 52 void PrintValueBool(bool b); |
| 51 void PrintValue(intptr_t i); | 53 void PrintValue(intptr_t i); |
| 52 void PrintValue(double d); | 54 void PrintValue(double d); |
| 53 void PrintValue(const char* s); | 55 void PrintValue(const char* s); |
| 54 void PrintfValue(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 56 void PrintfValue(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 55 void PrintValue(const Object& o, bool ref = true); | 57 void PrintValue(const Object& o, bool ref = true); |
| 58 void PrintValue(const Field& f, const Instance& instance, bool ref = true); |
| 56 | 59 |
| 57 void PrintPropertyBool(const char* name, bool b); | 60 void PrintPropertyBool(const char* name, bool b); |
| 58 void PrintProperty(const char* name, intptr_t i); | 61 void PrintProperty(const char* name, intptr_t i); |
| 59 void PrintProperty(const char* name, double d); | 62 void PrintProperty(const char* name, double d); |
| 60 void PrintProperty(const char* name, const char* s); | 63 void PrintProperty(const char* name, const char* s); |
| 61 void PrintfProperty(const char* name, const char* format, ...) | 64 void PrintfProperty(const char* name, const char* format, ...) |
| 62 PRINTF_ATTRIBUTE(3, 4); | 65 PRINTF_ATTRIBUTE(3, 4); |
| 63 void PrintProperty(const char* name, const Object& o, bool ref = true); | 66 void PrintProperty(const char* name, const Object& o, bool ref = true); |
| 64 | 67 |
| 65 void PrintPropertyName(const char* name); | 68 void PrintPropertyName(const char* name); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 stream_->CloseArray(); | 141 stream_->CloseArray(); |
| 139 } | 142 } |
| 140 | 143 |
| 141 void AddValue(bool b) const { stream_->PrintValueBool(b); } | 144 void AddValue(bool b) const { stream_->PrintValueBool(b); } |
| 142 void AddValue(intptr_t i) const { stream_->PrintValue(i); } | 145 void AddValue(intptr_t i) const { stream_->PrintValue(i); } |
| 143 void AddValue(double d) const { stream_->PrintValue(d); } | 146 void AddValue(double d) const { stream_->PrintValue(d); } |
| 144 void AddValue(const char* s) const { stream_->PrintValue(s); } | 147 void AddValue(const char* s) const { stream_->PrintValue(s); } |
| 145 void AddValue(const Object& obj, bool ref = true) const { | 148 void AddValue(const Object& obj, bool ref = true) const { |
| 146 stream_->PrintValue(obj, ref); | 149 stream_->PrintValue(obj, ref); |
| 147 } | 150 } |
| 151 // Print a field bound to a value. Value is looked up from 'instance'. |
| 152 void AddValue(const Field& field, |
| 153 const Instance& instance, |
| 154 bool ref = true) const { |
| 155 stream_->PrintValue(field, instance, ref); |
| 156 } |
| 148 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); | 157 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); |
| 149 | 158 |
| 150 private: | 159 private: |
| 151 JSONStream* stream_; | 160 JSONStream* stream_; |
| 152 | 161 |
| 153 friend class JSONObject; | 162 friend class JSONObject; |
| 154 | 163 |
| 155 DISALLOW_ALLOCATION(); | 164 DISALLOW_ALLOCATION(); |
| 156 DISALLOW_COPY_AND_ASSIGN(JSONArray); | 165 DISALLOW_COPY_AND_ASSIGN(JSONArray); |
| 157 }; | 166 }; |
| 158 | 167 |
| 159 } // namespace dart | 168 } // namespace dart |
| 160 | 169 |
| 161 #endif // VM_JSON_STREAM_H_ | 170 #endif // VM_JSON_STREAM_H_ |
| OLD | NEW |