15 #ifndef INCG_IRIS_IUTEST_MFC_HPP_43CC925C_BED2_4D9D_8502_78204B69B675_
16 #define INCG_IRIS_IUTEST_MFC_HPP_43CC925C_BED2_4D9D_8502_78204B69B675_
29 template<
typename T,
typename U>
30 class mfc_iterator :
public ::std::iterator < ::std::input_iterator_tag, U >
32 typedef typename iutest_type_traits::add_const_to_pointer<U>::type Item;
34 mfc_iterator(
const T& container, POSITION pos) : m_container(container), m_pos(pos) {}
39 mfc_iterator& operator ++ () { advance();
return *
this; }
42 Item operator * ()
const {
return m_container.GetAt(m_pos); }
43 Item operator -> ()
const {
return m_container.GetAt(m_pos); }
45 bool operator == (
mfc_iterator& rhs) {
return rhs.m_pos == m_pos; }
46 bool operator != (
mfc_iterator& rhs) {
return rhs.m_pos != m_pos; }
50 __if_exists(T::GetNext) {
51 m_container.GetNext(m_pos);
53 __if_not_exists(T::GetNext) {
65 template<
typename T,
typename Key,
typename Value>
66 class mfc_map_iterator :
public ::std::iterator < ::std::input_iterator_tag, ::std::pair<Key, Value> >
68 typedef ::std::pair<Key, Value> Item;
70 mfc_map_iterator(
const T& container, POSITION pos) : m_container(container), m_pos(pos) {}
78 Item operator * ()
const {
return m_pair; }
79 Item operator -> ()
const {
return m_pair; }
86 __if_exists(T::GetNextAssoc) {
87 m_container.GetNextAssoc(m_pos, m_pair.first, m_pair.second);
94 ::std::pair<Key, Value> m_pair;
97 template<
typename T,
typename U>
102 template<
typename T,
typename U>
103 mfc_iterator<CList<T, U>, T> end(CList<T, U>& list)
105 return mfc_iterator<CList<T, U>, T>(list, NULL);
108 template<
typename T,
typename U>
109 T* begin(CArray<T, U>& ar)
113 template<
typename T,
typename U>
114 T* end(CArray<T, U>& ar)
116 return ar.GetData() + ar.GetCount();
119 template<
typename T,
typename TA,
typename U,
typename UA>
120 mfc_map_iterator< CMap<T, TA, U, UA>, T, U > begin(CMap<T, TA, U, UA>& map)
122 return mfc_map_iterator< CMap<T, TA, U, UA>, T, U >(map, map.GetStartPosition());
125 template<
typename T,
typename TA,
typename U,
typename UA>
126 mfc_map_iterator< CMap<T, TA, U, UA>, T, U > end(CMap<T, TA, U, UA>& map)
128 return mfc_map_iterator< CMap<T, TA, U, UA>, T, U >(map, NULL);
135 struct base_type :
public T
137 __if_exists(T::BASE_TYPE)
140 typedef typename T::BASE_TYPE BASE_KEY;
141 typedef typename T::BASE_TYPE BASE_VALUE;
144 __if_not_exists(T::BASE_TYPE)
146 __if_exists(T::BASE_KEY)
148 __if_exists(T::BASE_VALUE)
152 typedef ::std::pair<T::BASE_KEY, T::BASE_VALUE> BASE_TYPE;
157 template<
typename T,
typename U>
158 struct base_type< CArray<T, U> >
162 typedef T BASE_VALUE;
164 template<
typename BASE_CLASS,
typename T>
165 struct base_type< CTypedPtrArray<BASE_CLASS, T> >
169 typedef T BASE_VALUE;
171 template<
typename T,
typename U>
172 struct base_type< CList<T, U> >
176 typedef T BASE_VALUE;
178 template<
typename BASE_CLASS,
typename T>
179 struct base_type< CTypedPtrList<BASE_CLASS, T> >
183 typedef T BASE_VALUE;
185 template<
typename T,
typename TA,
typename U,
typename UA>
186 struct base_type< CMap<T, TA, U, UA> >
188 typedef ::std::pair<T, U> BASE_TYPE;
190 typedef U BASE_VALUE;
192 template<
typename BASE_CLASS,
typename KEY,
typename VALUE>
193 struct base_type< CTypedPtrMap<BASE_CLASS, KEY, VALUE> >
195 typedef ::std::pair<KEY, VALUE> BASE_TYPE;
196 typedef KEY BASE_KEY;
197 typedef VALUE BASE_VALUE;
201 struct mfc_iterator_traits
203 typedef typename base_type<T>::BASE_TYPE BASE_TYPE;
204 typedef typename base_type<T>::BASE_KEY BASE_KEY;
205 typedef typename base_type<T>::BASE_VALUE BASE_VALUE;
206 template<
typename U,
bool isArray,
bool isList>
209 typedef mfc_map_iterator<T, BASE_KEY, BASE_VALUE> type;
212 struct type_select<U, true, false>
217 struct type_select<U, false, true>
219 typedef mfc_iterator<T, U> type;
221 typedef typename type_select<BASE_TYPE
222 , IUTEST_STATIC_EXISTS(T::GetData)
223 , IUTEST_STATIC_EXISTS(T::GetHeadPosition)
230 typename peep::base_type<T>::BASE_TYPE* begin(T& ar
231 ,
typename detail::enable_if< IUTEST_STATIC_EXISTS(T::GetData),
void>::type*& = detail::enabler::value)
233 return reinterpret_cast<typename peep::base_type<T>::BASE_TYPE*
>(ar.GetData());
236 typename peep::base_type<T>::BASE_TYPE* end(T& ar
237 ,
typename detail::enable_if< IUTEST_STATIC_EXISTS(T::GetData),
void>::type*& = detail::enabler::value)
239 return reinterpret_cast<typename peep::base_type<T>::BASE_TYPE*
>(ar.GetData() + ar.GetCount());
243 mfc_iterator<T, typename peep::base_type<T>::BASE_TYPE> begin(T& list
244 ,
typename detail::enable_if< IUTEST_STATIC_EXISTS(T::GetHeadPosition),
void>::type*& = detail::enabler::value)
246 return mfc_iterator<T, peep::base_type<T>::BASE_TYPE>(list, list.GetHeadPosition());
249 mfc_iterator<T, typename peep::base_type<T>::BASE_TYPE> end(T& list
250 ,
typename detail::enable_if< IUTEST_STATIC_EXISTS(T::GetHeadPosition),
void>::type*& = detail::enabler::value)
252 return mfc_iterator<T, peep::base_type<T>::BASE_TYPE>(list, NULL);
256 typename peep::mfc_iterator_traits<T>::type begin(T& map
257 ,
typename detail::enable_if< IUTEST_STATIC_EXISTS(T::GetStartPosition),
void>::type*& = detail::enabler::value)
259 return typename peep::mfc_iterator_traits<T>::type(map, map.GetStartPosition());
262 typename peep::mfc_iterator_traits<T>::type end(T& map
263 ,
typename detail::enable_if< IUTEST_STATIC_EXISTS(T::GetStartPosition),
void>::type*& = detail::enabler::value)
265 return typename peep::mfc_iterator_traits<T>::type(map, NULL);
279 typedef typename peep::base_type<T>::BASE_TYPE BASE_TYPE;
280 typedef typename peep::base_type<T>::BASE_KEY BASE_KEY;
281 typedef typename peep::base_type<T>::BASE_VALUE BASE_VALUE;
287 explicit CContainer(T& container) : m_container(container) {}
289 iterator_type begin()
const {
return mfc::begin(m_container); }
provide begin/end in mfc container
Definition: iutest_mfc.hpp:274
mfc container iterator
Definition: iutest_mfc.hpp:32
mfc map container iterator
Definition: iutest_mfc.hpp:68
CContainer< T > make_container(T &obj)
make mfc container
Definition: iutest_mfc.hpp:301
iutest root namespace
Definition: iutest_charcode.hpp:33