mfc_map.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Boost.Range library
  2. //
  3. // Copyright Adam D. Walling 2012. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_ADAPTOR_MFC_MAP_HPP
  11. #define BOOST_RANGE_ADAPTOR_MFC_MAP_HPP
  12. #if !defined(BOOST_RANGE_MFC_NO_CPAIR)
  13. #include <boost/range/mfc.hpp>
  14. #include <boost/range/adaptor/map.hpp>
  15. namespace boost
  16. {
  17. namespace range_detail
  18. {
  19. // CMap and CMapStringToString range iterators return CPair,
  20. // which has a key and value member. Other MFC range iterators
  21. // already return adapted std::pair objects. This allows usage
  22. // of the map_keys and map_values range adaptors with CMap
  23. // and CMapStringToString
  24. // CPair has a VALUE value member, and a KEY key member; we will
  25. // use VALUE& as the result_type consistent with CMap::operator[]
  26. // specialization for CMap
  27. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  28. struct select_first< CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> >
  29. {
  30. typedef BOOST_DEDUCED_TYPENAME CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> map_type;
  31. typedef BOOST_DEDUCED_TYPENAME range_reference<const map_type>::type argument_type;
  32. typedef BOOST_DEDUCED_TYPENAME const KEY& result_type;
  33. result_type operator()( argument_type r ) const
  34. {
  35. return r.key;
  36. }
  37. };
  38. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  39. struct select_second_mutable< CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> >
  40. {
  41. typedef BOOST_DEDUCED_TYPENAME CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> map_type;
  42. typedef BOOST_DEDUCED_TYPENAME range_reference<map_type>::type argument_type;
  43. typedef BOOST_DEDUCED_TYPENAME VALUE& result_type;
  44. result_type operator()( argument_type r ) const
  45. {
  46. return r.value;
  47. }
  48. };
  49. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  50. struct select_second_const< CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> >
  51. {
  52. typedef BOOST_DEDUCED_TYPENAME CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> map_type;
  53. typedef BOOST_DEDUCED_TYPENAME range_reference<const map_type>::type argument_type;
  54. typedef BOOST_DEDUCED_TYPENAME const VALUE& result_type;
  55. result_type operator()( argument_type r ) const
  56. {
  57. return r.value;
  58. }
  59. };
  60. // specialization for CMapStringToString
  61. template<>
  62. struct select_first< CMapStringToString >
  63. {
  64. typedef range_reference<const CMapStringToString>::type argument_type;
  65. typedef const CString& result_type;
  66. result_type operator()( argument_type r ) const
  67. {
  68. return r.key;
  69. }
  70. };
  71. template<>
  72. struct select_second_mutable< CMapStringToString >
  73. {
  74. typedef range_reference<CMapStringToString>::type argument_type;
  75. typedef CString& result_type;
  76. result_type operator()( argument_type r ) const
  77. {
  78. return r.value;
  79. }
  80. };
  81. template<>
  82. struct select_second_const< CMapStringToString >
  83. {
  84. typedef range_reference<const CMapStringToString>::type argument_type;
  85. typedef const CString& result_type;
  86. result_type operator()( argument_type r ) const
  87. {
  88. return r.value;
  89. }
  90. };
  91. } // 'range_detail'
  92. } // 'boost'
  93. #endif // !defined(BOOST_RANGE_MFC_NO_CPAIR)
  94. #endif