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
This commit is contained in:
parent
1805077dc2
commit
db9504c504
@ -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
|
||||
|
@ -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, ...)
|
||||
|
Loading…
Reference in New Issue
Block a user