X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/46dc76ba3573649a9ed7c7aff6dc677f533eee11..dcf40a56e7b09fc5472edc1d4471e7954c0da40d:/src/common/list.cpp diff --git a/src/common/list.cpp b/src/common/list.cpp index c36e7f7953..80841b6ea6 100644 --- a/src/common/list.cpp +++ b/src/common/list.cpp @@ -24,6 +24,7 @@ #include "wx/defs.h" #include "wx/list.h" #include "wx/utils.h" +#include #endif // Sun CC compatibility (interference with xview/pkg.h, apparently...) @@ -51,7 +52,7 @@ wxNode::wxNode (wxList * the_list, wxNode * last_one, wxNode * next_one, previous = last_one; next = next_one; list = the_list; - key.string = NULL; + key.string = (char *) NULL; if (previous) previous->next = this; @@ -125,8 +126,8 @@ wxNode::~wxNode (void) wxList::wxList (void) { - first_node = NULL; - last_node = NULL; + first_node = (wxNode *) NULL; + last_node = (wxNode *) NULL; n = 0; destroy_data = 0; key_type = wxKEY_NONE; @@ -134,12 +135,12 @@ wxList::wxList (void) wxList::wxList (int N, wxObject * Objects[]) { - wxNode *last = NULL; + wxNode *last = (wxNode *) NULL; int i; for (i = 0; i < N; i++) { - wxNode *next = new wxNode (this, last, NULL, Objects[i]); + wxNode *next = new wxNode (this, last, (wxNode *) NULL, Objects[i]); last = next; if (i == 0) first_node = next; @@ -153,8 +154,8 @@ wxList::wxList (const unsigned int the_key_type) { n = 0; destroy_data = 0; - first_node = NULL; - last_node = NULL; + first_node = (wxNode *) NULL; + last_node = (wxNode *) NULL; key_type = the_key_type; } @@ -166,7 +167,7 @@ wxList::wxList (wxObject * first_one...) va_start (ap, first_one); - wxNode *last = new wxNode (this, NULL, NULL, first_one); + wxNode *last = new wxNode (this, (wxNode *) NULL, (wxNode *) NULL, first_one); first_node = last; n = 1; @@ -182,7 +183,7 @@ wxList::wxList (wxObject * first_one...) break; else { - wxNode *node = new wxNode (this, last, NULL, object); + wxNode *node = new wxNode (this, last, (wxNode *) NULL, object); last = node; n++; } @@ -212,7 +213,7 @@ wxList::~wxList (void) wxNode *wxList::Append(wxObject *object) { - wxNode *node = new wxNode(this, last_node, NULL, object); + wxNode *node = new wxNode(this, last_node, (wxNode *) NULL, object); if (!first_node) first_node = node; last_node = node; @@ -228,7 +229,7 @@ wxNode *wxList::Nth (int i) const if (j++ == i) return current; } - return NULL; // No such element + return (wxNode *) NULL; // No such element } @@ -242,7 +243,7 @@ wxNode *wxList::Find (long key) const current = current->Next(); } - return NULL; // Not found! + return (wxNode *) NULL; // Not found! } wxNode *wxList::Find (const char *key) const @@ -252,7 +253,7 @@ wxNode *wxList::Find (const char *key) const { if (!current->key.string) { - wxFatalError ("wxList: string key not present, probably did not Append correctly!"); + wxFatalError (_("wxList: string key not present, probably did not Append correctly!")); break; } if (strcmp (current->key.string, key) == 0) @@ -260,7 +261,7 @@ wxNode *wxList::Find (const char *key) const current = current->Next(); } - return NULL; // Not found! + return (wxNode *) NULL; // Not found! } @@ -272,7 +273,7 @@ wxNode *wxList::Member (wxObject * object) const if (each == object) return current; } - return NULL; + return (wxNode *) NULL; } bool wxList::DeleteNode (wxNode * node) @@ -304,7 +305,7 @@ bool wxList::DeleteObject (wxObject * object) // Insert new node at front of list wxNode *wxList::Insert (wxObject * object) { - wxNode *node = new wxNode (this, NULL, First (), object); + wxNode *node = new wxNode (this, (wxNode *) NULL, First (), object); first_node = node; if (!(node->Next ())) @@ -318,7 +319,7 @@ wxNode *wxList::Insert (wxObject * object) // Insert new node before given node. wxNode *wxList::Insert (wxNode * position, wxObject * object) { - wxNode *prev = NULL; + wxNode *prev = (wxNode *) NULL; if (position) prev = position->Previous (); @@ -338,7 +339,7 @@ wxNode *wxList::Insert (wxNode * position, wxObject * object) // Keyed append wxNode *wxList::Append (long key, wxObject * object) { - wxNode *node = new wxNode (this, last_node, NULL, object, key); + wxNode *node = new wxNode (this, last_node, (wxNode *) NULL, object, key); if (!first_node) first_node = node; last_node = node; @@ -348,7 +349,7 @@ wxNode *wxList::Append (long key, wxObject * object) wxNode *wxList::Append (const char *key, wxObject * object) { - wxNode *node = new wxNode (this, last_node, NULL, object, key); + wxNode *node = new wxNode (this, last_node, (wxNode *) NULL, object, key); if (!first_node) first_node = node; last_node = node; @@ -365,8 +366,8 @@ void wxList::Clear (void) delete current; current = next; } - first_node = NULL; - last_node = NULL; + first_node = (wxNode *) NULL; + last_node = (wxNode *) NULL; n = 0; } @@ -388,7 +389,7 @@ wxObject *wxList::FirstThat(wxListIterateFunction F) { if ((*F)( each->Data ())) return each->Data(); each = each->Next(); } - return NULL; + return (wxNode *) NULL; } // Like FirstThat, but proceeds from the end backward wxObject *wxList::LastThat(wxListIterateFunction F) @@ -398,7 +399,7 @@ wxObject *wxList::LastThat(wxListIterateFunction F) { if ((*F)( each->Data ())) return each->Data(); each = each->Previous(); } - return NULL; + return (wxNode *) NULL; } // (stefan.hammes@urz.uni-heidelberg.de) @@ -465,6 +466,11 @@ wxList () { } +wxStringList::wxStringList (const wxStringList& list) +{ + (*this) = list; +} + // Variable argument list, terminated by a zero // Makes new storage for the strings wxStringList::wxStringList (const char *first...) @@ -473,8 +479,8 @@ wxStringList::wxStringList (const char *first...) n = 0; destroy_data = 0; key_type = wxKEY_NONE; - first_node = NULL; - last_node = NULL; + first_node = (wxNode *) NULL; + last_node = (wxNode *) NULL; if (!first) return; @@ -483,7 +489,7 @@ wxStringList::wxStringList (const char *first...) va_start (ap, first); - wxNode *last = new wxNode (this, NULL, NULL, (wxObject *) copystring (first)); + wxNode *last = new wxNode (this, (wxNode *) NULL, (wxNode *) NULL, (wxObject *) copystring (first)); first_node = last; n = 1; @@ -499,7 +505,7 @@ wxStringList::wxStringList (const char *first...) break; else { - wxNode *node = new wxNode (this, last, NULL, (wxObject *) copystring (s)); + wxNode *node = new wxNode (this, last, (wxNode *) NULL, (wxObject *) copystring (s)); last = node; n++; } @@ -515,7 +521,12 @@ wxStringList::wxStringList (const char *first...) wxStringList::~wxStringList (void) { - wxNode *each = first_node; + Clear(); +} + +void wxStringList::Clear(void) +{ + wxNode *each = First(); while (each) { char *s = (char *) each->Data (); @@ -524,6 +535,7 @@ wxStringList::~wxStringList (void) delete each; each = next; } + wxList::Clear(); } wxNode *wxStringList::Add (const char *s) @@ -604,3 +616,24 @@ bool wxStringList::Member (const char *s) const } return FALSE; } + +void wxStringList::operator= (const wxStringList& list) +{ + Clear(); + + wxNode *node = list.First(); + while (node) + { + char *s = (char *) node->Data (); + Add(s); + node = node->Next(); + } +} + +char* wxStringList::operator[] (int i) const +{ + wxASSERT_MSG( (i < Number()), "Invalid index for wxStringList" ); + + return (char*) (Nth(i)->Data()); +} +