]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/list.h
allow using CPPUNIT_ASSERT_EQUAL(int,unsigned) even on 64 bit platforms (see r59576)
[wxWidgets.git] / include / wx / list.h
index b88449f12f7336e024eb38be9b2a361a28182b7a..b8cc07ea8471f4bdf4b403ea2f26b8119f8f7d24 100644 (file)
@@ -275,7 +275,7 @@ inline const void *wxListCastElementToVoidPtr(const wxString& str)
             push_front( e );                                                  \
             return compatibility_iterator( this, begin() );                   \
         }                                                                     \
-        compatibility_iterator Insert( compatibility_iterator & i, elT e )    \
+        compatibility_iterator Insert(const compatibility_iterator & i, elT e)\
         {                                                                     \
             return compatibility_iterator( this, insert( i.m_iter, e ) );     \
         }                                                                     \
@@ -420,9 +420,9 @@ class WXDLLIMPEXP_BASE wxNodeBase
 friend class wxListBase;
 public:
     // ctor
-    wxNodeBase(wxListBase *list = (wxListBase *)NULL,
-               wxNodeBase *previous = (wxNodeBase *)NULL,
-               wxNodeBase *next = (wxNodeBase *)NULL,
+    wxNodeBase(wxListBase *list = NULL,
+               wxNodeBase *previous = NULL,
+               wxNodeBase *next = NULL,
                void *data = NULL,
                const wxListKey& key = wxDefaultListKey);
 
@@ -457,7 +457,7 @@ protected:
     virtual void DeleteData() { }
 public:
     // for wxList::iterator
-    void** GetDataPtr() const { return &(wx_const_cast(wxNodeBase*, this)->m_data); }
+    void** GetDataPtr() const { return &(const_cast<wxNodeBase*>(this)->m_data); }
 private:
     // optional key stuff
     wxListKeyValue m_key;
@@ -468,7 +468,7 @@ private:
 
     wxListBase  *m_list;        // list we belong to
 
-    DECLARE_NO_COPY_CLASS(wxNodeBase)
+    wxDECLARE_NO_COPY_CLASS(wxNodeBase);
 };
 
 // -----------------------------------------------------------------------------
@@ -559,7 +559,7 @@ protected:
     {
         wxNodeBase *node = Item(n);
 
-        return node ? node->GetData() : (wxNodeBase *)NULL;
+        return node ? node->GetData() : NULL;
     }
 
     // operations
@@ -569,7 +569,8 @@ protected:
         // append to beginning 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); }
+    wxNodeBase *Insert(void *object)
+        { return Insert(static_cast<wxNodeBase *>(NULL), object); }
         // insert a new item at the given position
     wxNodeBase *Insert(size_t pos, void *object)
         { return pos == GetCount() ? Append(object)
@@ -673,10 +674,10 @@ private:
     classexp nodetype : public wxNodeBase                                   \
     {                                                                       \
     public:                                                                 \
-        nodetype(wxListBase *list = (wxListBase *)NULL,                     \
-                 nodetype *previous = (nodetype *)NULL,                     \
-                 nodetype *next = (nodetype *)NULL,                         \
-                 T *data = (T *)NULL,                                       \
+        nodetype(wxListBase *list = NULL,                                   \
+                 nodetype *previous = NULL,                                 \
+                 nodetype *next = NULL,                                     \
+                 T *data = NULL,                                            \
                  const wxListKey& key = wxDefaultListKey)                   \
             : wxNodeBase(list, previous, next, data, key) { }               \
                                                                             \
@@ -733,13 +734,14 @@ private:
         T *operator[](size_t index) const                                   \
         {                                                                   \
             nodetype *node = Item(index);                                   \
-            return node ? (T*)(node->GetData()) : (T*)NULL;                 \
+            return node ? (T*)(node->GetData()) : NULL;                     \
         }                                                                   \
                                                                             \
         nodetype *Append(Tbase *object)                                     \
             { return (nodetype *)wxListBase::Append(object); }              \
         nodetype *Insert(Tbase *object)                                     \
-            { return (nodetype *)Insert((nodetype*)NULL, object); }         \
+            { return (nodetype *)Insert(static_cast<nodetype *>(NULL),      \
+                                        object); }                          \
         nodetype *Insert(size_t pos, Tbase *object)                         \
             { return (nodetype *)wxListBase::Insert(pos, object); }         \
         nodetype *Insert(nodetype *prev, Tbase *object)                     \
@@ -1005,21 +1007,25 @@ private:
             for(size_type i = 0; i < n; ++i)                                \
                 Append((const_base_reference)v);                            \
         }                                                                   \
-        iterator insert(const iterator& it, const_reference v = value_type())\
+        iterator insert(const iterator& it, const_reference v)              \
         {                                                                   \
-            Insert(it.m_node, (const_base_reference)v);                     \
+            if ( it == end() )                                              \
+                Append((const_base_reference)v);                            \
+            else                                                            \
+                Insert(it.m_node, (const_base_reference)v);                 \
             iterator itprev(it);                                            \
             return itprev--;                                                \
         }                                                                   \
-        void insert(const iterator& it, size_type n, const_reference v = value_type())\
+        void insert(const iterator& it, size_type n, const_reference v)     \
         {                                                                   \
             for(size_type i = 0; i < n; ++i)                                \
-                Insert(it.m_node, (const_base_reference)v);                 \
+                insert(it, v);                                              \
         }                                                                   \
-        void insert(const iterator& it, const_iterator first, const const_iterator& last)\
+        void insert(const iterator& it,                                     \
+                    const_iterator first, const const_iterator& last)       \
         {                                                                   \
             for(; first != last; ++first)                                   \
-                Insert(it.m_node, (const_base_reference)*first);            \
+                insert(it, *first);                                         \
         }                                                                   \
         iterator erase(const iterator& it)                                  \
         {                                                                   \
@@ -1028,7 +1034,9 @@ private:
         }                                                                   \
         iterator erase(const iterator& first, const iterator& last)         \
         {                                                                   \
-            iterator next = last; ++next;                                   \
+            iterator next = last;                                           \
+            if ( next != end() )                                            \
+                ++next;                                                     \
             DeleteNodes(first.m_node, last.m_node);                         \
             return next;                                                    \
         }                                                                   \
@@ -1039,10 +1047,11 @@ private:
             { splice(it, l, l.begin(), l.end() ); }                         \
         void splice(const iterator& it, name& l, const iterator& first)     \
         {                                                                   \
-            iterator tmp = first; ++tmp;                                    \
-            if(it == first || it == tmp) return;                            \
-            insert(it, *first);                                             \
-            l.erase(first);                                                 \
+            if ( it != first )                                              \
+            {                                                               \
+                insert(it, *first);                                         \
+                l.erase(first);                                             \
+            }                                                               \
         }                                                                   \
         void remove(const_reference v)                                      \
             { DeleteObject((const_base_reference)v); }                      \
@@ -1271,4 +1280,15 @@ public:
         (list).clear();                                                      \
     }
 
+// append all element of one list to another one
+#define WX_APPEND_LIST(list, other)                                           \
+    {                                                                         \
+        wxList::compatibility_iterator node = other->GetFirst();              \
+        while ( node )                                                        \
+        {                                                                     \
+            (list)->push_back(node->GetData());                               \
+            node = node->GetNext();                                           \
+        }                                                                     \
+    }
+
 #endif // _WX_LISTH__