diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2014-06-08 01:57:54 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2014-09-30 09:56:38 +0200 |
commit | 9f10d125f6dc622e7cd7f303e28ecf9efede0035 (patch) | |
tree | 68e62cd0993f35e32c3e3a3f6de57e1fd63b0132 | |
parent | Merge common code of sw format lists (diff) | |
download | core-9f10d125f6dc622e7cd7f303e28ecf9efede0035.tar.gz core-9f10d125f6dc622e7cd7f303e28ecf9efede0035.zip |
Add sorted vector special case for delete all
Specializes DeleteAndDestroyAll() to optionally keep the default
item.
Change-Id: I570fc6614a59fcf08c4569d44873ed79f4af5eda
(cherry picked from commit f4efc9051a25f52ed218c515dc8c5a75f54c8fbd)
-rw-r--r-- | include/o3tl/sorted_vector.hxx | 13 | ||||
-rw-r--r-- | o3tl/qa/test-sorted_vector.cxx | 4 |
2 files changed, 14 insertions, 3 deletions
diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx index 7fd23234e550..551a06d6bc68 100644 --- a/include/o3tl/sorted_vector.hxx +++ b/include/o3tl/sorted_vector.hxx @@ -195,11 +195,18 @@ public: } /* Clear() elements in the vector, and free them one by one. */ - void DeleteAndDestroyAll() + void DeleteAndDestroyAll( bool keepDefault=false ) { - for( const_iterator it = begin(); it != end(); ++it ) + if ( empty() ) + return; + + const int _Offset = (keepDefault && mOffset) ? mOffset : 0; + for( const_iterator it = begin() + _Offset; it != end(); ++it ) delete *it; - clear(); + if ( _Offset ) + base_t::erase( begin_nonconst() + _Offset, end_nonconst() ); + else + clear(); } // fdo#58793: some existing code in Writer (SwpHintsArray) diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx index 7b4dacaac5f3..602998b82f89 100644 --- a/o3tl/qa/test-sorted_vector.cxx +++ b/o3tl/qa/test-sorted_vector.cxx @@ -349,6 +349,10 @@ public: CPPUNIT_ASSERT( aVec[4] == p3 ); CPPUNIT_ASSERT( aVec[5] == p4 ); + aVec.DeleteAndDestroyAll( true ); + CPPUNIT_ASSERT( aVec.size() == 1 ); + aVec.DeleteAndDestroyAll( true ); + CPPUNIT_ASSERT( aVec.size() == 1 ); aVec.DeleteAndDestroyAll(); } |