]> git.saurik.com Git - wxWidgets.git/commitdiff
wxStringList::copy ctor and assignment operator added (very inefficient
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 27 Nov 1998 16:31:27 +0000 (16:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 27 Nov 1998 16:31:27 +0000 (16:31 +0000)
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
src/common/list.cpp

index ee4df382e9fd70dd0aff1d69573f333d101250fa..696162ab4400a75e5048d57fdc2e3ecea54cff17 100644 (file)
@@ -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
index 2ee408969295648b2166da77c99153c3513a505a..a689f0b40eaea85cf0516bd96bed5cf7419692af 100644 (file)
@@ -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, ...)