Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenericValue: add optional support for std::string #107

Merged
merged 4 commits into from
Aug 20, 2014

Conversation

pah
Copy link
Contributor

@pah pah commented Aug 20, 2014

Some users want to use RapidJSON with std::string objects. This pull-request adds an (opt-in) feature to include some basic support. The implementation uses std::basic_string<Ch> as generic string type.

GenericValue's string support currently covers:

  • construction / SetString
  • comparison

No special APIs for AddMember or PushBack have been added, as std::string most probably requires copying (or an explicit StringRef() call). Using the GenericValue constructor should be sufficient:

std::string str;
d.AddMember("string", Value(str, d.GetAllocator()).Move(), d.GetAllocator());

The functionality needs to be enabled by defining RAPIDJSON_HAS_STDSTRING. The Travis CI config has been updated to add this define by default to include the tests.

Last, but not least, the comparison operators have been refactored to simplify the addition of new overloads (see 702b45b). With the new forwarding structure, only a single function needs to be added to extend the comparison support.

pah added 4 commits August 20, 2014 07:07
By restructuring the call forwarding of the various operator== and
operator!= overloads, new overloads can be added by simply adding an
additional member operator==.

Additionally, the "Ch*" overloads are dropped in favour of an SFINAE
version that removes the pointer variants from matching the templated
operator== (see also operator=).
Some users may want to use RapidJSON with std::string objects.  This commits
adds an (opt-in) feature to include some basic support.  The implementation
uses std::basic_string<Ch> as generic string type.

Support currently covers:
 * construction
 * comparison

No special APIs for AddMember or PushBack have been added, as std::string
most probably requires copying (or an explicit StringRef() call).
pah referenced this pull request in Urban82/rapidjsonxml Aug 20, 2014
miloyip added a commit that referenced this pull request Aug 20, 2014
GenericValue: add optional support for std::string
@miloyip miloyip merged commit df70ee8 into Tencent:master Aug 20, 2014
@pah pah deleted the feature/basic_string branch August 20, 2014 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants