X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/745817ffbc209df91833d6a66a1bacc1321f5e2f..cc5bd48eff6f3a12b6066179d1b00d6404c9d921:/include/wx/stringimpl.h diff --git a/include/wx/stringimpl.h b/include/wx/stringimpl.h index 4173d2c69b..04ff3e43a1 100644 --- a/include/wx/stringimpl.h +++ b/include/wx/stringimpl.h @@ -177,8 +177,100 @@ public: typedef const value_type& const_reference; typedef value_type* pointer; typedef const value_type* const_pointer; - typedef value_type *iterator; - typedef const value_type *const_iterator; + + // macro to define the bulk of iterator and const_iterator classes + #define WX_DEFINE_STRINGIMPL_ITERATOR(iterator_name, ref_type, ptr_type) \ + public: \ + typedef wxStringCharType value_type; \ + typedef ref_type reference; \ + typedef ptr_type pointer; \ + \ + iterator_name(pointer ptr) : m_ptr(ptr) { } \ + \ + reference operator*() const { return *m_ptr; } \ + \ + iterator_name& operator++() { m_ptr++; return *this; } \ + iterator_name operator++(int) \ + { \ + const iterator_name tmp(*this); \ + m_ptr++; \ + return tmp; \ + } \ + \ + iterator_name& operator--() { m_ptr--; return *this; } \ + iterator_name operator--(int) \ + { \ + const iterator_name tmp(*this); \ + m_ptr--; \ + return tmp; \ + } \ + \ + iterator_name operator+(int n) const \ + { return iterator_name(m_ptr + n); } \ + iterator_name operator+(size_t n) const \ + { return iterator_name(m_ptr + n); } \ + iterator_name operator-(int n) const \ + { return iterator_name(m_ptr - n); } \ + iterator_name operator-(size_t n) const \ + { return iterator_name(m_ptr - n); } \ + iterator_name& operator+=(int n) \ + { m_ptr += n; return *this; } \ + iterator_name& operator+=(size_t n) \ + { m_ptr += n; return *this; } \ + iterator_name& operator-=(int n) \ + { m_ptr -= n; return *this; } \ + iterator_name& operator-=(size_t n) \ + { m_ptr -= n; return *this; } \ + \ + size_t operator-(const iterator_name& i) const \ + { return m_ptr - i.m_ptr; } \ + \ + bool operator==(const iterator_name& i) const \ + { return m_ptr == i.m_ptr; } \ + bool operator!=(const iterator_name& i) const \ + { return m_ptr != i.m_ptr; } \ + \ + bool operator<(const iterator_name& i) const \ + { return m_ptr < i.m_ptr; } \ + bool operator>(const iterator_name& i) const \ + { return m_ptr > i.m_ptr; } \ + bool operator<=(const iterator_name& i) const \ + { return m_ptr <= i.m_ptr; } \ + bool operator>=(const iterator_name& i) const \ + { return m_ptr >= i.m_ptr; } \ + \ + private: \ + /* for wxStringImpl use only */ \ + operator pointer() const { return m_ptr; } \ + \ + friend class WXDLLIMPEXP_BASE wxStringImpl; \ + \ + pointer m_ptr + + // we need to declare const_iterator in wxStringImpl scope, the friend + // declaration inside iterator class itself is not enough, or at least not + // for g++ 3.4 (g++ 4 is ok) + class const_iterator; + + class iterator + { + WX_DEFINE_STRINGIMPL_ITERATOR(iterator, + wxStringCharType&, + wxStringCharType*); + + friend class const_iterator; + }; + + class const_iterator + { + public: + const_iterator(iterator i) : m_ptr(i.m_ptr) { } + + WX_DEFINE_STRINGIMPL_ITERATOR(const_iterator, + const wxStringCharType&, + const wxStringCharType*); + }; + // constructors and destructor // ctor for an empty string @@ -215,8 +307,8 @@ public: size_t strLen = str.length() - nPos; nLen = strLen < nLen ? strLen : nLen; InitWith(str.c_str(), nPos, nLen); } - // take all characters from pStart to pEnd - wxStringImpl(const void *pStart, const void *pEnd); + // take everything between start and end + wxStringImpl(const_iterator start, const_iterator end); // dtor is not virtual, this class must not be inherited from! ~wxStringImpl() @@ -397,7 +489,7 @@ public: // find first n characters of sz size_t find(const wxStringCharType* sz, size_t nStart = 0, size_t n = npos) const; - // find the first occurence of character ch after nStart + // find the first occurrence of character ch after nStart size_t find(wxStringCharType ch, size_t nStart = 0) const; // rfind() family is exactly like find() but works right to left