Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiloyip <miloyip@gmail.com>2015-05-02 16:52:49 +0300
committermiloyip <miloyip@gmail.com>2015-05-02 16:52:49 +0300
commit32b45f6e6d15b229ea1907e9569e4792bff6e207 (patch)
treee58a1ffa53cc7b73a04486e6ce0766b01fa0ced5 /include/rapidjson/pointer.h
parent2ddbd09031b90765e31fc31a7607e3e0248a17d1 (diff)
Add GetWithDefault() overloads
Diffstat (limited to 'include/rapidjson/pointer.h')
-rw-r--r--include/rapidjson/pointer.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h
index bc2795fe..16d2e602 100644
--- a/include/rapidjson/pointer.h
+++ b/include/rapidjson/pointer.h
@@ -248,6 +248,28 @@ public:
return v;
}
+ ValueType& GetWithDefault(ValueType& root, GenericStringRef<Ch> defaultValue, typename ValueType::AllocatorType& allocator) const {
+ ValueType v(defaultValue);
+ return GetWithDefault(root, v, allocator);
+ }
+
+ ValueType& GetWithDefault(ValueType& root, const Ch* defaultValue, typename ValueType::AllocatorType& allocator) const {
+ bool alreadyExist;
+ Value& v = Create(root, allocator, &alreadyExist);
+ if (!alreadyExist) {
+ Value clone(defaultValue, allocator); // This has overhead, so do it inside if.
+ v = clone;
+ }
+ return v;
+ }
+
+ template <typename T>
+ RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
+ GetWithDefault(ValueType& root, T defaultValue, typename ValueType::AllocatorType& allocator) const {
+ ValueType v(defaultValue);
+ return GetWithDefault(root, v, allocator);
+ }
+
// Move semantics, create parents if non-exist
ValueType& Set(ValueType& root, ValueType& value, typename ValueType::AllocatorType& allocator) const {
return Create(root, allocator) = value;