diff options
author | miloyip <miloyip@gmail.com> | 2014-07-31 10:22:59 +0400 |
---|---|---|
committer | miloyip <miloyip@gmail.com> | 2014-07-31 10:22:59 +0400 |
commit | 0f7d2dad519a115c0405aa83f7788cec455d870f (patch) | |
tree | bd6fdf544743bac34cd736b194cc4a496409c269 /include | |
parent | 88a9716c6c6a9d7b57a5a6a72b589d55aa7c4177 (diff) |
Add 2 overloads of Erase() for removing elements of array.
Diffstat (limited to 'include')
-rw-r--r-- | include/rapidjson/document.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 4448600b..77250a30 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -933,6 +933,38 @@ int z = a[0u].GetInt(); // This works too. data_.a.elements[--data_.a.size].~GenericValue();
return *this;
}
+
+ //! Remove an element of array by iterator.
+ /*!
+ \param pos iterator to the element to remove
+ \pre IsArray() == true
+ \return Iterator following the removed element. If the iterator pos refers to the last element, the End() iterator is returned.
+ */
+ ValueIterator Erase(ValueIterator pos) {
+ return Erase(pos, pos + 1);
+ }
+
+ //! Remove elements in the range [first, last) of the array.
+ /*!
+ \param pos iterator to the element to remove
+ \param first,last range of elements to remove
+ \pre IsArray() == true
+ \return Iterator following the last removed element. If the iterator pos refers to the last element, the End() iterator is returned.
+ */
+ ValueIterator Erase(ValueIterator first, ValueIterator last) {
+ RAPIDJSON_ASSERT(IsArray());
+ RAPIDJSON_ASSERT(data_.a.size > 0);
+ RAPIDJSON_ASSERT(data_.a.elements != 0);
+ RAPIDJSON_ASSERT(first >= Begin());
+ RAPIDJSON_ASSERT(first <= last);
+ RAPIDJSON_ASSERT(last <= End());
+ for (ValueIterator itr = first; itr != last; ++itr)
+ itr->~GenericValue();
+ memmove(first, last, (End() - last) * sizeof(GenericValue));
+ data_.a.size -= (last - first);
+ return first;
+ }
+
//@}
//!@name Number
|