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 template <class C>
00127 struct array_adaptor_traits;
00128
00129 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00130
00131
00132 STLSOFT_TEMPLATE_SPECIALISATION
00133 struct array_adaptor_traits<CByteArray>
00134 {
00135 typedef BYTE value_type;
00136 typedef BYTE arg_type;
00137 };
00138
00139
00140
00141 STLSOFT_TEMPLATE_SPECIALISATION
00142 struct array_adaptor_traits<CDWordArray>
00143 {
00144 typedef DWORD value_type;
00145 typedef DWORD arg_type;
00146 };
00147
00148
00149
00150 STLSOFT_TEMPLATE_SPECIALISATION
00151 struct array_adaptor_traits<CObArray>
00152 {
00153 typedef CObject *value_type;
00154 typedef CObject *arg_type;
00155 };
00156
00157
00158
00159 STLSOFT_TEMPLATE_SPECIALISATION
00160 struct array_adaptor_traits<CPtrArray>
00161 {
00162 typedef void *value_type;
00163 typedef void *arg_type;
00164 };
00165
00166
00167
00168 STLSOFT_TEMPLATE_SPECIALISATION
00169 struct array_adaptor_traits<CStringArray>
00170 {
00171 typedef CString value_type;
00172 typedef const CString &arg_type;
00173 };
00174
00175
00176
00177 STLSOFT_TEMPLATE_SPECIALISATION
00178 struct array_adaptor_traits<CUIntArray>
00179 {
00180 typedef UINT value_type;
00181 typedef UINT arg_type;
00182 };
00183
00184
00185
00186 STLSOFT_TEMPLATE_SPECIALISATION
00187 struct array_adaptor_traits<CWordArray>
00188 {
00189 typedef WORD value_type;
00190 typedef WORD arg_type;
00191 };
00192
00193
00194
00195
00196 #ifdef __AFXTEMPL_H__
00197 # ifdef __STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00198
00199
00200
00201
00202 template <class V, class A>
00203 struct array_adaptor_traits<CArray<V, A> >
00204 {
00205 typedef V value_type;
00206 typedef A arg_type;
00207 };
00208
00209 # else
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 # endif // __STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00221 #endif // __AFXTEMPL_H__
00222 #endif
00223
00241
00242 template< class C
00243 , class T = array_adaptor_traits<C>
00244 >
00245 class array_adaptor
00246 {
00247 public:
00249 typedef array_adaptor<C, T> class_type;
00251 typedef C container_type;
00252 private:
00253 typedef T traits_type;
00254 typedef class_type adapted_container_type;
00255 public:
00256
00257
00258
00259 typedef ss_typename_type_k traits_type::value_type value_type;
00261 typedef ms_size_t size_type;
00263 typedef ms_ptrdiff_t difference_type;
00264
00265 public:
00269 class const_iterator
00270 : public stlsoft_ns_qual(iterator_base)<mfcstl_ns_qual_std(random_access_iterator_tag), value_type, ms_ptrdiff_t, void, value_type>
00271 {
00272 friend class array_adaptor<C, T>;
00273
00274 typedef const_iterator class_type;
00275
00276
00277
00278 typedef int index_type;
00279 #ifdef __STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00280 typedef ss_typename_type_k array_adaptor<C, T>::value_type value_type;
00281 #else
00282 #endif
00283
00284
00285 private:
00286 friend class adapted_container_type;
00287
00288 const_iterator(container_type *c, index_type index)
00289 : m_c(c)
00290 , m_index(index)
00291 {}
00292 public:
00294 const_iterator()
00295 : m_c(0)
00296 , m_index(0)
00297 {}
00301 const_iterator(class_type const &rhs)
00302 : m_c(rhs.m_c)
00303 , m_index(rhs.m_index)
00304 {}
00305
00309 const_iterator const &operator =(class_type const &rhs)
00310 {
00311 m_c = rhs.m_c;
00312 m_index = rhs.m_index;
00313
00314 return *this;
00315 }
00316
00317
00318 public:
00319 ss_typename_type_k traits_type::value_type operator *() const
00320 {
00321 mfcstl_message_assert("", m_c != 0);
00322
00323 return m_c->GetAt(m_index);
00324 }
00325
00327 class_type &operator ++()
00328 {
00329 ++m_index;
00330
00331 return *this;
00332 }
00333
00335 class_type operator ++(int)
00336 {
00337 class_type ret(*this);
00338
00339 operator ++();
00340
00341 return ret;
00342 }
00343
00350 difference_type compare(class_type const &rhs) const
00351 {
00352
00353
00354
00355
00356
00357
00358
00359 mfcstl_message_assert("invalid comparison between iterators from different ranges", m_c == 0 || rhs.m_c == 0 || m_c == rhs.m_c);
00360
00361 return m_index - rhs.m_index;
00362 }
00363
00369 ms_bool_t operator ==(class_type const &rhs) const
00370 {
00371 return compare(rhs) == 0;
00372 }
00373
00379 ms_bool_t operator !=(class_type const &rhs) const
00380 {
00381 return compare(rhs) != 0;
00382 }
00383
00384
00385
00387 class_type &operator --()
00388 {
00389 --m_index;
00390
00391 return *this;
00392 }
00393
00395 class_type operator --(int)
00396 {
00397 class_type ret(*this);
00398
00399 operator --();
00400
00401 return ret;
00402 }
00403
00404
00405
00409 class_type &operator +=(difference_type inc)
00410 {
00411 m_index += inc;
00412
00413 return *this;
00414 }
00415
00419 class_type &operator -=(difference_type dec)
00420 {
00421 m_index -= dec;
00422
00423 return *this;
00424 }
00425
00429 value_type &operator [](difference_type index)
00430 {
00431 return m_c->ElementAt(m_index + index);
00432 }
00433
00437 value_type operator [](difference_type index) const
00438 {
00439 return m_c->GetAt(m_index + index);
00440 }
00441
00442 difference_type distance(class_type const &rhs) const
00443 {
00444 return m_index - rhs.m_index;
00445 }
00446
00447 class_type operator -(difference_type n)
00448 {
00449 return class_type(*this) -= n;
00450 }
00451
00452 class_type operator +(difference_type n)
00453 {
00454 return class_type(*this) += n;
00455 }
00456
00457 difference_type operator -(class_type const &rhs)
00458 {
00459 return distance(rhs);
00460 }
00461
00462 ms_bool_t operator <(class_type const &rhs)
00463 {
00464 return compare(rhs) < 0;
00465 }
00466
00467 ms_bool_t operator >(class_type const &rhs)
00468 {
00469 return compare(rhs) > 0;
00470 }
00471
00472 ms_bool_t operator <=(class_type const &rhs)
00473 {
00474 return compare(rhs) <= 0;
00475 }
00476
00477 ms_bool_t operator >=(class_type const &rhs)
00478 {
00479 return compare(rhs) >= 0;
00480 }
00481
00482
00483
00484 private:
00485 container_type *m_c;
00486 size_type m_index;
00487 };
00488
00490 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00491 typedef stlsoft_ns_qual(const_reverse_bidirectional_iterator_base)< const_iterator,
00492 value_type,
00493 value_type,
00494 void*,
00495 difference_type> const_reverse_iterator;
00496 #endif
00497
00498
00499
00500 public:
00504 ss_explicit_k array_adaptor(container_type &c)
00505 : m_c(c)
00506 {}
00507
00508
00509 public:
00511 size_type size() const
00512 {
00513 return static_cast<size_type>(m_c.GetSize());
00514 }
00516 ms_bool_t empty() const
00517 {
00518 return m_c.GetSize() == 0;
00519 }
00521 static size_type max_size()
00522 {
00523 return static_cast<size_type>(-1) / sizeof(value_type);
00524 }
00525
00526
00527 public:
00531 const_iterator begin() const
00532 {
00533 return const_iterator(const_cast<container_type*>(&m_c), 0);
00534 }
00538 const_iterator end() const
00539 {
00540 return const_iterator(const_cast<container_type*>(&m_c), size());
00541 }
00542
00543
00544 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00548 const_reverse_iterator rbegin() const
00549 {
00550 return const_reverse_iterator(end());
00551 }
00555 const_reverse_iterator rend() const
00556 {
00557 return const_reverse_iterator(begin());
00558 }
00559 #endif
00560
00561
00562 public:
00564 value_type &operator [](difference_type index)
00565 {
00566 return m_c.ElementAt(index);
00567 }
00568
00570 value_type operator [](difference_type index) const
00571 {
00572 return m_c.GetAt(index);
00573 }
00574
00575
00576 private:
00577 container_type const &m_c;
00578 };
00579
00580
00581
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 #endif
00595
00596
00597
00598
00599
00600