+ wxChar *string;
+};
+
+// a struct which may contain both types of keys
+//
+// implementation note: on one hand, this class allows to have only one function
+// for any keyed operation instead of 2 almost equivalent. OTOH, it's needed to
+// resolve ambiguity which we would otherwise have with wxStringList::Find() and
+// wxList::Find(const char *).
+class WXDLLEXPORT wxListKey
+{
+public:
+ // implicit ctors
+ wxListKey()
+ { m_keyType = wxKEY_NONE; }
+ wxListKey(long i)
+ { m_keyType = wxKEY_INTEGER; m_key.integer = i; }
+ wxListKey(const wxChar *s)
+ { m_keyType = wxKEY_STRING; m_key.string = wxStrdup(s); }
+ wxListKey(const wxString& s)
+ { m_keyType = wxKEY_STRING; m_key.string = wxStrdup(s.c_str()); }
+
+ // accessors
+ wxKeyType GetKeyType() const { return m_keyType; }
+ const wxChar *GetString() const
+ { wxASSERT( m_keyType == wxKEY_STRING ); return m_key.string; }
+ long GetNumber() const
+ { wxASSERT( m_keyType == wxKEY_INTEGER ); return m_key.integer; }
+
+ // comparison
+ // Note: implementation moved to list.cpp to prevent BC++ inline
+ // expansion warning.
+ bool operator==(wxListKeyValue value) const ;
+
+ // dtor
+ ~wxListKey()
+ {
+ if ( m_keyType == wxKEY_STRING )
+ free(m_key.string);
+ }
+
+private:
+ wxKeyType m_keyType;
+ wxListKeyValue m_key;
+};
+
+// -----------------------------------------------------------------------------
+// wxNodeBase class is a (base for) node in a double linked list
+// -----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(extern wxListKey) wxDefaultListKey;
+
+class WXDLLEXPORT wxNodeBase
+{
+friend class wxListBase;
+public:
+ // ctor
+ wxNodeBase(wxListBase *list = (wxListBase *)NULL,
+ wxNodeBase *previous = (wxNodeBase *)NULL,
+ wxNodeBase *next = (wxNodeBase *)NULL,
+ void *data = NULL,
+ const wxListKey& key = wxDefaultListKey);
+
+ virtual ~wxNodeBase();
+
+ // FIXME no check is done that the list is really keyed on strings
+ const wxChar *GetKeyString() const { return m_key.string; }
+ long GetKeyInteger() const { return m_key.integer; }
+
+ // Necessary for some existing code
+ void SetKeyString(wxChar* s) { m_key.string = s; }
+ void SetKeyInteger(long i) { m_key.integer = i; }
+
+#ifdef wxLIST_COMPATIBILITY
+ // compatibility methods
+ wxNode *Next() const { return (wxNode *)GetNext(); }
+ wxNode *Previous() const { return (wxNode *)GetPrevious(); }
+ wxObject *Data() const { return (wxObject *)GetData(); }
+#endif // wxLIST_COMPATIBILITY
+
+protected:
+ // all these are going to be "overloaded" in the derived classes
+ wxNodeBase *GetNext() const { return m_next; }
+ wxNodeBase *GetPrevious() const { return m_previous; }
+
+ void *GetData() const { return m_data; }
+ void SetData(void *data) { m_data = data; }
+
+ // get 0-based index of this node within the list or wxNOT_FOUND
+ int IndexOf() const;
+
+ virtual void DeleteData() { }
+
+private:
+ // optional key stuff
+ wxListKeyValue m_key;
+
+ void *m_data; // user data
+ wxNodeBase *m_next, // next and previous nodes in the list
+ *m_previous;
+
+ wxListBase *m_list; // list we belong to
+};
+
+// -----------------------------------------------------------------------------
+// a double-linked list class
+// -----------------------------------------------------------------------------
+class WXDLLEXPORT wxListBase : public wxObject
+{
+friend class wxNodeBase; // should be able to call DetachNode()
+friend class wxHashTableBase; // should be able to call untyped Find()
+public:
+ // default ctor & dtor
+ wxListBase(wxKeyType keyType = wxKEY_NONE) { Init(keyType); }
+ virtual ~wxListBase();
+
+ // accessors
+ // count of items in the list
+ size_t GetCount() const { return m_count; }
+
+ // operations
+
+ // delete all nodes
+ void Clear();
+
+ // instruct it to destroy user data when deleting nodes
+ void DeleteContents(bool destroy) { m_destroy = destroy; }
+
+ // query if to delete
+ bool GetDeleteContents() const
+ { return m_destroy; }
+
+ // get the keytype
+ wxKeyType GetKeyType() const
+ { return m_keyType; }
+
+ // set the keytype (required by the serial code)
+ void SetKeyType(wxKeyType keyType)
+ { wxASSERT( m_count==0 ); m_keyType = keyType; }
+
+#ifdef wxLIST_COMPATIBILITY
+ int Number() const { return GetCount(); }
+ wxNode *First() const { return (wxNode *)GetFirst(); }
+ wxNode *Last() const { return (wxNode *)GetLast(); }
+ wxNode *Nth(size_t index) const { return (wxNode *)Item(index); }
+#endif // wxLIST_COMPATIBILITY
+
+protected:
+
+ // all methods here are "overloaded" in derived classes to provide compile
+ // time type checking
+
+ // create a node for the list of this type
+ virtual wxNodeBase *CreateNode(wxNodeBase *prev, wxNodeBase *next,
+ void *data,
+ const wxListKey& key = wxDefaultListKey) = 0;
+
+// Can't access these from derived classes otherwise (bug in Salford C++?)
+#ifdef __SALFORDC__
+public:
+#endif
+
+ // ctors
+ // from an array
+ wxListBase(size_t count, void *elements[]);
+ // from a sequence of objects
+ wxListBase(void *object, ... /* terminate with NULL */);
+
+protected:
+ // copy ctor and assignment operator
+ wxListBase(const wxListBase& list)
+ { Init(); DoCopy(list); }
+ wxListBase& operator=(const wxListBase& list)
+ { Clear(); DoCopy(list); return *this; }
+
+ // get list head/tail
+ wxNodeBase *GetFirst() const { return m_nodeFirst; }
+ wxNodeBase *GetLast() const { return m_nodeLast; }
+
+ // by (0-based) index
+ wxNodeBase *Item(size_t index) const;
+
+ // get the list item's data
+ void *operator[](size_t index) const
+ { wxNodeBase *node = Item(index); return node ? node->GetData() : (wxNodeBase*)NULL; }
+
+ // operations
+ // append to end of list
+ wxNodeBase *Append(void *object);
+ // insert a new item at the beginning of the list
+ wxNodeBase *Insert(void *object) { return Insert( (wxNodeBase*)NULL, object); }
+ // insert a new item at the given position
+ wxNodeBase *Insert(size_t pos, void *object)
+ { return pos == GetCount() ? Append(object)
+ : Insert(Item(pos), object); }
+ // insert before given node or at front of list if prev == NULL
+ wxNodeBase *Insert(wxNodeBase *prev, void *object);
+
+ // keyed append
+ wxNodeBase *Append(long key, void *object);
+ wxNodeBase *Append(const wxChar *key, void *object);
+
+ // removes node from the list but doesn't delete it (returns pointer
+ // to the node or NULL if it wasn't found in the list)
+ wxNodeBase *DetachNode(wxNodeBase *node);
+ // delete element from list, returns FALSE if node not found
+ bool DeleteNode(wxNodeBase *node);
+ // finds object pointer and deletes node (and object if DeleteContents
+ // is on), returns FALSE if object not found
+ bool DeleteObject(void *object);
+
+ // search (all return NULL if item not found)
+ // by data
+ wxNodeBase *Find(void *object) const;
+
+ // by key
+ wxNodeBase *Find(const wxListKey& key) const;
+
+ // get 0-based index of object or wxNOT_FOUND
+ int IndexOf( void *object ) const;
+
+ // this function allows the sorting of arbitrary lists by giving
+ // a function to compare two list elements. The list is sorted in place.
+ void Sort(const wxSortCompareFunction compfunc);
+
+ // functions for iterating over the list
+ void *FirstThat(wxListIterateFunction func);
+ void ForEach(wxListIterateFunction func);
+ void *LastThat(wxListIterateFunction func);
+
+private:
+ // helpers
+ // common part of all ctors
+ void Init(wxKeyType keyType = wxKEY_NONE);
+ // common part of copy ctor and assignment operator
+ void DoCopy(const wxListBase& list);
+ // common part of all Append()s
+ wxNodeBase *AppendCommon(wxNodeBase *node);
+ // free node's data and node itself
+ void DoDeleteNode(wxNodeBase *node);
+
+ size_t m_count; // number of elements in the list
+ bool m_destroy; // destroy user data when deleting list items?
+ wxNodeBase *m_nodeFirst, // pointers to the head and tail of the list
+ *m_nodeLast;
+
+ wxKeyType m_keyType; // type of our keys (may be wxKEY_NONE)