]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/string.h
Committing in .
[wxWidgets.git] / include / wx / string.h
index d21eb47a473242cafd7a8316a7fff38139dbb839..7cd776c85fa0f4b7f1374564fc19cbffdc484c20 100644 (file)
@@ -302,7 +302,7 @@ public:
   wxString(const unsigned char* psz, size_t nLength = wxSTRING_MAXLEN)
     { InitWith((const char*)psz, 0, nLength); }
     // from multibyte string
-  wxString(const char *psz, wxMBConv& WXUNUSED(conv), size_t nLength = wxSTRING_MAXLEN)
+  wxString(const char *psz, wxMBConv& WXUNUSED(conv) , size_t nLength = wxSTRING_MAXLEN)
     { InitWith(psz, 0, nLength); }
 
 #if wxUSE_WCHAR_T
@@ -370,21 +370,27 @@ public:
     wxChar& Last()
       { wxASSERT( !IsEmpty() ); CopyBeforeWrite(); return m_pchData[Len()-1]; }
 
-    // under Unix it is tested with configure, assume it works on other
-    // platforms (there might be overloading problems if size_t and int are
-    // the same type)
-#if !defined(__UNIX__) || wxUSE_SIZE_T_STRING_OPERATOR
     // operator version of GetChar
     wxChar  operator[](size_t n) const
       { ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
-#endif
 
     // operator version of GetChar
     wxChar  operator[](int n) const
       { ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
-    // operator version of GetWritableChar
+#ifdef __alpha__
+    // operator version of GetChar
+    wxChar  operator[](unsigned int n) const
+      { ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
+#endif
+    
+    // operator version of GetWriteableChar
     wxChar& operator[](size_t n)
       { ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
+#ifdef __alpha__
+    // operator version of GetWriteableChar
+    wxChar&  operator[](unsigned int n)
+      { ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
+#endif
 
     // implicit conversion to C string
     operator const wxChar*() const { return m_pchData; }
@@ -869,8 +875,9 @@ public:
                                  const wxString& second);
 
   // constructors and destructor
-    // default ctor
-  wxArrayString();
+    // default ctor: if autoSort is TRUE, the array is always sorted (in
+    // alphabetical order)
+  wxArrayString(bool autoSort = FALSE);
     // copy ctor
   wxArrayString(const wxArrayString& array);
     // assignment operator
@@ -911,8 +918,9 @@ public:
     // sensitive (default). Returns index of the first item matched or
     // wxNOT_FOUND
   int  Index (const wxChar *sz, bool bCase = TRUE, bool bFromEnd = FALSE) const;
-    // add new element at the end
-  void Add(const wxString& str);
+    // add new element at the end (if the array is not sorted), return its
+    // index
+  size_t Add(const wxString& str);
     // add new element at given position
   void Insert(const wxString& str, size_t uiIndex);
     // remove first item matching this value
@@ -927,16 +935,30 @@ public:
     // sort array elements using specified comparaison function
   void Sort(CompareFunction compareFunction);
 
+protected:
+  void Copy(const wxArrayString& src);  // copies the contents of another array
+
 private:
-  void    Grow();     // makes array bigger if needed
-  void    Free();     // free the string stored
+  void Grow();                          // makes array bigger if needed
+  void Free();                          // free all the strings stored
 
-  void    DoSort();   // common part of all Sort() variants
+  void DoSort();                        // common part of all Sort() variants
 
   size_t  m_nSize,    // current size of the array
           m_nCount;   // current number of elements
 
-  wxChar  **m_pItems;   // pointer to data
+  wxChar  **m_pItems; // pointer to data
+
+  bool    m_autoSort; // if TRUE, keep the array always sorted
+};
+
+class WXDLLEXPORT wxSortedArrayString : public wxArrayString
+{
+public:
+  wxSortedArrayString() : wxArrayString(TRUE)
+    { }
+  wxSortedArrayString(const wxArrayString& array) : wxArrayString(TRUE)
+    { Copy(array); }
 };
 
 // ---------------------------------------------------------------------------
@@ -1026,7 +1048,8 @@ inline wxString WXDLLEXPORT operator+(const wxCharBuffer& buf, const wxString& s
 
 #include "wx/ioswrap.h"
 
-WXDLLEXPORT istream& operator>>(istream& is, wxString& str);
+WXDLLEXPORT istream& operator>>(istream&, wxString&);
+WXDLLEXPORT ostream& operator<<(ostream&, const wxString&);
 
 #endif  // wxSTD_STRING_COMPATIBILITY