From db9504c5049e9e89588b3947ac9ecce524b820b8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Nov 1998 16:31:27 +0000 Subject: [PATCH] wxStringList::copy ctor and assignment operator added (very inefficient because they don't take advantage of wxString ref counting) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1073 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/list.h | 11 ++++++++++- src/common/list.cpp | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/wx/list.h b/include/wx/list.h index ee4df382e9..696162ab44 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -189,7 +189,7 @@ public: // operations // delete all nodes - virtual void Clear(); + void Clear(); // instruct it to destroy user data when deleting nodes void DeleteContents(bool destroy) { m_destroy = destroy; } @@ -437,6 +437,12 @@ public: wxStringList() { DeleteContents(TRUE); } wxStringList(const char *first ...); + // copying the string list: the strings are copied, too (extremely + // inefficient!) + wxStringList(const wxStringList& other) { DoCopy(other); } + wxStringList& operator=(const wxStringList& other) + { Clear(); DoCopy(other); return *this; } + // operations // makes a copy of the string wxNode *Add(const char *s) @@ -456,6 +462,9 @@ public: wxNode *First() const { return (wxNode *)GetFirst(); } wxNode *Last() const { return (wxNode *)GetLast(); } wxNode *Nth(size_t index) const { return (wxNode *)Item(index); } + +private: + void DoCopy(const wxStringList&); // common part of copy ctor and operator= }; #endif // wxLIST_COMPATIBILITY diff --git a/src/common/list.cpp b/src/common/list.cpp index 2ee4089692..a689f0b40e 100644 --- a/src/common/list.cpp +++ b/src/common/list.cpp @@ -491,6 +491,17 @@ void wxStringListNode::DeleteData() delete [] (char *)GetData(); } +void wxStringList::DoCopy(const wxStringList& other) +{ + wxASSERT( GetCount() == 0 ); // this list must be empty before copying! + + size_t count = other.GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + Add(other.Item(n)->GetData()); + } +} + // Variable argument list, terminated by a zero // Makes new storage for the strings wxStringList::wxStringList (const char *first, ...)