Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Unified Diff: runtime/vm/json_stream.h

Issue 23875015: - Base JSON stream printing on stack objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/json_stream.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/json_stream.h
===================================================================
--- runtime/vm/json_stream.h (revision 27342)
+++ runtime/vm/json_stream.h (working copy)
@@ -6,16 +6,38 @@
#define VM_JSON_STREAM_H_
#include "platform/json.h"
+#include "vm/allocation.h"
namespace dart {
class Object;
+class JSONObject;
+class JSONArray;
class JSONStream : ValueObject {
public:
- explicit JSONStream(TextBuffer* buffer);
+ explicit JSONStream(intptr_t buf_size = 256);
~JSONStream();
+ const char* ToCString() { return buffer_.buf(); }
+
+ void SetArguments(const char** arguments, intptr_t num_arguments);
+ void SetOptions(const char** option_keys, const char** option_values,
+ intptr_t num_options);
+
+ intptr_t num_arguments() const { return num_arguments_; }
+ const char* GetArgument(intptr_t i) const {
+ return arguments_[i];
+ }
+ intptr_t num_options() const { return num_options_; }
+ const char* GetOptionKey(intptr_t i) const {
+ return option_keys_[i];
+ }
+ const char* GetOptionValue(intptr_t i) const {
+ return option_values_[i];
+ }
+
+ private:
void Clear();
void OpenObject(const char* property_name = NULL);
@@ -36,38 +58,94 @@
void PrintProperty(const char* name, double d);
void PrintProperty(const char* name, const char* s);
void PrintfProperty(const char* name, const char* format, ...)
- PRINTF_ATTRIBUTE(3, 4);
+ PRINTF_ATTRIBUTE(3, 4);
void PrintProperty(const char* name, const Object& o, bool ref = true);
- void SetArguments(const char** arguments, intptr_t num_arguments);
- void SetOptions(const char** option_keys, const char** option_values,
- intptr_t num_options);
-
- intptr_t num_arguments() const { return num_arguments_; }
- const char* GetArgument(intptr_t i) const {
- return arguments_[i];
- }
- intptr_t num_options() const { return num_options_; }
- const char* GetOptionKey(intptr_t i) const {
- return option_keys_[i];
- }
- const char* GetOptionValue(intptr_t i) const {
- return option_values_[i];
- }
-
- private:
void PrintPropertyName(const char* name);
void PrintCommaIfNeeded();
bool NeedComma();
+
+ intptr_t nesting_level() const { return open_objects_; }
+
intptr_t open_objects_;
- TextBuffer* buffer_;
+ TextBuffer buffer_;
const char** arguments_;
intptr_t num_arguments_;
const char** option_keys_;
const char** option_values_;
intptr_t num_options_;
+
+ friend class JSONObject;
+ friend class JSONArray;
};
+
+class JSONObject : public ValueObject {
+ public:
+ explicit JSONObject(JSONStream* stream) : stream_(stream) {
+ stream_->OpenObject();
+ }
+ JSONObject(const JSONObject& obj, const char* name) : stream_(obj.stream_) {
+ stream_->OpenObject(name);
+ }
+ explicit JSONObject(const JSONArray& arr);
+
+ ~JSONObject() {
+ stream_->CloseObject();
+ }
+
+ void AddProperty(const char* name, bool b) const {
+ stream_->PrintPropertyBool(name, b);
+ }
+ void AddProperty(const char* name, intptr_t i) const {
+ stream_->PrintProperty(name, i);
+ }
+ void AddProperty(const char* name, double d) const {
+ stream_->PrintProperty(name, d);
+ }
+ void AddProperty(const char* name, const Object& obj, bool ref = true) const {
+ stream_->PrintProperty(name, obj, ref);
+ }
+ void AddPropertyF(const char* name, const char* format, ...) const
+ PRINTF_ATTRIBUTE(3, 4);
+
+ private:
+ JSONStream* stream_;
+
+ friend class JSONArray;
+};
+
+
+class JSONArray : public ValueObject {
+ public:
+ explicit JSONArray(JSONStream* stream) : stream_(stream) {
+ stream_->OpenArray();
+ }
+ JSONArray(const JSONObject& obj, const char* name) : stream_(obj.stream_) {
+ stream_->OpenArray(name);
+ }
+ JSONArray(const JSONArray& arr) : stream_(arr.stream_) {
+ stream_->OpenArray();
+ }
+ ~JSONArray() {
+ stream_->CloseArray();
+ }
+
+ void AddValue(bool b) const { stream_->PrintValueBool(b); }
+ void AddValue(intptr_t i) const { stream_->PrintValue(i); }
+ void AddValue(double d) const { stream_->PrintValue(d); }
+ void AddValue(const char* s) const { stream_->PrintValue(s); }
+ void AddValue(const Object& obj, bool ref = true) const {
+ stream_->PrintValue(obj, ref);
+ }
+ void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3);
+
+ private:
+ JSONStream* stream_;
+
+ friend class JSONObject;
+};
+
} // namespace dart
#endif // VM_JSON_STREAM_H_
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/json_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698