]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/string.h
Big wxGL classes refactoring/cleanup:
[wxWidgets.git] / include / wx / string.h
index 72900dcfb1e428356ae3f3cd25bcd4d5e39ac03c..3cb68a0df4ae5b22893537a6d9f8f1cdf31e06dc 100644 (file)
@@ -571,8 +571,6 @@ public:
   wxString(const wxString& str, size_t nLength)
       : m_impl(str.Mid(0, nLength).m_impl) {}
 
-  ~wxString();
-
 public:
   // standard types
   typedef wxUniChar value_type;
@@ -640,7 +638,7 @@ public:
           iterator_name& operator-=(size_t n)                               \
             { m_cur = wxString::AddToIter(m_cur, -(int)n); return *this; }  \
                                                                             \
-          unsigned operator-(const iterator_name& i) const                  \
+          difference_type operator-(const iterator_name& i) const           \
             { return wxString::DiffIters(m_cur, i.m_cur); }                 \
                                                                             \
           bool operator==(const iterator_name& i) const                     \
@@ -666,14 +664,14 @@ public:
           friend class WXDLLIMPEXP_BASE wxCStrData;                         \
                                                                             \
       private:                                                              \
-          underlying_iterator m_cur;
+          underlying_iterator m_cur
 
   class const_iterator;
 
   class iterator
   {
       WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef,
-                           wxUniCharRef::CreateForString(m_cur))
+                           wxUniCharRef::CreateForString(m_cur));
 
       friend class const_iterator;
   };
@@ -683,7 +681,7 @@ public:
       // NB: reference_type is intentionally value, not reference, the character
       //     may be encoded differently in wxString data:
       WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar,
-                           wxUniChar(*m_cur))
+                           wxUniChar(*m_cur));
 
   public:
       const_iterator(const iterator& i) : m_cur(i.m_cur) {}
@@ -2001,6 +1999,35 @@ private:
 
 private:
   wxStringImpl m_impl;
+
+  // buffers for compatibility conversion from (char*)c_str() and
+  // (wchar_t*)c_str():
+  // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
+  template<typename T>
+  struct ConvertedBuffer
+  {
+      ConvertedBuffer() : m_buf(NULL) {}
+      ~ConvertedBuffer()
+          { free(m_buf); }
+
+      operator const T*() const { return m_buf; }
+
+      ConvertedBuffer& operator=(T *str)
+      {
+          free(m_buf);
+          m_buf = str;
+          return *this;
+      }
+
+      T *m_buf;
+  };
+#if wxUSE_UNICODE
+  ConvertedBuffer<char> m_convertedToChar;
+#endif
+#if !wxUSE_UNICODE_WCHAR
+  ConvertedBuffer<wchar_t> m_convertedToWChar;
+#endif
+  friend class WXDLLIMPEXP_BASE wxCStrData;
 };
 
 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
@@ -2308,7 +2335,7 @@ inline wxCStrData::~wxCStrData()
 inline wxCStrData::operator bool() const
 {
     return !m_str->empty();
-};
+}
 
 // simple cases for AsChar() and AsWChar(), the complicated ones are
 // in string.cpp
@@ -2347,6 +2374,22 @@ inline wxUniChar wxCStrData::operator[](size_t n) const
     return m_str->at(m_offset + n);
 }
 
+// ----------------------------------------------------------------------------
+// more wxCStrData operators
+// ----------------------------------------------------------------------------
+
+// we need to define those to allow "size_t pos = p - s.c_str()" where p is
+// some pointer into the string
+inline size_t operator-(const char *p, const wxCStrData& cs)
+{
+    return p - cs.AsChar();
+}
+
+inline size_t operator-(const wchar_t *p, const wxCStrData& cs)
+{
+    return p - cs.AsWChar();
+}
+
 // ----------------------------------------------------------------------------
 // implementation of wx[W]CharBuffer inline methods using wxCStrData
 // ----------------------------------------------------------------------------