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 |
|
---|
11 | #ifndef BOOST_RANGE_ADAPTOR_MFC_MAP_HPP
|
---|
12 | #define BOOST_RANGE_ADAPTOR_MFC_MAP_HPP
|
---|
13 |
|
---|
14 | #if !defined(BOOST_RANGE_MFC_NO_CPAIR)
|
---|
15 |
|
---|
16 | #include <boost/range/mfc.hpp>
|
---|
17 | #include <boost/range/adaptor/map.hpp>
|
---|
18 |
|
---|
19 | namespace boost
|
---|
20 | {
|
---|
21 | namespace range_detail
|
---|
22 | {
|
---|
23 | // CMap and CMapStringToString range iterators return CPair,
|
---|
24 | // which has a key and value member. Other MFC range iterators
|
---|
25 | // already return adapted std::pair objects. This allows usage
|
---|
26 | // of the map_keys and map_values range adaptors with CMap
|
---|
27 | // and CMapStringToString
|
---|
28 |
|
---|
29 | // CPair has a VALUE value member, and a KEY key member; we will
|
---|
30 | // use VALUE& as the result_type consistent with CMap::operator[]
|
---|
31 |
|
---|
32 | // specialization for CMap
|
---|
33 | template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
|
---|
34 | struct select_first< CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> >
|
---|
35 | {
|
---|
36 | typedef BOOST_DEDUCED_TYPENAME CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> map_type;
|
---|
37 | typedef BOOST_DEDUCED_TYPENAME range_reference<const map_type>::type argument_type;
|
---|
38 | typedef BOOST_DEDUCED_TYPENAME const KEY& result_type;
|
---|
39 |
|
---|
40 | result_type operator()( argument_type r ) const
|
---|
41 | {
|
---|
42 | return r.key;
|
---|
43 | }
|
---|
44 | };
|
---|
45 |
|
---|
46 | template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
|
---|
47 | struct select_second_mutable< CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> >
|
---|
48 | {
|
---|
49 | typedef BOOST_DEDUCED_TYPENAME CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> map_type;
|
---|
50 | typedef BOOST_DEDUCED_TYPENAME range_reference<map_type>::type argument_type;
|
---|
51 | typedef BOOST_DEDUCED_TYPENAME VALUE& result_type;
|
---|
52 |
|
---|
53 | result_type operator()( argument_type r ) const
|
---|
54 | {
|
---|
55 | return r.value;
|
---|
56 | }
|
---|
57 | };
|
---|
58 |
|
---|
59 | template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
|
---|
60 | struct select_second_const< CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> >
|
---|
61 | {
|
---|
62 | typedef BOOST_DEDUCED_TYPENAME CMap<KEY, ARG_KEY, VALUE, ARG_VALUE> map_type;
|
---|
63 | typedef BOOST_DEDUCED_TYPENAME range_reference<const map_type>::type argument_type;
|
---|
64 | typedef BOOST_DEDUCED_TYPENAME const VALUE& result_type;
|
---|
65 |
|
---|
66 | result_type operator()( argument_type r ) const
|
---|
67 | {
|
---|
68 | return r.value;
|
---|
69 | }
|
---|
70 | };
|
---|
71 |
|
---|
72 |
|
---|
73 | // specialization for CMapStringToString
|
---|
74 | template<>
|
---|
75 | struct select_first< CMapStringToString >
|
---|
76 | {
|
---|
77 | typedef range_reference<const CMapStringToString>::type argument_type;
|
---|
78 | typedef const CString& result_type;
|
---|
79 |
|
---|
80 | result_type operator()( argument_type r ) const
|
---|
81 | {
|
---|
82 | return r.key;
|
---|
83 | }
|
---|
84 | };
|
---|
85 |
|
---|
86 | template<>
|
---|
87 | struct select_second_mutable< CMapStringToString >
|
---|
88 | {
|
---|
89 | typedef range_reference<CMapStringToString>::type argument_type;
|
---|
90 | typedef CString& result_type;
|
---|
91 |
|
---|
92 | result_type operator()( argument_type r ) const
|
---|
93 | {
|
---|
94 | return r.value;
|
---|
95 | }
|
---|
96 | };
|
---|
97 |
|
---|
98 | template<>
|
---|
99 | struct select_second_const< CMapStringToString >
|
---|
100 | {
|
---|
101 | typedef range_reference<const CMapStringToString>::type argument_type;
|
---|
102 | typedef const CString& result_type;
|
---|
103 |
|
---|
104 | result_type operator()( argument_type r ) const
|
---|
105 | {
|
---|
106 | return r.value;
|
---|
107 | }
|
---|
108 | };
|
---|
109 | } // 'range_detail'
|
---|
110 | } // 'boost'
|
---|
111 |
|
---|
112 | #endif // !defined(BOOST_RANGE_MFC_NO_CPAIR)
|
---|
113 |
|
---|
114 | #endif
|
---|