To simplify the error handling, this commit adds an implicit conversion
of GenericDocument to ParseResult, allowing code like (already in the
documentation):
ParseResult ok = doc.Parse(json);
if (!ok) // ...
Keeping the DOM unchanged in case of an error is the intended
behaviour according to the [documentation] [1].
Instead of forcing the value to `kNullType` before starting the
parsing, store the parsed value upon success via regular move.
[1]: https://miloyip.github.io/rapidjson/md_doc_dom.html#ParseError
As reported in #387, silently moving a `GenericDocument` to a
`GenericValue` can lead to object slicing and premature deletion of
the owning allocator of the (surviving) `GenericValue`.
To reduce this risk, prohibit move construction of a `GenericValue`
from a `GenericDocument`.
@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).
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.
According to the C/C++ standards, calling `memcpy(NULL, NULL, 0)` is
undefined behaviour. Recent GCC versions may rely on this by optimizing
NULL pointer checks more aggressively, see [1].
This patch tries to avoid calling std::memcpy with zero elements.
As a side effect, explicitly return NULL when requesting an empty block
from MemoryPoolAllocator::Malloc.
This may be related to #301.
[1] https://gcc.gnu.org/gcc-4.9/porting_to.html
As discovered by @felipegb94, there are missing overloads to the
`GenericValue::AddMember<T>` template function, taking an explicit
`GenericValue&` as a name and accepting arbitrary primitive values.
This patch adds the missing overloads. The `StringRefType` overload
is needed to disambiguate the addition of a string literal as
value.
Some tests are added to `TEST(Value, Object)` in `valuetest.cpp`.
The GenericValue "copy" constructor (with Allocator) uses a temporary
GenericDocument object to perform the deep copying with the provided
allocator. This leads to the temporary allocation of the `Stack`
memory, even in case of shallow values (numbers, etc.).
This patch improves the performance of this operation by only resorting
the the SAX Handler implementation in case of Array or Object values.
As mentioned in #181, some environments may require adaptations to
the internal calls to the global `new`/`delete` operators, like
adding explicit `NULL` checks to `delete.
This patch adds two new macros
* RAPIDJSON_NEW(x)
* RAPIDJSON_DELETE(x)
to allow user-defined expressions in these cases.
This fixes#181 in an alternative manner.
In the original disambiguation fix for `GenericValue::operator[]` (#170),
the documentation has been missing, which led to quite badly rendered
Doxygen pages.
During a cleanup, I've realized that a much simpler disambiguation is
possible:
````cpp
GenericValue& operator[](SizeType idx); // array
template <typename T>
GenericValue& operator[](T* name); // object
````
This approach works, as non-template functions are preferred over
template functions.
In order to improve the error messages, the pointer type is restricted
to `(const) Ch`.
Update `tutorial.md` to drop the ambiguity warning.