From 413144a8b21270883bfe9d20723441ac12b414dc Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Fri, 26 Jun 2015 16:00:49 +0200 Subject: [PATCH 1/3] Add GenericDocument ctor overload to specify JSON type. It unifies the interfaces with Value where kXXXType can be passed into constructor. It enables shortcut that helps to avoid extra SetXXX() call following construction of a document. --- include/rapidjson/document.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 889cdfa..1b3a4f3 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1748,6 +1748,13 @@ public: typedef GenericValue ValueType; //!< Value type of the document. typedef Allocator AllocatorType; //!< Allocator type from template parameter. + GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : + GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() + { + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + } + //! Constructor /*! \param allocator Optional allocator for allocating memory. \param stackCapacity Optional initial capacity of stack in bytes. From a0177ca210c2e9e047ec747a71cca7c3d7683ece Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 30 Jun 2015 10:28:07 +0200 Subject: [PATCH 2/3] Add documentation for new GenericDocument ctor taking object type. Update also documentation of the existing GenericDocument constructor. --- include/rapidjson/document.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 1b3a4f3..026c2fb 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1748,6 +1748,13 @@ public: typedef GenericValue ValueType; //!< Value type of the document. typedef Allocator AllocatorType; //!< Allocator type from template parameter. + //! Constructor + /*! Creates an empty document of specified type. + \param type Mandatory type of object to create. + \param allocator Optional allocator for allocating memory. + \param stackCapacity Optional initial capacity of stack in bytes. + \param stackAllocator Optional allocator for allocating memory for stack. + */ GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { @@ -1756,7 +1763,8 @@ public: } //! Constructor - /*! \param allocator Optional allocator for allocating memory. + /*! Creates an empty document which type is Null. + \param allocator Optional allocator for allocating memory. \param stackCapacity Optional initial capacity of stack in bytes. \param stackAllocator Optional allocator for allocating memory for stack. */ From 8197805208304499487e0719555d084625606850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Wed, 1 Jul 2015 22:36:26 +0200 Subject: [PATCH 3/3] Add explicit specifier to GenericDocument ctor. @pah recommended to mark this constructor as explicit to avoid accidentally creating a temporary GenericDocument from a Type enum value (because all arguments but the first one are optional). --- include/rapidjson/document.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 026c2fb..a20d644 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1755,7 +1755,7 @@ public: \param stackCapacity Optional initial capacity of stack in bytes. \param stackAllocator Optional allocator for allocating memory for stack. */ - GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : + explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { if (!allocator_)