diff --git a/example/condense/condense.cpp b/example/condense/condense.cpp index fdd704a..22c882e 100644 --- a/example/condense/condense.cpp +++ b/example/condense/condense.cpp @@ -27,7 +27,5 @@ int main(int argc, char* argv[]) { return 1; } - os.Flush(); - return 0; } diff --git a/example/pretty/pretty.cpp b/example/pretty/pretty.cpp index f304fbb..dae41b4 100644 --- a/example/pretty/pretty.cpp +++ b/example/pretty/pretty.cpp @@ -24,6 +24,5 @@ int main(int argc, char* argv[]) { return 1; } - os.Flush(); return 0; } diff --git a/include/rapidjson/filereadstream.h b/include/rapidjson/filereadstream.h index 284c931..06b9c18 100644 --- a/include/rapidjson/filereadstream.h +++ b/include/rapidjson/filereadstream.h @@ -25,6 +25,7 @@ public: // Not implemented void Put(char c) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } diff --git a/include/rapidjson/filestream.h b/include/rapidjson/filestream.h index 86d3f56..57ab0ba 100644 --- a/include/rapidjson/filestream.h +++ b/include/rapidjson/filestream.h @@ -21,6 +21,7 @@ public: char Take() { char c = current_; Read(); return c; } size_t Tell() const { return count_; } void Put(char c) { fputc(c, fp_); } + void Flush() { fflush(fp_); } // Not implemented char* PutBegin() { return 0; } diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 6faefde..6ed47e3 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -64,7 +64,8 @@ public: T* Bottom() { return (T*)stack_; } Allocator& GetAllocator() { return *allocator_; } - size_t GetSize() const { /*return stack_top_;*/ return stack_top_ - stack_; } + bool Empty() const { return stack_top_ == stack_; } + size_t GetSize() const { return stack_top_ - stack_; } size_t GetCapacity() const { return stack_capacity_; } private: diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 6f28293..403daa5 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -71,6 +71,8 @@ public: WriteIndent(); } Base::WriteEndObject(); + if (Base::level_stack_.Empty()) // end of json text + Base::stream_.Flush(); return *this; } @@ -91,6 +93,8 @@ public: WriteIndent(); } Base::WriteEndArray(); + if (Base::level_stack_.Empty()) // end of json text + Base::stream_.Flush(); return *this; } diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 14b0c3a..114519d 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -397,9 +397,9 @@ struct UTF32 { /*! \class rapidjson::Stream \brief Concept for reading and writing characters. - For read-only stream, no need to implement PutBegin(), Put() and PutEnd(). + For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd(). - For write-only stream, only need to implement Put(). + For write-only stream, only need to implement Put() and Flush(). \code concept Stream { @@ -422,6 +422,9 @@ concept Stream { //! Write a character. void Put(Ch c); + //! Flush the buffer. + void Flush(); + //! End the writing operation. //! \param begin The begin write pointer returned by PutBegin(). //! \return Number of characters written. @@ -455,6 +458,7 @@ struct GenericStringStream { Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } void Put(Ch c) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } size_t PutEnd(Ch* begin) { RAPIDJSON_ASSERT(false); return 0; } const Ch* src_; //!< Current read position. @@ -484,6 +488,7 @@ struct GenericInsituStringStream { // Write Ch* PutBegin() { return dst_ = src_; } void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } + void Flush() {} size_t PutEnd(Ch* begin) { return dst_ - begin; } Ch* src_; diff --git a/include/rapidjson/stringbuffer.h b/include/rapidjson/stringbuffer.h index d69e3d1..319bb44 100644 --- a/include/rapidjson/stringbuffer.h +++ b/include/rapidjson/stringbuffer.h @@ -19,6 +19,7 @@ struct GenericStringBuffer { GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} void Put(Ch c) { *stack_.template Push() = c; } + void Flush() {} void Clear() { stack_.Clear(); } diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 1d028cc..08fb81e 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -59,6 +59,8 @@ public: RAPIDJSON_ASSERT(!level_stack_.template Top()->inArray); level_stack_.template Pop(1); WriteEndObject(); + if (level_stack_.Empty()) // end of json text + stream_.Flush(); return *this; } @@ -74,6 +76,8 @@ public: RAPIDJSON_ASSERT(level_stack_.template Top()->inArray); level_stack_.template Pop(1); WriteEndArray(); + if (level_stack_.Empty()) // end of json text + stream_.Flush(); return *this; } //@} diff --git a/test/perftest/perftest.h b/test/perftest/perftest.h index 2c358ff..141c408 100644 --- a/test/perftest/perftest.h +++ b/test/perftest/perftest.h @@ -1,10 +1,10 @@ #ifndef PERFTEST_H_ #define PERFTEST_H_ -#define TEST_RAPIDJSON 1 -#define TEST_JSONCPP 1 -#define TEST_YAJL 1 - +#define TEST_RAPIDJSON 0 +#define TEST_JSONCPP 0 +#define TEST_YAJL 0 +#define TEST_PLATFORM 1 #if TEST_RAPIDJSON //#define RAPIDJSON_SSE2 //#define RAPIDJSON_SSE42 @@ -44,7 +44,6 @@ public: json_ = (char*)malloc(length_ + 1); fread(json_, 1, length_, fp); json_[length_] = '\0'; - length_++; // include the null terminator fclose(fp); // whitespace test