]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/list.h
destroy m_impl even if an exception is thrown from the main loop
[wxWidgets.git] / include / wx / list.h
index 2539ab1c1086019939e5c67b0cb06d67e5326432..a2907d0693c191213d2fbfeca765b9d3051dd635 100644 (file)
@@ -136,7 +136,7 @@ private:
 #endif // defined( __VISUALC__ )
 
 /*
 #endif // defined( __VISUALC__ )
 
 /*
-    Note: the outer helper class _WX_LIST_HELPER_##liT below is a workaround
+    Note 1: the outer helper class _WX_LIST_HELPER_##liT below is a workaround
     for mingw 3.2.3 compiler bug that prevents a static function of liT class
     from being exported into dll. A minimal code snippet reproducing the bug:
 
     for mingw 3.2.3 compiler bug that prevents a static function of liT class
     from being exported into dll. A minimal code snippet reproducing the bug:
 
@@ -155,11 +155,18 @@ private:
 
     The program does not link under mingw_gcc 3.2.3 producing undefined
     reference to Foo::Bar() function
 
     The program does not link under mingw_gcc 3.2.3 producing undefined
     reference to Foo::Bar() function
+
+
+    Note 2: the EmptyList is needed to allow having a NULL pointer-like
+    invalid iterator. We used to use just an uninitialized iterator object
+    instead but this fails with some debug/checked versions of STL, notably the
+    glibc version activated with _GLIBCXX_DEBUG, so we need to have a separate
+    invalid iterator.
  */
 
 // the real wxList-class declaration
 #define WX_DECLARE_LIST_XO(elT, liT, decl)                                    \
  */
 
 // the real wxList-class declaration
 #define WX_DECLARE_LIST_XO(elT, liT, decl)                                    \
-    class WXDLLEXPORT _WX_LIST_HELPER_##liT                                   \
+    decl _WX_LIST_HELPER_##liT                                                \
     {                                                                         \
         typedef elT _WX_LIST_ITEM_TYPE_##liT;                                 \
     public:                                                                   \
     {                                                                         \
         typedef elT _WX_LIST_ITEM_TYPE_##liT;                                 \
     public:                                                                   \
@@ -170,20 +177,25 @@ private:
     decl liT : public std::list<elT>                                          \
     {                                                                         \
     private:                                                                  \
     decl liT : public std::list<elT>                                          \
     {                                                                         \
     private:                                                                  \
+        typedef std::list<elT> BaseListType;                                  \
+        static BaseListType EmptyList;                                        \
+                                                                              \
         bool m_destroy;                                                       \
         bool m_destroy;                                                       \
+                                                                              \
     public:                                                                   \
         decl compatibility_iterator                                           \
         {                                                                     \
         private:                                                              \
     public:                                                                   \
         decl compatibility_iterator                                           \
         {                                                                     \
         private:                                                              \
-          /* Workaround for broken VC6 nested class name resolution */        \
-          typedef std::list<elT>::iterator iterator;                          \
-          friend class liT;                                                   \
-        private:                                                              \
+            /* Workaround for broken VC6 nested class name resolution */      \
+            typedef std::list<elT>::iterator iterator;                        \
+            friend class liT;                                                 \
+                                                                              \
             iterator m_iter;                                                  \
             liT * m_list;                                                     \
             iterator m_iter;                                                  \
             liT * m_list;                                                     \
+                                                                              \
         public:                                                               \
             compatibility_iterator()                                          \
         public:                                                               \
             compatibility_iterator()                                          \
-                : m_iter(), m_list( NULL ) {}                                 \
+                : m_iter(EmptyList.end()), m_list( NULL ) {}                  \
             compatibility_iterator( liT* li, iterator i )                     \
                 : m_iter( i ), m_list( li ) {}                                \
             compatibility_iterator( const liT* li, iterator i )               \
             compatibility_iterator( liT* li, iterator i )                     \
                 : m_iter( i ), m_list( li ) {}                                \
             compatibility_iterator( const liT* li, iterator i )               \
@@ -252,6 +264,11 @@ private:
             std::advance( i, idx );                                           \
             return compatibility_iterator( this, i );                         \
         }                                                                     \
             std::advance( i, idx );                                           \
             return compatibility_iterator( this, i );                         \
         }                                                                     \
+        elT operator[](size_t idx) const                                      \
+        {                                                                     \
+            return Item(idx).GetData();                                       \
+        }                                                                     \
+                                                                              \
         compatibility_iterator GetFirst() const                               \
         {                                                                     \
             return compatibility_iterator( this,                              \
         compatibility_iterator GetFirst() const                               \
         {                                                                     \
             return compatibility_iterator( this,                              \
@@ -323,6 +340,9 @@ private:
         void Sort( wxSortCompareFunction compfunc )                           \
             { sort( WX_LIST_SORTFUNCTION( elT, compfunc ) ); }                \
         ~liT() { Clear(); }                                                   \
         void Sort( wxSortCompareFunction compfunc )                           \
             { sort( WX_LIST_SORTFUNCTION( elT, compfunc ) ); }                \
         ~liT() { Clear(); }                                                   \
+                                                                              \
+        /* It needs access to our EmptyList */                                \
+        friend decl compatibility_iterator;                                   \
     }
 
 #define WX_DECLARE_LIST(elementtype, listname)                              \
     }
 
 #define WX_DECLARE_LIST(elementtype, listname)                              \
@@ -349,11 +369,6 @@ private:
 
 #else // if !wxUSE_STL
 
 
 #else // if !wxUSE_STL
 
-// due to circular header dependencies this function has to be declared here
-// (normally it's found in utils.h which includes itself list.h...)
-#if WXWIN_COMPATIBILITY_2_4
-extern WXDLLIMPEXP_BASE wxChar* copystring(const wxChar *s);
-#endif
 
 // undef it to get rid of old, deprecated functions
 #define wxLIST_COMPATIBILITY
 
 // undef it to get rid of old, deprecated functions
 #define wxLIST_COMPATIBILITY