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
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef MFCSTL_INCL_H_MFCSTL
00061 # include "mfcstl.h"
00062 #endif
00063 #ifndef STLSOFT_INCL_H_STLSOFT_ITERATOR
00064 # include "stlsoft_iterator.h"
00065 #endif
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #ifndef _MFCSTL_NO_NAMESPACE
00085 # if defined(_STLSOFT_NO_NAMESPACE) || \
00086 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00087
00088 namespace mfcstl
00089 {
00090 # else
00091
00092
00093 namespace stlsoft
00094 {
00095
00096 namespace mfcstl_project
00097 {
00098
00099 # endif
00100 #endif
00101
00102
00103
00106
00110
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 template <class C>
00146 struct list_adaptor_traits;
00147
00148 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00149
00150
00151 STLSOFT_TEMPLATE_SPECIALISATION
00152 struct list_adaptor_traits<CObList>
00153 {
00154 typedef CObject *value_type;
00155 typedef CObject *arg_type;
00156 };
00157
00158
00159
00160 STLSOFT_TEMPLATE_SPECIALISATION
00161 struct list_adaptor_traits<CPtrList>
00162 {
00163 typedef void *value_type;
00164 typedef void *arg_type;
00165 };
00166
00167
00168
00169 STLSOFT_TEMPLATE_SPECIALISATION
00170 struct list_adaptor_traits<CStringList>
00171 {
00172 typedef CString value_type;
00173 typedef const CString &arg_type;
00174 };
00175
00176
00177
00178 #ifdef __AFXTEMPL_H__
00179 # ifdef __STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00180
00181
00182
00183
00184 template <class V, class A>
00185 struct list_adaptor_traits<CList<V, A> >
00186 {
00187 typedef V value_type;
00188 typedef A arg_type;
00189 };
00190
00191 # else
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 # endif // __STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00203 #endif // __AFXTEMPL_H__
00204 #endif
00205
00223
00224 template< class C
00225 , class T = list_adaptor_traits<C>
00226 >
00227 class list_adaptor
00228 {
00229 public:
00230 typedef list_adaptor<C, T> class_type;
00231 typedef class_type adapted_container_type;
00232 private:
00233 typedef C container_type;
00234 typedef T traits_type;
00235 public:
00236
00237
00238
00239 typedef ss_typename_type_k traits_type::value_type value_type;
00240 typedef ms_size_t size_type;
00241
00242 public:
00246 class const_iterator
00247 : public stlsoft_ns_qual(iterator_base)<mfcstl_ns_qual_std(input_iterator_tag), value_type, ms_ptrdiff_t, void, value_type>
00248 {
00249 friend class list_adaptor<C, T>;
00250
00251 typedef const_iterator class_type;
00252
00253
00254
00255 # ifdef __STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00256 typedef ss_typename_type_k list_adaptor<C, T>::value_type value_type;
00257 # else
00258 # endif
00259 # ifndef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
00260 typedef stlsoft_define_move_rhs_type(class_type) rhs_type;
00261 # endif
00262
00263
00264 private:
00266 const_iterator(container_type *c, POSITION pos)
00267 : m_c(c)
00268 , m_pos(pos)
00269 {
00270 operator ++();
00271 }
00272 public:
00274 const_iterator()
00275 : m_c(0)
00276 , m_pos(NULL)
00277 {}
00278 # ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
00279
00280
00281
00282
00283
00284 # else
00285
00286 const_iterator(rhs_type rhs)
00287 : m_c(rhs.m_c)
00288 , m_pos(rhs.m_pos)
00289 {
00290 move_lhs_from_rhs(rhs).m_pos = NULL;
00291 }
00292
00294 const_iterator const &operator =(rhs_type rhs)
00295 {
00296 m_c = rhs.m_c;
00297 m_pos = rhs.m_pos;
00298
00299 move_lhs_from_rhs(rhs).m_pos = NULL;
00300
00301 return *this;
00302 }
00303 # endif
00304
00305
00306 public:
00308 value_type operator *() const
00309 {
00310 mfcstl_message_assert("", m_c != 0);
00311
00312 return m_value;
00313 }
00314
00316 const_iterator &operator ++()
00317 {
00318 if(m_pos == NULL)
00319 {
00320 mfcstl_message_assert("operator ++() called on invalid iterator", m_c != 0);
00321
00322 m_c = 0;
00323 }
00324 else
00325 {
00326 m_value = m_c->GetNext(m_pos);
00327 }
00328
00329 return *this;
00330 }
00331
00333 # ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
00334 const_iterator operator ++(int)
00335 # else
00336 void operator ++(int)
00337 # endif
00338 {
00339 # ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
00340 class_type ret(*this);
00341 # endif
00342
00343 operator ++();
00344
00345 # ifdef _MFCSTL_LIST_ADAPTOR_ENABLE_FWD_ITERATOR
00346 return ret;
00347 # endif
00348 }
00349
00355 ms_bool_t operator ==(const_iterator const &rhs) const
00356 {
00357
00358
00359
00360
00361
00362
00363
00364 mfcstl_message_assert("invalid comparison between iterators from different ranges", m_c == 0 || rhs.m_c == 0 || m_c == rhs.m_c);
00365
00366 return m_pos == rhs.m_pos && m_c == rhs.m_c;
00367 }
00373 ms_bool_t operator !=(const_iterator const &rhs) const
00374 {
00375 return !operator ==(rhs);
00376 }
00377
00378
00379 private:
00380 container_type *m_c;
00381 POSITION m_pos;
00382 value_type m_value;
00383 };
00384
00385
00386 public:
00390 ss_explicit_k list_adaptor(C &c)
00391 : m_c(c)
00392 {}
00393
00394
00395 public:
00397 size_type size() const
00398 {
00399 return static_cast<size_type>(m_c.GetCount());
00400 }
00402 ms_bool_t empty() const
00403 {
00404 return m_c.GetCount() == 0;
00405 }
00407 static size_type max_size()
00408 {
00409 return static_cast<size_type>(-1) / sizeof(value_type);
00410 }
00411
00412
00413 public:
00417 const_iterator begin() const
00418 {
00419 return const_iterator(&m_c, m_c.GetHeadPosition());
00420 }
00424 const_iterator end() const
00425 {
00426 return const_iterator();
00427 }
00428
00429
00430 private:
00431 container_type &m_c;
00432 };
00433
00434
00435
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 #endif
00449
00450
00451
00452
00453
00454