| 1 | #ifndef BOOST_RANGE_MFC_HPP |
| 2 | #define BOOST_RANGE_MFC_HPP |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | // Boost.Range MFC Extension |
| 8 | // |
| 9 | // Copyright Shunsuke Sogame 2005-2006. |
| 10 | // Distributed under the Boost Software License, Version 1.0. |
| 11 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 12 | // http://www.boost.org/LICENSE_1_0.txt) |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | // config |
| 18 | // |
| 19 | |
| 20 | |
| 21 | #include <afx.h> // _MFC_VER |
| 22 | |
| 23 | |
| 24 | #if !defined(BOOST_RANGE_MFC_NO_CPAIR) |
| 25 | #if (_MFC_VER < 0x0700) // dubious |
| 26 | #define BOOST_RANGE_MFC_NO_CPAIR |
| 27 | #endif |
| 28 | #endif |
| 29 | |
| 30 | |
| 31 | #if !defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) |
| 32 | #if (_MFC_VER < 0x0700) // dubious |
| 33 | #define BOOST_RANGE_MFC_HAS_LEGACY_STRING |
| 34 | #endif |
| 35 | #endif |
| 36 | |
| 37 | |
| 38 | // A const collection of old MFC doesn't return const reference. |
| 39 | // |
| 40 | #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) |
| 41 | #if (_MFC_VER < 0x0700) // dubious |
| 42 | #define BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF |
| 43 | #endif |
| 44 | #endif |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | // forward declarations |
| 50 | // |
| 51 | |
| 52 | |
| 53 | template< class Type, class ArgType > |
| 54 | class CArray; |
| 55 | |
| 56 | template< class Type, class ArgType > |
| 57 | class CList; |
| 58 | |
| 59 | template< class Key, class ArgKey, class Mapped, class ArgMapped > |
| 60 | class CMap; |
| 61 | |
| 62 | template< class BaseClass, class PtrType > |
| 63 | class CTypedPtrArray; |
| 64 | |
| 65 | template< class BaseClass, class PtrType > |
| 66 | class CTypedPtrList; |
| 67 | |
| 68 | template< class BaseClass, class KeyPtrType, class MappedPtrType > |
| 69 | class CTypedPtrMap; |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | // extended customizations |
| 75 | // |
| 76 | |
| 77 | |
| 78 | #include <cstddef> // ptrdiff_t |
| 79 | #include <utility> // pair |
| 80 | #include <boost/assert.hpp> |
| 81 | #include <boost/mpl/if.hpp> |
| 82 | #include <boost/range/atl.hpp> |
| 83 | #include <boost/range/begin.hpp> |
| 84 | #include <boost/range/const_iterator.hpp> |
| 85 | #include <boost/range/detail/microsoft.hpp> |
| 86 | #include <boost/range/end.hpp> |
| 87 | #include <boost/iterator/iterator_adaptor.hpp> |
| 88 | #include <boost/iterator/iterator_categories.hpp> |
| 89 | #include <boost/iterator/iterator_facade.hpp> |
| 90 | #include <boost/iterator/transform_iterator.hpp> |
| 91 | #include <boost/type_traits/is_const.hpp> |
| 92 | #include <boost/type_traits/remove_pointer.hpp> |
| 93 | #include <boost/utility/addressof.hpp> |
| 94 | #include <afx.h> // legacy CString |
| 95 | #include <afxcoll.h> // CXXXArray, CXXXList, CMapXXXToXXX |
| 96 | #include <tchar.h> |
| 97 | |
| 98 | |
| 99 | namespace boost { namespace range_detail_microsoft { |
| 100 | |
| 101 | |
| 102 | // mfc_ptr_array_iterator |
| 103 | // |
| 104 | // 'void **' is not convertible to 'void const **', |
| 105 | // so we define... |
| 106 | // |
| 107 | |
| 108 | template< class ArrayT, class PtrType > |
| 109 | struct mfc_ptr_array_iterator; |
| 110 | |
| 111 | template< class ArrayT, class PtrType > |
| 112 | struct mfc_ptr_array_iterator_super |
| 113 | { |
| 114 | typedef iterator_adaptor< |
| 115 | mfc_ptr_array_iterator<ArrayT, PtrType>, |
| 116 | std::ptrdiff_t, // Base! |
| 117 | PtrType, // Value |
| 118 | random_access_traversal_tag, |
| 119 | use_default, |
| 120 | std::ptrdiff_t // Difference |
| 121 | > type; |
| 122 | }; |
| 123 | |
| 124 | template< class ArrayT, class PtrType > |
| 125 | struct mfc_ptr_array_iterator : |
| 126 | mfc_ptr_array_iterator_super<ArrayT, PtrType>::type |
| 127 | { |
| 128 | private: |
| 129 | typedef mfc_ptr_array_iterator self_t; |
| 130 | typedef typename mfc_ptr_array_iterator_super<ArrayT, PtrType>::type super_t; |
| 131 | typedef typename super_t::reference ref_t; |
| 132 | |
| 133 | public: |
| 134 | explicit mfc_ptr_array_iterator() |
| 135 | { } |
| 136 | |
| 137 | explicit mfc_ptr_array_iterator(ArrayT& arr, INT_PTR index) : |
| 138 | super_t(index), m_parr(boost::addressof(arr)) |
| 139 | { } |
| 140 | |
| 141 | template< class, class > friend struct mfc_ptr_array_iterator; |
| 142 | template< class ArrayT_, class PtrType_ > |
| 143 | mfc_ptr_array_iterator(mfc_ptr_array_iterator<ArrayT_, PtrType_> const& other) : |
| 144 | super_t(other.base()), m_parr(other.m_parr) |
| 145 | { } |
| 146 | |
| 147 | private: |
| 148 | ArrayT *m_parr; |
| 149 | |
| 150 | friend class iterator_core_access; |
| 151 | ref_t dereference() const |
| 152 | { |
| 153 | BOOST_ASSERT(0 <= this->base() && this->base() < m_parr->GetSize() && "out of range" ); |
| 154 | return *( m_parr->GetData() + this->base() ); |
| 155 | } |
| 156 | |
| 157 | bool equal(self_t const& other) const |
| 158 | { |
| 159 | BOOST_ASSERT(m_parr == other.m_parr && "iterators incompatible" ); |
| 160 | return this->base() == other.base(); |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | struct mfc_ptr_array_functions |
| 165 | { |
| 166 | template< class Iterator, class X > |
| 167 | Iterator begin(X& x) |
| 168 | { |
| 169 | return Iterator(x, 0); |
| 170 | } |
| 171 | |
| 172 | template< class Iterator, class X > |
| 173 | Iterator end(X& x) |
| 174 | { |
| 175 | return Iterator(x, x.GetSize()); |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | // arrays |
| 181 | // |
| 182 | |
| 183 | template< > |
| 184 | struct customization< ::CByteArray > : |
| 185 | array_functions |
| 186 | { |
| 187 | template< class X > |
| 188 | struct meta |
| 189 | { |
| 190 | typedef BYTE val_t; |
| 191 | |
| 192 | typedef val_t *mutable_iterator; |
| 193 | typedef val_t const *const_iterator; |
| 194 | }; |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | template< > |
| 199 | struct customization< ::CDWordArray > : |
| 200 | array_functions |
| 201 | { |
| 202 | template< class X > |
| 203 | struct meta |
| 204 | { |
| 205 | typedef DWORD val_t; |
| 206 | |
| 207 | typedef val_t *mutable_iterator; |
| 208 | typedef val_t const *const_iterator; |
| 209 | }; |
| 210 | }; |
| 211 | |
| 212 | |
| 213 | template< > |
| 214 | struct customization< ::CObArray > : |
| 215 | mfc_ptr_array_functions |
| 216 | { |
| 217 | template< class X > |
| 218 | struct meta |
| 219 | { |
| 220 | typedef mfc_ptr_array_iterator<X, CObject *> mutable_iterator; |
| 221 | typedef mfc_ptr_array_iterator<X const, CObject const *> const_iterator; |
| 222 | }; |
| 223 | }; |
| 224 | |
| 225 | |
| 226 | template< > |
| 227 | struct customization< ::CPtrArray > : |
| 228 | mfc_ptr_array_functions |
| 229 | { |
| 230 | template< class X > |
| 231 | struct meta |
| 232 | { |
| 233 | typedef mfc_ptr_array_iterator<X, void *> mutable_iterator; |
| 234 | typedef mfc_ptr_array_iterator<X const, void const *> const_iterator; |
| 235 | }; |
| 236 | }; |
| 237 | |
| 238 | |
| 239 | template< > |
| 240 | struct customization< ::CStringArray > : |
| 241 | array_functions |
| 242 | { |
| 243 | template< class X > |
| 244 | struct meta |
| 245 | { |
| 246 | typedef ::CString val_t; |
| 247 | |
| 248 | typedef val_t *mutable_iterator; |
| 249 | typedef val_t const *const_iterator; |
| 250 | }; |
| 251 | }; |
| 252 | |
| 253 | |
| 254 | template< > |
| 255 | struct customization< ::CUIntArray > : |
| 256 | array_functions |
| 257 | { |
| 258 | template< class X > |
| 259 | struct meta |
| 260 | { |
| 261 | typedef UINT val_t; |
| 262 | |
| 263 | typedef val_t *mutable_iterator; |
| 264 | typedef val_t const *const_iterator; |
| 265 | }; |
| 266 | }; |
| 267 | |
| 268 | |
| 269 | template< > |
| 270 | struct customization< ::CWordArray > : |
| 271 | array_functions |
| 272 | { |
| 273 | template< class X > |
| 274 | struct meta |
| 275 | { |
| 276 | typedef WORD val_t; |
| 277 | |
| 278 | typedef val_t *mutable_iterator; |
| 279 | typedef val_t const *const_iterator; |
| 280 | }; |
| 281 | }; |
| 282 | |
| 283 | |
| 284 | // lists |
| 285 | // |
| 286 | |
| 287 | template< > |
| 288 | struct customization< ::CObList > : |
| 289 | list_functions |
| 290 | { |
| 291 | template< class X > |
| 292 | struct meta |
| 293 | { |
| 294 | typedef list_iterator<X, ::CObject *> mutable_iterator; |
| 295 | // const CObList and const CPtrList both return a value (and probably always will) |
| 296 | typedef list_iterator<X const, ::CObject const * const, ::CObject const * const> const_iterator; |
| 297 | }; |
| 298 | }; |
| 299 | |
| 300 | |
| 301 | template< > |
| 302 | struct customization< ::CPtrList > : |
| 303 | list_functions |
| 304 | { |
| 305 | template< class X > |
| 306 | struct meta |
| 307 | { |
| 308 | typedef list_iterator<X, void *> mutable_iterator; |
| 309 | // const CObList and const CPtrList both return a value (and probably always will) |
| 310 | typedef list_iterator<X const, void const * const, void const * const> const_iterator; |
| 311 | }; |
| 312 | }; |
| 313 | |
| 314 | |
| 315 | template< > |
| 316 | struct customization< ::CStringList > : |
| 317 | list_functions |
| 318 | { |
| 319 | template< class X > |
| 320 | struct meta |
| 321 | { |
| 322 | typedef ::CString val_t; |
| 323 | |
| 324 | typedef list_iterator<X, val_t> mutable_iterator; |
| 325 | #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) |
| 326 | typedef list_iterator<X const, val_t const> const_iterator; |
| 327 | #else |
| 328 | typedef list_iterator<X const, val_t const, val_t const> const_iterator; |
| 329 | #endif |
| 330 | }; |
| 331 | }; |
| 332 | |
| 333 | |
| 334 | // mfc_map_iterator |
| 335 | // |
| 336 | |
| 337 | template< class MapT, class KeyT, class MappedT > |
| 338 | struct mfc_map_iterator; |
| 339 | |
| 340 | template< class MapT, class KeyT, class MappedT > |
| 341 | struct mfc_map_iterator_super |
| 342 | { |
| 343 | typedef iterator_facade< |
| 344 | mfc_map_iterator<MapT, KeyT, MappedT>, |
| 345 | std::pair<KeyT, MappedT>, |
| 346 | forward_traversal_tag, |
| 347 | std::pair<KeyT, MappedT> const |
| 348 | > type; |
| 349 | }; |
| 350 | |
| 351 | template< class MapT, class KeyT, class MappedT > |
| 352 | struct mfc_map_iterator : |
| 353 | mfc_map_iterator_super<MapT, KeyT, MappedT>::type |
| 354 | { |
| 355 | private: |
| 356 | typedef mfc_map_iterator self_t; |
| 357 | typedef typename mfc_map_iterator_super<MapT, KeyT, MappedT>::type super_t; |
| 358 | typedef typename super_t::reference ref_t; |
| 359 | |
| 360 | public: |
| 361 | explicit mfc_map_iterator() |
| 362 | { } |
| 363 | |
| 364 | explicit mfc_map_iterator(MapT const& map, POSITION pos) : |
| 365 | m_pmap(boost::addressof(map)), m_posNext(pos) |
| 366 | { |
| 367 | increment(); |
| 368 | } |
| 369 | |
| 370 | explicit mfc_map_iterator(MapT const& map) : |
| 371 | m_pmap(&map), m_pos(0) // end iterator |
| 372 | { } |
| 373 | |
| 374 | template< class, class, class > friend struct mfc_map_iterator; |
| 375 | template< class MapT_, class KeyT_, class MappedT_> |
| 376 | mfc_map_iterator(mfc_map_iterator<MapT_, KeyT_, MappedT_> const& other) : |
| 377 | m_pmap(other.m_pmap), |
| 378 | m_pos(other.m_pos), m_posNext(other.m_posNext), |
| 379 | m_key(other.m_key), m_mapped(other.m_mapped) |
| 380 | { } |
| 381 | |
| 382 | private: |
| 383 | MapT const *m_pmap; |
| 384 | POSITION m_pos, m_posNext; |
| 385 | KeyT m_key; MappedT m_mapped; |
| 386 | |
| 387 | friend class iterator_core_access; |
| 388 | ref_t dereference() const |
| 389 | { |
| 390 | BOOST_ASSERT(m_pos != 0 && "out of range" ); |
| 391 | return std::make_pair(m_key, m_mapped); |
| 392 | } |
| 393 | |
| 394 | void increment() |
| 395 | { |
| 396 | BOOST_ASSERT(m_pos != 0 && "out of range" ); |
| 397 | |
| 398 | if (m_posNext == 0) { |
| 399 | m_pos = 0; |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | m_pos = m_posNext; |
| 404 | m_pmap->GetNextAssoc(m_posNext, m_key, m_mapped); |
| 405 | } |
| 406 | |
| 407 | bool equal(self_t const& other) const |
| 408 | { |
| 409 | BOOST_ASSERT(m_pmap == other.m_pmap && "iterators incompatible" ); |
| 410 | return m_pos == other.m_pos; |
| 411 | } |
| 412 | }; |
| 413 | |
| 414 | struct mfc_map_functions |
| 415 | { |
| 416 | template< class Iterator, class X > |
| 417 | Iterator begin(X& x) |
| 418 | { |
| 419 | return Iterator(x, x.GetStartPosition()); |
| 420 | } |
| 421 | |
| 422 | template< class Iterator, class X > |
| 423 | Iterator end(X& x) |
| 424 | { |
| 425 | return Iterator(x); |
| 426 | } |
| 427 | }; |
| 428 | |
| 429 | |
| 430 | #if !defined(BOOST_RANGE_MFC_NO_CPAIR) |
| 431 | |
| 432 | |
| 433 | // mfc_cpair_map_iterator |
| 434 | // |
| 435 | // used by ::CMap and ::CMapStringToString |
| 436 | // |
| 437 | |
| 438 | template< class MapT, class PairT > |
| 439 | struct mfc_cpair_map_iterator; |
| 440 | |
| 441 | template< class MapT, class PairT > |
| 442 | struct mfc_pget_map_iterator_super |
| 443 | { |
| 444 | typedef iterator_facade< |
| 445 | mfc_cpair_map_iterator<MapT, PairT>, |
| 446 | PairT, |
| 447 | forward_traversal_tag |
| 448 | > type; |
| 449 | }; |
| 450 | |
| 451 | template< class MapT, class PairT > |
| 452 | struct mfc_cpair_map_iterator : |
| 453 | mfc_pget_map_iterator_super<MapT, PairT>::type |
| 454 | { |
| 455 | private: |
| 456 | typedef mfc_cpair_map_iterator self_t; |
| 457 | typedef typename mfc_pget_map_iterator_super<MapT, PairT>::type super_t; |
| 458 | typedef typename super_t::reference ref_t; |
| 459 | |
| 460 | public: |
| 461 | explicit mfc_cpair_map_iterator() |
| 462 | { } |
| 463 | |
| 464 | explicit mfc_cpair_map_iterator(MapT& map, PairT *pp) : |
| 465 | m_pmap(boost::addressof(map)), m_pp(pp) |
| 466 | { } |
| 467 | |
| 468 | template< class, class > friend struct mfc_cpair_map_iterator; |
| 469 | template< class MapT_, class PairT_> |
| 470 | mfc_cpair_map_iterator(mfc_cpair_map_iterator<MapT_, PairT_> const& other) : |
| 471 | m_pmap(other.m_pmap), m_pp(other.m_pp) |
| 472 | { } |
| 473 | |
| 474 | private: |
| 475 | MapT *m_pmap; |
| 476 | PairT *m_pp; |
| 477 | |
| 478 | friend class iterator_core_access; |
| 479 | ref_t dereference() const |
| 480 | { |
| 481 | BOOST_ASSERT(m_pp != 0 && "out of range" ); |
| 482 | return *m_pp; |
| 483 | } |
| 484 | |
| 485 | void increment() |
| 486 | { |
| 487 | BOOST_ASSERT(m_pp != 0 && "out of range" ); |
| 488 | m_pp = m_pmap->PGetNextAssoc(m_pp); |
| 489 | } |
| 490 | |
| 491 | bool equal(self_t const& other) const |
| 492 | { |
| 493 | BOOST_ASSERT(m_pmap == other.m_pmap && "iterators incompatible" ); |
| 494 | return m_pp == other.m_pp; |
| 495 | } |
| 496 | }; |
| 497 | |
| 498 | struct mfc_cpair_map_functions |
| 499 | { |
| 500 | template< class Iterator, class X > |
| 501 | Iterator begin(X& x) |
| 502 | { |
| 503 | // Workaround: |
| 504 | // Assertion fails if empty. |
| 505 | // MFC document is wrong. |
| 506 | #if !defined(NDEBUG) |
| 507 | if (x.GetCount() == 0) |
| 508 | return Iterator(x, 0); |
| 509 | #endif |
| 510 | |
| 511 | return Iterator(x, x.PGetFirstAssoc()); |
| 512 | } |
| 513 | |
| 514 | template< class Iterator, class X > |
| 515 | Iterator end(X& x) |
| 516 | { |
| 517 | return Iterator(x, 0); |
| 518 | } |
| 519 | }; |
| 520 | |
| 521 | |
| 522 | #endif // !defined(BOOST_RANGE_MFC_NO_CPAIR) |
| 523 | |
| 524 | |
| 525 | // maps |
| 526 | // |
| 527 | |
| 528 | template< > |
| 529 | struct customization< ::CMapPtrToWord > : |
| 530 | mfc_map_functions |
| 531 | { |
| 532 | template< class X > |
| 533 | struct meta |
| 534 | { |
| 535 | typedef void *key_t; |
| 536 | typedef WORD mapped_t; |
| 537 | |
| 538 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 539 | typedef mutable_iterator const_iterator; |
| 540 | }; |
| 541 | }; |
| 542 | |
| 543 | |
| 544 | template< > |
| 545 | struct customization< ::CMapPtrToPtr > : |
| 546 | mfc_map_functions |
| 547 | { |
| 548 | template< class X > |
| 549 | struct meta |
| 550 | { |
| 551 | typedef void *key_t; |
| 552 | typedef void *mapped_t; |
| 553 | |
| 554 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 555 | typedef mutable_iterator const_iterator; |
| 556 | }; |
| 557 | }; |
| 558 | |
| 559 | |
| 560 | template< > |
| 561 | struct customization< ::CMapStringToOb > : |
| 562 | mfc_map_functions |
| 563 | { |
| 564 | template< class X > |
| 565 | struct meta |
| 566 | { |
| 567 | typedef ::CString key_t; |
| 568 | typedef ::CObject *mapped_t; |
| 569 | |
| 570 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 571 | typedef mutable_iterator const_iterator; |
| 572 | }; |
| 573 | }; |
| 574 | |
| 575 | |
| 576 | template< > |
| 577 | struct customization< ::CMapStringToPtr > : |
| 578 | mfc_map_functions |
| 579 | { |
| 580 | template< class X > |
| 581 | struct meta |
| 582 | { |
| 583 | typedef ::CString key_t; |
| 584 | typedef void *mapped_t; |
| 585 | |
| 586 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 587 | typedef mutable_iterator const_iterator; |
| 588 | }; |
| 589 | }; |
| 590 | |
| 591 | |
| 592 | template< > |
| 593 | struct customization< ::CMapStringToString > : |
| 594 | #if !defined(BOOST_RANGE_MFC_NO_CPAIR) |
| 595 | mfc_cpair_map_functions |
| 596 | #else |
| 597 | mfc_map_functions |
| 598 | #endif |
| 599 | { |
| 600 | template< class X > |
| 601 | struct meta |
| 602 | { |
| 603 | #if !defined(BOOST_RANGE_MFC_NO_CPAIR) |
| 604 | typedef typename X::CPair pair_t; |
| 605 | |
| 606 | typedef mfc_cpair_map_iterator<X, pair_t> mutable_iterator; |
| 607 | typedef mfc_cpair_map_iterator<X const, pair_t const> const_iterator; |
| 608 | #else |
| 609 | typedef ::CString key_t; |
| 610 | typedef ::CString mapped_t; |
| 611 | |
| 612 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 613 | typedef mutable_iterator const_iterator; |
| 614 | #endif |
| 615 | }; |
| 616 | }; |
| 617 | |
| 618 | |
| 619 | template< > |
| 620 | struct customization< ::CMapWordToOb > : |
| 621 | mfc_map_functions |
| 622 | { |
| 623 | template< class X > |
| 624 | struct meta |
| 625 | { |
| 626 | typedef WORD key_t; |
| 627 | typedef ::CObject *mapped_t; |
| 628 | |
| 629 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 630 | typedef mutable_iterator const_iterator; |
| 631 | }; |
| 632 | }; |
| 633 | |
| 634 | |
| 635 | template< > |
| 636 | struct customization< ::CMapWordToPtr > : |
| 637 | mfc_map_functions |
| 638 | { |
| 639 | template< class X > |
| 640 | struct meta |
| 641 | { |
| 642 | typedef WORD key_t; |
| 643 | typedef void *mapped_t; |
| 644 | |
| 645 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 646 | typedef mutable_iterator const_iterator; |
| 647 | }; |
| 648 | }; |
| 649 | |
| 650 | |
| 651 | // templates |
| 652 | // |
| 653 | |
| 654 | template< class Type, class ArgType > |
| 655 | struct customization< ::CArray<Type, ArgType> > : |
| 656 | array_functions |
| 657 | { |
| 658 | template< class X > |
| 659 | struct meta |
| 660 | { |
| 661 | typedef Type val_t; |
| 662 | |
| 663 | typedef val_t *mutable_iterator; |
| 664 | typedef val_t const *const_iterator; |
| 665 | }; |
| 666 | }; |
| 667 | |
| 668 | |
| 669 | template< class Type, class ArgType > |
| 670 | struct customization< ::CList<Type, ArgType> > : |
| 671 | list_functions |
| 672 | { |
| 673 | template< class X > |
| 674 | struct meta |
| 675 | { |
| 676 | typedef Type val_t; |
| 677 | |
| 678 | typedef list_iterator<X, val_t> mutable_iterator; |
| 679 | #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF) |
| 680 | typedef list_iterator<X const, val_t const> const_iterator; |
| 681 | #else |
| 682 | typedef list_iterator<X const, val_t const, val_t const> const_iterator; |
| 683 | #endif |
| 684 | }; |
| 685 | }; |
| 686 | |
| 687 | |
| 688 | template< class Key, class ArgKey, class Mapped, class ArgMapped > |
| 689 | struct customization< ::CMap<Key, ArgKey, Mapped, ArgMapped> > : |
| 690 | #if !defined(BOOST_RANGE_MFC_NO_CPAIR) |
| 691 | mfc_cpair_map_functions |
| 692 | #else |
| 693 | mfc_map_functions |
| 694 | #endif |
| 695 | { |
| 696 | template< class X > |
| 697 | struct meta |
| 698 | { |
| 699 | #if !defined(BOOST_RANGE_MFC_NO_CPAIR) |
| 700 | typedef typename X::CPair pair_t; |
| 701 | |
| 702 | typedef mfc_cpair_map_iterator<X, pair_t> mutable_iterator; |
| 703 | typedef mfc_cpair_map_iterator<X const, pair_t const> const_iterator; |
| 704 | #else |
| 705 | typedef Key key_t; |
| 706 | typedef Mapped mapped_t; |
| 707 | |
| 708 | typedef mfc_map_iterator<X, key_t, mapped_t> mutable_iterator; |
| 709 | typedef mutable_iterator const_iterator; |
| 710 | #endif |
| 711 | }; |
| 712 | }; |
| 713 | |
| 714 | |
| 715 | template< class BaseClass, class PtrType > |
| 716 | struct customization< ::CTypedPtrArray<BaseClass, PtrType> > |
| 717 | { |
| 718 | template< class X > |
| 719 | struct fun |
| 720 | { |
| 721 | typedef typename remove_pointer<PtrType>::type val_t; |
| 722 | |
| 723 | typedef typename mpl::if_< is_const<X>, |
| 724 | val_t const, |
| 725 | val_t |
| 726 | >::type val_t_; |
| 727 | |
| 728 | typedef val_t_ * const result_type; |
| 729 | |
| 730 | template< class PtrType_ > |
| 731 | result_type operator()(PtrType_ p) const |
| 732 | { |
| 733 | return static_cast<result_type>(p); |
| 734 | } |
| 735 | }; |
| 736 | |
| 737 | template< class X > |
| 738 | struct meta |
| 739 | { |
| 740 | typedef typename compatible_mutable_iterator<BaseClass>::type miter_t; |
| 741 | typedef typename range_const_iterator<BaseClass>::type citer_t; |
| 742 | |
| 743 | typedef transform_iterator<fun<X>, miter_t> mutable_iterator; |
| 744 | typedef transform_iterator<fun<X const>, citer_t> const_iterator; |
| 745 | }; |
| 746 | |
| 747 | template< class Iterator, class X > |
| 748 | Iterator begin(X& x) |
| 749 | { |
| 750 | return Iterator(boost::begin<BaseClass>(x), fun<X>()); |
| 751 | } |
| 752 | |
| 753 | template< class Iterator, class X > |
| 754 | Iterator end(X& x) |
| 755 | { |
| 756 | return Iterator(boost::end<BaseClass>(x), fun<X>()); |
| 757 | } |
| 758 | }; |
| 759 | |
| 760 | |
| 761 | template< class BaseClass, class PtrType > |
| 762 | struct customization< ::CTypedPtrList<BaseClass, PtrType> > : |
| 763 | list_functions |
| 764 | { |
| 765 | template< class X > |
| 766 | struct meta |
| 767 | { |
| 768 | typedef typename remove_pointer<PtrType>::type val_t; |
| 769 | |
| 770 | // not l-value |
| 771 | typedef list_iterator<X, val_t * const, val_t * const> mutable_iterator; |
| 772 | typedef list_iterator<X const, val_t const * const, val_t const * const> const_iterator; |
| 773 | }; |
| 774 | }; |
| 775 | |
| 776 | |
| 777 | template< class BaseClass, class KeyPtrType, class MappedPtrType > |
| 778 | struct customization< ::CTypedPtrMap<BaseClass, KeyPtrType, MappedPtrType> > : |
| 779 | mfc_map_functions |
| 780 | { |
| 781 | template< class X > |
| 782 | struct meta |
| 783 | { |
| 784 | typedef mfc_map_iterator<X, KeyPtrType, MappedPtrType> mutable_iterator; |
| 785 | typedef mutable_iterator const_iterator; |
| 786 | }; |
| 787 | }; |
| 788 | |
| 789 | |
| 790 | // strings |
| 791 | // |
| 792 | |
| 793 | #if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) |
| 794 | |
| 795 | template< > |
| 796 | struct customization< ::CString > |
| 797 | { |
| 798 | template< class X > |
| 799 | struct meta |
| 800 | { |
| 801 | // LPTSTR/LPCTSTR is not always defined in <tchar.h>. |
| 802 | typedef TCHAR *mutable_iterator; |
| 803 | typedef TCHAR const *const_iterator; |
| 804 | }; |
| 805 | |
| 806 | template< class Iterator, class X > |
| 807 | typename mutable_<Iterator, X>::type begin(X& x) |
| 808 | { |
| 809 | return x.GetBuffer(0); |
| 810 | } |
| 811 | |
| 812 | template< class Iterator, class X > |
| 813 | Iterator begin(X const& x) |
| 814 | { |
| 815 | return x; |
| 816 | } |
| 817 | |
| 818 | template< class Iterator, class X > |
| 819 | Iterator end(X& x) |
| 820 | { |
| 821 | return begin<Iterator>(x) + x.GetLength(); |
| 822 | } |
| 823 | }; |
| 824 | |
| 825 | #endif // defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) |
| 826 | |
| 827 | |
| 828 | } } // namespace boost::range_detail_microsoft |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | // range customizations |
| 834 | // |
| 835 | |
| 836 | |
| 837 | // arrays |
| 838 | // |
| 839 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 840 | boost::range_detail_microsoft::using_type_as_tag, |
| 841 | BOOST_PP_NIL, CByteArray |
| 842 | ) |
| 843 | |
| 844 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 845 | boost::range_detail_microsoft::using_type_as_tag, |
| 846 | BOOST_PP_NIL, CDWordArray |
| 847 | ) |
| 848 | |
| 849 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 850 | boost::range_detail_microsoft::using_type_as_tag, |
| 851 | BOOST_PP_NIL, CStringArray |
| 852 | ) |
| 853 | |
| 854 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 855 | boost::range_detail_microsoft::using_type_as_tag, |
| 856 | BOOST_PP_NIL, CUIntArray |
| 857 | ) |
| 858 | |
| 859 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 860 | boost::range_detail_microsoft::using_type_as_tag, |
| 861 | BOOST_PP_NIL, CWordArray |
| 862 | ) |
| 863 | |
| 864 | |
| 865 | // lists |
| 866 | // |
| 867 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 868 | boost::range_detail_microsoft::using_type_as_tag, |
| 869 | BOOST_PP_NIL, CObList |
| 870 | ) |
| 871 | |
| 872 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 873 | boost::range_detail_microsoft::using_type_as_tag, |
| 874 | BOOST_PP_NIL, CPtrList |
| 875 | ) |
| 876 | |
| 877 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 878 | boost::range_detail_microsoft::using_type_as_tag, |
| 879 | BOOST_PP_NIL, CStringList |
| 880 | ) |
| 881 | |
| 882 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 883 | boost::range_detail_microsoft::using_type_as_tag, |
| 884 | BOOST_PP_NIL, CObArray |
| 885 | ) |
| 886 | |
| 887 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 888 | boost::range_detail_microsoft::using_type_as_tag, |
| 889 | BOOST_PP_NIL, CPtrArray |
| 890 | ) |
| 891 | |
| 892 | |
| 893 | // maps |
| 894 | // |
| 895 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 896 | boost::range_detail_microsoft::using_type_as_tag, |
| 897 | BOOST_PP_NIL, CMapPtrToWord |
| 898 | ) |
| 899 | |
| 900 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 901 | boost::range_detail_microsoft::using_type_as_tag, |
| 902 | BOOST_PP_NIL, CMapPtrToPtr |
| 903 | ) |
| 904 | |
| 905 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 906 | boost::range_detail_microsoft::using_type_as_tag, |
| 907 | BOOST_PP_NIL, CMapStringToOb |
| 908 | ) |
| 909 | |
| 910 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 911 | boost::range_detail_microsoft::using_type_as_tag, |
| 912 | BOOST_PP_NIL, CMapStringToPtr |
| 913 | ) |
| 914 | |
| 915 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 916 | boost::range_detail_microsoft::using_type_as_tag, |
| 917 | BOOST_PP_NIL, CMapStringToString |
| 918 | ) |
| 919 | |
| 920 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 921 | boost::range_detail_microsoft::using_type_as_tag, |
| 922 | BOOST_PP_NIL, CMapWordToOb |
| 923 | ) |
| 924 | |
| 925 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 926 | boost::range_detail_microsoft::using_type_as_tag, |
| 927 | BOOST_PP_NIL, CMapWordToPtr |
| 928 | ) |
| 929 | |
| 930 | |
| 931 | // templates |
| 932 | // |
| 933 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( |
| 934 | boost::range_detail_microsoft::using_type_as_tag, |
| 935 | BOOST_PP_NIL, CArray, 2 |
| 936 | ) |
| 937 | |
| 938 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( |
| 939 | boost::range_detail_microsoft::using_type_as_tag, |
| 940 | BOOST_PP_NIL, CList, 2 |
| 941 | ) |
| 942 | |
| 943 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( |
| 944 | boost::range_detail_microsoft::using_type_as_tag, |
| 945 | BOOST_PP_NIL, CMap, 4 |
| 946 | ) |
| 947 | |
| 948 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( |
| 949 | boost::range_detail_microsoft::using_type_as_tag, |
| 950 | BOOST_PP_NIL, CTypedPtrArray, 2 |
| 951 | ) |
| 952 | |
| 953 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( |
| 954 | boost::range_detail_microsoft::using_type_as_tag, |
| 955 | BOOST_PP_NIL, CTypedPtrList, 2 |
| 956 | ) |
| 957 | |
| 958 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE( |
| 959 | boost::range_detail_microsoft::using_type_as_tag, |
| 960 | BOOST_PP_NIL, CTypedPtrMap, 3 |
| 961 | ) |
| 962 | |
| 963 | |
| 964 | // strings |
| 965 | // |
| 966 | #if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING) |
| 967 | |
| 968 | BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE( |
| 969 | boost::range_detail_microsoft::using_type_as_tag, |
| 970 | BOOST_PP_NIL, CString |
| 971 | ) |
| 972 | |
| 973 | #endif |
| 974 | |
| 975 | |
| 976 | |
| 977 | |
| 978 | #endif |
| 979 | |