📄 atl.cpp
字号:
// Boost.Range ATL Extension//// Copyright Shunsuke Sogame 2005-2006.// Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt)// #include <pstade/vodka/drink.hpp>#include <boost/test/test_tools.hpp>#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS#define _ATL_NO_AUTOMATIC_NAMESPACE#define BOOST_LIB_NAME boost_test_exec_monitor#include <boost/config/auto_link.hpp>#define BOOST_RANGE_DETAIL_MICROSOFT_TEST#include <boost/range/atl.hpp> // can be placed first#include <map>#include <string>#include <boost/concept_check.hpp>#include <boost/mpl/if.hpp>#include <boost/range/begin.hpp>#include <boost/range/distance.hpp>#include <boost/range/iterator_range.hpp>#include <boost/static_assert.hpp>#include <boost/type_traits/is_same.hpp>#include <boost/foreach.hpp>#include <atlbase.h> // for ATL3 CSimpleArray/CSimpleValArray#if !(_ATL_VER < 0x0700) #include <atlcoll.h> #include <cstringt.h> #include <atlsimpstr.h> #include <atlstr.h>#endifnamespace brdm = boost::range_detail_microsoft;#if !(_ATL_VER < 0x0700)template< class ArrayT, class SampleRange >bool test_init_auto_ptr_array(ArrayT& arr, SampleRange& sample){ typedef typename boost::range_iterator<SampleRange>::type iter_t; for (iter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { arr.Add(*it); // moves ownership } return boost::distance(arr) == boost::distance(sample);}template< class ListT, class SampleRange >bool test_init_auto_ptr_list(ListT& lst, SampleRange& sample){ typedef typename boost::range_iterator<SampleRange>::type iter_t; typedef typename boost::range_value<SampleRange>::type val_t; for (iter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { lst.AddTail(*it); // moves ownership } return boost::distance(lst) == boost::distance(sample);}// Workaround:// CRBTree provides no easy access function, but yes, it is the range!//template< class AtlMapT, class KeyT, class MappedT >bool test_atl_map_has(AtlMapT& map, const KeyT& k, const MappedT m){ typedef typename boost::range_iterator<AtlMapT>::type iter_t; for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) { if (it->m_key == k && it->m_value == m) return true; } return false;}template< class AtlMapT, class MapT >bool test_atl_map(AtlMapT& map, const MapT& sample){ typedef typename boost::range_iterator<AtlMapT>::type iter_t; typedef typename boost::range_const_iterator<MapT>::type siter_t; bool result = true; result = result && (boost::distance(map) == boost::distance(sample)); if (!result) return false; { for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) { result = result && brdm::test_find_key_and_mapped(sample, std::make_pair(it->m_key, it->m_value)); } } { for (siter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) { result = result && (test_atl_map_has)(map, it->first, it->second); } } return result;}template< class MapT, class SampleMap >bool test_init_atl_multimap(MapT& map, const SampleMap& sample){ typedef typename boost::range_const_iterator<SampleMap>::type iter_t; for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) { map.Insert(it->first, it->second); } return boost::distance(map) == boost::distance(sample);}// arrays//template< class Range >void test_CAtlArray(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef ATL::CAtlArray<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, val_t *>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, val_t const*>::value )); rng_t rng; BOOST_CHECK( brdm::test_init_array(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class ValT, class Range >void test_CAutoPtrArray(Range& sample){ typedef ValT val_t; typedef ATL::CAutoPtrArray<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, boost::indirect_iterator< ATL::CAutoPtr<val_t> *> >::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, boost::indirect_iterator< ATL::CAutoPtr<val_t> const*> >::value )); rng_t rng; BOOST_CHECK( ::test_init_auto_ptr_array(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class I, class Range >void test_CInterfaceArray(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef ATL::CInterfaceArray<I> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, ATL::CComQIPtr<I> * >::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, ATL::CComQIPtr<I> const* >::value )); rng_t rng; BOOST_CHECK( brdm::test_init_array(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}// lists//template< class Range >void test_CAtlList(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef ATL::CAtlList<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator<rng_t, val_t> >::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, val_t const> >::value )); rng_t rng; BOOST_CHECK( brdm::test_init_list(rng, sample) ); BOOST_CHECK( brdm::test_bidirectional(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class ValT, class Range >void test_CAutoPtrList(Range& sample){ typedef ValT val_t; typedef ATL::CAutoPtrList<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, boost::indirect_iterator< brdm::list_iterator<rng_t, ATL::CAutoPtr<val_t> > > >::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, boost::indirect_iterator< brdm::list_iterator<rng_t const, ATL::CAutoPtr<val_t> const> > >::value )); rng_t rng; BOOST_CHECK( ::test_init_auto_ptr_list(rng, sample) ); BOOST_CHECK( brdm::test_bidirectional(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class ValT, class Range >void test_CHeapPtrList(const Range& sample){ typedef ValT val_t; typedef ATL::CHeapPtrList<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, boost::indirect_iterator< brdm::list_iterator<rng_t, ATL::CHeapPtr<val_t> > > >::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, boost::indirect_iterator< brdm::list_iterator<rng_t const, ATL::CHeapPtr<val_t> const> > >::value )); rng_t rng; BOOST_CHECK( ::test_init_auto_ptr_list(rng, sample) ); BOOST_CHECK( brdm::test_bidirectional(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class I, class Range >void test_CInterfaceList(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef ATL::CInterfaceList<I> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator<rng_t, ATL::CComQIPtr<I> > >::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, ATL::CComQIPtr<I> const> >::value )); rng_t rng; BOOST_CHECK( brdm::test_init_list(rng, sample) ); BOOST_CHECK( brdm::test_bidirectional(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}// strings//template< class Range >void test_CSimpleStringT(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef typename boost::mpl::if_< boost::is_same<val_t, char>, ATL::CAtlStringA, ATL::CAtlStringW >::type derived_t; typedef ATL::CSimpleStringT<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, typename rng_t::PXSTR>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, typename rng_t::PCXSTR>::value )); derived_t drng; rng_t& rng = drng; BOOST_CHECK( brdm::test_init_string(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); // BOOST_CHECK( brdm::test_emptiness(rng) ); no default constructible}template< int n, class Range >void test_CFixedStringT(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef typename boost::mpl::if_< boost::is_same<val_t, char>, ATL::CAtlStringA, ATL::CAtlStringW >::type base_t; typedef ATL::CFixedStringT<base_t, n> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, typename rng_t::PXSTR>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, typename rng_t::PCXSTR>::value )); rng_t rng; BOOST_CHECK( brdm::test_init_string(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class Range >void test_CStringT(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef typename boost::mpl::if_< boost::is_same<val_t, char>, ATL::CAtlStringA, // == CStringT<char, X> ATL::CAtlStringW // == CStringT<wchar_t, X> >::type rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, typename rng_t::PXSTR>::value ));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -