@@ -844,6 +844,12 @@ class GenericValue {
844844 template <typename SourceAllocator>
845845 const GenericValue& operator [](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast <GenericValue&>(*this )[name]; }
846846
847+ #if RAPIDJSON_HAS_STDSTRING
848+ // ! Get a value from an object associated with name (string object).
849+ GenericValue& operator [](const std::basic_string<Ch>& name) { return (*this )[GenericValue (StringRef (name))]; }
850+ const GenericValue& operator [](const std::basic_string<Ch>& name) const { return (*this )[GenericValue (StringRef (name))]; }
851+ #endif
852+
847853 // ! Const member iterator
848854 /* ! \pre IsObject() == true */
849855 ConstMemberIterator MemberBegin () const { RAPIDJSON_ASSERT (IsObject ()); return ConstMemberIterator (data_.o .members ); }
@@ -867,6 +873,18 @@ class GenericValue {
867873 */
868874 bool HasMember (const Ch* name) const { return FindMember (name) != MemberEnd (); }
869875
876+ #if RAPIDJSON_HAS_STDSTRING
877+ // ! Check whether a member exists in the object with string object.
878+ /* !
879+ \param name Member name to be searched.
880+ \pre IsObject() == true
881+ \return Whether a member with that name exists.
882+ \note It is better to use FindMember() directly if you need the obtain the value as well.
883+ \note Linear time complexity.
884+ */
885+ bool HasMember (const std::basic_string<Ch>& name) const { return FindMember (name) != MemberEnd (); }
886+ #endif
887+
870888 // ! Check whether a member exists in the object with GenericValue name.
871889 /* !
872890 This version is faster because it does not need a StrLen(). It can also handle string with null character.
@@ -923,6 +941,18 @@ class GenericValue {
923941 }
924942 template <typename SourceAllocator> ConstMemberIterator FindMember (const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast <GenericValue&>(*this ).FindMember (name); }
925943
944+ #if RAPIDJSON_HAS_STDSTRING
945+ // ! Find member by string object name.
946+ /* !
947+ \param name Member name to be searched.
948+ \pre IsObject() == true
949+ \return Iterator to member, if it exists.
950+ Otherwise returns \ref MemberEnd().
951+ */
952+ MemberIterator FindMember (const std::basic_string<Ch>& name) { return FindMember (StringRef (name)); }
953+ ConstMemberIterator FindMember (const std::basic_string<Ch>& name) const { return FindMember (StringRef (name)); }
954+ #endif
955+
926956 // ! Add a member (name-value pair) to the object.
927957 /* ! \param name A string value as name of member.
928958 \param value Value of any type.
@@ -969,6 +999,22 @@ class GenericValue {
969999 return AddMember (name, v, allocator);
9701000 }
9711001
1002+ #if RAPIDJSON_HAS_STDSTRING
1003+ // ! Add a string object as member (name-value pair) to the object.
1004+ /* ! \param name A string value as name of member.
1005+ \param value constant string reference as value of member.
1006+ \param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
1007+ \return The value itself for fluent API.
1008+ \pre IsObject()
1009+ \note This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below.
1010+ \note Amortized Constant time complexity.
1011+ */
1012+ GenericValue& AddMember (GenericValue& name, std::basic_string<Ch>& value, Allocator& allocator) {
1013+ GenericValue v (value, allocator);
1014+ return AddMember (name, v, allocator);
1015+ }
1016+ #endif
1017+
9721018 // ! Add any primitive value as member (name-value pair) to the object.
9731019 /* ! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t
9741020 \param name A string value as name of member.
@@ -1087,6 +1133,10 @@ class GenericValue {
10871133 return RemoveMember (n);
10881134 }
10891135
1136+ #if RAPIDJSON_HAS_STDSTRING
1137+ bool RemoveMember (const std::basic_string<Ch>& name) { return RemoveMember (GenericValue (StringRef (name))); }
1138+ #endif
1139+
10901140 template <typename SourceAllocator>
10911141 bool RemoveMember (const GenericValue<Encoding, SourceAllocator>& name) {
10921142 MemberIterator m = FindMember (name);
@@ -1741,7 +1791,7 @@ class GenericDocument : public GenericValue<Encoding, Allocator> {
17411791 template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
17421792 GenericDocument& ParseStream (InputStream& is) {
17431793 ValueType::SetNull (); // Remove existing root if exist
1744- GenericReader<SourceEncoding, Encoding, Allocator > reader (&GetAllocator ());
1794+ GenericReader<SourceEncoding, Encoding, StackAllocator > reader (&stack_. GetAllocator ());
17451795 ClearStackOnExit scope (*this );
17461796 parseResult_ = reader.template Parse <parseFlags>(is, *this );
17471797 if (parseResult_) {
0 commit comments