00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00049 #ifndef WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR
00050 #define WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_MAJOR 4
00054 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_MINOR 3
00055 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_REVISION 1
00056 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTBOX_CONST_ITERATOR_EDIT 74
00057 #endif
00058
00059
00060
00061
00062
00063 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00064 # include <winstl/winstl.h>
00065 #endif
00066 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00067 # include <stlsoft/memory/auto_buffer.hpp>
00068 #endif
00069 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
00070 # include <winstl/memory/processheap_allocator.hpp>
00071 #endif
00072 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS
00073 # include <stlsoft/string/string_traits.hpp>
00074 #endif
00075 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00076 # include <stlsoft/util/std/iterator_helper.hpp>
00077 #endif
00078 #ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXTERNAL_ITERATOR_INVALIDATION
00079 # include <stlsoft/error/external_iterator_invalidation.hpp>
00080 #endif
00081
00082
00083
00084
00085
00086 #ifndef _WINSTL_NO_NAMESPACE
00087 # if defined(_STLSOFT_NO_NAMESPACE) || \
00088 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00089
00090 namespace winstl
00091 {
00092 # else
00093
00094
00095 namespace stlsoft
00096 {
00097
00098 namespace winstl_project
00099 {
00100
00101 # endif
00102 #endif
00103
00104
00105
00106
00107
00117 template< ss_typename_param_k S
00118 , ss_typename_param_k BT
00119 >
00120 class listbox_const_iterator
00121 : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(random_access_iterator_tag)
00122 , S
00123 , ws_ptrdiff_t
00124 , S const*
00125 , S const&
00126 >
00127 {
00130 public:
00132 typedef S value_type;
00134 typedef listbox_const_iterator<S, BT> class_type;
00135 #if defined(STLSOFT_COMPILER_IS_BORLAND)
00136 private:
00137 typedef stlsoft_ns_qual(string_traits)<S> string_traits_type_;
00138 typedef ss_typename_type_k string_traits_type_::char_type char_type;
00139 public:
00140 #else
00142 typedef ss_typename_type_k stlsoft_ns_qual(string_traits)<S>::char_type char_type;
00143 #endif
00145 typedef ws_size_t size_type;
00147 typedef ws_ptrdiff_t difference_type;
00149 typedef value_type const& const_reference;
00151 typedef value_type const* const_pointer;
00153 typedef processheap_allocator<char_type> allocator_type;
00154 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00164 typedef stlsoft_ns_qual(const_reverse_iterator_base)< class_type
00165 , value_type
00166 , value_type
00167 , void
00168 , difference_type
00169 > const_reverse_iterator_type;
00170 #endif
00172 typedef stlsoft_ns_qual(auto_buffer_old)< char_type
00173 , allocator_type
00174 , 256
00175 > buffer_type;
00177 typedef BT control_traits_type;
00179
00182 public:
00184 listbox_const_iterator(HWND hwndListBox, int index)
00185 : m_hwnd(hwndListBox)
00186 , m_index(index)
00187 , m_bRetrieved(false)
00188 {}
00190
00193 public:
00195 const_reference operator *() const
00196 {
00197 if(!m_bRetrieved)
00198 {
00199 int len;
00200
00201 if(control_traits_type::err_constant() == (len = control_traits_type::get_text_len(m_hwnd, m_index)))
00202 {
00203 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00204 STLSOFT_THROW_X(stlsoft_ns_qual(external_iterator_invalidation)("external iterator invalidation: control contents may have been altered externally"));
00205 #else
00206 len = 0;
00207 #endif
00208 }
00209
00210 buffer_type buffer(1 + len);
00211
00212 if(control_traits_type::err_constant() == (len = control_traits_type::get_text(m_hwnd, m_index, &buffer[0])))
00213 {
00214 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00215 STLSOFT_THROW_X(stlsoft_ns_qual(external_iterator_invalidation)("external iterator invalidation: control contents may have been altered externally"));
00216 #else
00217 buffer.resize(1);
00218 #endif
00219 }
00220
00221
00222 mutable_access(m_value).assign(&buffer[0], buffer.size() - 1);
00223
00224 mutable_access(m_bRetrieved) = true;
00225 }
00226
00227 return m_value;
00228 }
00229
00231 const_pointer operator ->() const
00232 {
00233 return &operator *();
00234 }
00235
00237 class_type& operator ++()
00238 {
00239 ++m_index;
00240 m_bRetrieved = false;
00241
00242 return *this;
00243 }
00244
00246 class_type operator ++(int)
00247 {
00248 class_type ret(*this);
00249
00250 operator ++();
00251
00252 return ret;
00253 }
00254
00256 difference_type compare(class_type const& rhs) const
00257 {
00258 WINSTL_MESSAGE_ASSERT("invalid comparison between iterators from different ranges", (m_hwnd == rhs.m_hwnd || NULL == m_hwnd || NULL == rhs.m_hwnd));
00259
00260 return m_index - rhs.m_index;
00261 }
00262
00264 bool operator == (class_type const& rhs) const
00265 {
00266 return 0 == compare(rhs);
00267 }
00268
00270 bool operator != (class_type const& rhs) const
00271 {
00272 return 0 != compare(rhs);
00273 }
00275
00278 public:
00280 class_type& operator --()
00281 {
00282 --m_index;
00283 m_bRetrieved = false;
00284
00285 return *this;
00286 }
00287
00289 class_type operator --(int)
00290 {
00291 class_type ret(*this);
00292
00293 operator --();
00294
00295 return ret;
00296 }
00298
00301 public:
00303 class_type& operator +=(difference_type index)
00304 {
00305 m_index += index;
00306 m_bRetrieved = false;
00307
00308 return *this;
00309 }
00310
00312 class_type& operator -=(difference_type index)
00313 {
00314 m_index -= index;
00315 m_bRetrieved = false;
00316
00317 return *this;
00318 }
00319
00321 value_type operator [](difference_type index) const
00322 {
00323
00324 return get_value_at_(m_hwnd, m_index + index);
00325 }
00326
00328 difference_type distance(class_type const& rhs) const
00329 {
00330 return m_index - rhs.m_index;
00331 }
00332
00334 class_type operator -(difference_type n) const
00335 {
00336 return class_type(*this) -= n;
00337 }
00338
00340 class_type operator +(difference_type n) const
00341 {
00342 return class_type(*this) += n;
00343 }
00344
00346 difference_type operator -(class_type const& rhs) const
00347 {
00348 return distance(rhs);
00349 }
00350
00352 ws_bool_t operator <(class_type const& rhs) const
00353 {
00354 return compare(rhs) < 0;
00355 }
00356
00358 ws_bool_t operator >(class_type const& rhs) const
00359 {
00360 return compare(rhs) > 0;
00361 }
00362
00364 ws_bool_t operator <=(class_type const& rhs) const
00365 {
00366 return compare(rhs) <= 0;
00367 }
00368
00370 ws_bool_t operator >=(class_type const& rhs) const
00371 {
00372 return compare(rhs) >= 0;
00373 }
00375
00378 public:
00379 static value_type get_value_at_(HWND hwnd, difference_type index)
00380 {
00381 WINSTL_MESSAGE_ASSERT("Invalid index", index >= 0);
00382
00383 int len;
00384
00385 if(control_traits_type::err_constant() == (len = control_traits_type::get_text_len(hwnd, index)))
00386 {
00387 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00388 STLSOFT_THROW_X(stlsoft_ns_qual(external_iterator_invalidation)("external iterator invalidation: control contents may have been altered externally"));
00389 #else
00390 len = 0;
00391 #endif
00392 }
00393
00394 buffer_type buffer(1 + len);
00395
00396 if(control_traits_type::err_constant() == (len = control_traits_type::get_text(hwnd, index, &buffer[0])))
00397 {
00398 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00399 STLSOFT_THROW_X(stlsoft_ns_qual(external_iterator_invalidation)("external iterator invalidation: control contents may have been altered externally"));
00400 #else
00401 buffer.resize(1);
00402 #endif
00403 }
00404
00405 return value_type(&buffer[0], buffer.size() - 1);
00406 }
00408
00411 private:
00412 HWND m_hwnd;
00413 int m_index;
00414 ss_mutable_k ws_bool_t m_bRetrieved;
00415 ss_mutable_k value_type m_value;
00417 };
00418
00419
00420
00421 #ifndef _WINSTL_NO_NAMESPACE
00422 # if defined(_STLSOFT_NO_NAMESPACE) || \
00423 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00424 }
00425 # else
00426 }
00427 }
00428 # endif
00429 #endif
00430
00431
00432
00433 #endif
00434
00435