added wxArrayString::swap()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55549 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -291,6 +291,7 @@ All:
|
|||||||
- Corrected bug in wxTimeSpan::IsShorterThan() for equal time spans.
|
- Corrected bug in wxTimeSpan::IsShorterThan() for equal time spans.
|
||||||
- Use std::unordered_{map,set} for wxHashMap/Set if available (Jan van Dijk).
|
- Use std::unordered_{map,set} for wxHashMap/Set if available (Jan van Dijk).
|
||||||
- Added wxString::Capitalize() and MakeCapitalized().
|
- Added wxString::Capitalize() and MakeCapitalized().
|
||||||
|
- Added wxArrayString::swap().
|
||||||
- Added wxSHUTDOWN_LOGOFF and wxSHUTDOWN_FORCE wxShutdown() flags (troelsk).
|
- Added wxSHUTDOWN_LOGOFF and wxSHUTDOWN_FORCE wxShutdown() flags (troelsk).
|
||||||
|
|
||||||
All (Unix):
|
All (Unix):
|
||||||
|
@@ -301,6 +301,25 @@ public:
|
|||||||
void reserve(size_type n) /* base::reserve*/;
|
void reserve(size_type n) /* base::reserve*/;
|
||||||
void resize(size_type n, value_type v = value_type());
|
void resize(size_type n, value_type v = value_type());
|
||||||
size_type size() const { return GetCount(); }
|
size_type size() const { return GetCount(); }
|
||||||
|
void swap(wxArrayString& other)
|
||||||
|
{
|
||||||
|
// not sure if we can rely on having std::swap() everywhere so do it
|
||||||
|
// manually
|
||||||
|
const size_t savedSize = m_nSize;
|
||||||
|
const size_t savedCount = m_nCount;
|
||||||
|
wxString * const savedItems = m_pItems;
|
||||||
|
const bool savedAutoSort = m_autoSort;
|
||||||
|
|
||||||
|
m_nSize = other.m_nSize;
|
||||||
|
m_nCount = other.m_nCount;
|
||||||
|
m_pItems = other.m_pItems;
|
||||||
|
m_autoSort = other.m_autoSort;
|
||||||
|
|
||||||
|
other.m_nSize = savedSize;
|
||||||
|
other.m_nCount = savedCount;
|
||||||
|
other.m_pItems = savedItems;
|
||||||
|
other.m_autoSort = savedAutoSort;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Init(bool autoSort); // common part of all ctors
|
void Init(bool autoSort); // common part of all ctors
|
||||||
|
@@ -170,6 +170,7 @@ private:
|
|||||||
CPPUNIT_TEST( wxArrayCharTest );
|
CPPUNIT_TEST( wxArrayCharTest );
|
||||||
CPPUNIT_TEST( TestSTL );
|
CPPUNIT_TEST( TestSTL );
|
||||||
CPPUNIT_TEST( Alloc );
|
CPPUNIT_TEST( Alloc );
|
||||||
|
CPPUNIT_TEST( Swap );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void wxStringArrayTest();
|
void wxStringArrayTest();
|
||||||
@@ -182,6 +183,7 @@ private:
|
|||||||
void wxArrayCharTest();
|
void wxArrayCharTest();
|
||||||
void TestSTL();
|
void TestSTL();
|
||||||
void Alloc();
|
void Alloc();
|
||||||
|
void Swap();
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(ArraysTestCase)
|
DECLARE_NO_COPY_CLASS(ArraysTestCase)
|
||||||
};
|
};
|
||||||
@@ -555,6 +557,28 @@ void ArraysTestCase::Alloc()
|
|||||||
CPPUNIT_ASSERT_EQUAL( 9, a[1] );
|
CPPUNIT_ASSERT_EQUAL( 9, a[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArraysTestCase::Swap()
|
||||||
|
{
|
||||||
|
wxArrayString a1, a2;
|
||||||
|
a1.swap(a2);
|
||||||
|
CPPUNIT_ASSERT( a1.empty() && a2.empty() );
|
||||||
|
|
||||||
|
a1.push_back("Foo");
|
||||||
|
a1.swap(a2);
|
||||||
|
CPPUNIT_ASSERT( a1.empty() );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( 1, a2.size() );
|
||||||
|
|
||||||
|
a1.push_back("Bar");
|
||||||
|
a1.push_back("Baz");
|
||||||
|
a2.swap(a1);
|
||||||
|
CPPUNIT_ASSERT_EQUAL( 1, a1.size() );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( 2, a2.size() );
|
||||||
|
|
||||||
|
a1.swap(a2);
|
||||||
|
CPPUNIT_ASSERT_EQUAL( 2, a1.size() );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( 1, a2.size() );
|
||||||
|
}
|
||||||
|
|
||||||
void ArraysTestCase::TestSTL()
|
void ArraysTestCase::TestSTL()
|
||||||
{
|
{
|
||||||
wxArrayInt list1;
|
wxArrayInt list1;
|
||||||
|
Reference in New Issue
Block a user