Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:19

0001 #ifndef BOOST_RANGE_ATL_HPP
0002 #define BOOST_RANGE_ATL_HPP
0003 
0004 
0005 
0006 
0007 // Boost.Range ATL Extension
0008 //
0009 // Copyright Shunsuke Sogame 2005-2006.
0010 // Distributed under the Boost Software License, Version 1.0. 
0011 // (See accompanying file LICENSE_1_0.txt or copy at 
0012 // http://www.boost.org/LICENSE_1_0.txt)
0013 
0014 
0015 
0016 
0017 // config
0018 //
0019 
0020 
0021 #include <atldef.h> // _ATL_VER
0022 
0023 
0024 #if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS)
0025     #if (_ATL_VER < 0x0700)
0026         #define BOOST_RANGE_ATL_NO_COLLECTIONS
0027     #endif
0028 #endif
0029 
0030 
0031 #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0032     #if (_ATL_VER < 0x0700) // dubious
0033         #define BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX
0034     #endif
0035 #endif
0036 
0037 
0038 // forward declarations
0039 //
0040 
0041 
0042 #include <basetyps.h> // IID
0043 
0044 
0045 namespace ATL {
0046 
0047 
0048 #if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS)
0049 
0050 
0051     // arrays
0052     //
0053     template< class E, class ETraits >
0054     class CAtlArray;
0055 
0056     template< class E >
0057     class CAutoPtrArray;
0058 
0059     template< class I, const IID *piid >
0060     class CInterfaceArray;
0061 
0062 
0063     // lists
0064     //
0065     template< class E, class ETraits >
0066     class CAtlList;
0067 
0068     template< class E >
0069     class CAutoPtrList;
0070 
0071     template< class E, class Allocator >
0072     class CHeapPtrList;
0073 
0074     template< class I, const IID *piid >
0075     class CInterfaceList;
0076 
0077 
0078     // maps
0079     //
0080     template< class K, class V, class KTraits, class VTraits >
0081     class CAtlMap;
0082 
0083     template< class K, class V, class KTraits, class VTraits >
0084     class CRBTree;
0085 
0086     template< class K, class V, class KTraits, class VTraits >
0087     class CRBMap;
0088 
0089     template< class K, class V, class KTraits, class VTraits >
0090     class CRBMultiMap;
0091 
0092 
0093     // strings
0094     //
0095 #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLESTRING)
0096     template< class BaseType, bool t_bMFCDLL >
0097     class CSimpleStringT;
0098 #else
0099     template< class BaseType >
0100     class CSimpleStringT;
0101 #endif
0102 
0103     template< class BaseType, class StringTraits >
0104     class CStringT;
0105 
0106     template< class StringType, int t_nChars >
0107     class CFixedStringT;
0108 
0109     template< class BaseType, const int t_nSize >
0110     class CStaticString;
0111 
0112 
0113 #endif // !defined(BOOST_RANGE_ATL_NO_COLLECTIONS)
0114 
0115 
0116     // simples
0117     //
0118 #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0119 
0120     template< class T, class TEqual >
0121     class CSimpleArray;
0122 
0123     template< class TKey, class TVal, class TEqual >
0124     class CSimpleMap;
0125 
0126 #else
0127 
0128     template< class T >
0129     class CSimpleArray;
0130 
0131     template< class T >
0132     class CSimpleValArray;
0133 
0134     template< class TKey, class TVal >
0135     class CSimpleMap;
0136 
0137 #endif // !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0138 
0139 
0140     // pointers
0141     //
0142     template< class E >
0143     class CAutoPtr;
0144 
0145     template< class T >
0146     class CComPtr;
0147 
0148     template< class T, const IID *piid >
0149     class CComQIPtr;
0150 
0151     template< class E, class Allocator >
0152     class CHeapPtr;
0153 
0154     template< class T >
0155     class CAdapt;
0156 
0157 
0158 } // namespace ATL
0159 
0160 
0161 
0162 
0163 // indirect_iterator customizations
0164 //
0165 
0166 
0167 #include <boost/mpl/identity.hpp>
0168 #include <boost/pointee.hpp>
0169 
0170 
0171 namespace boost {
0172 
0173 
0174     template< class E >
0175     struct pointee< ATL::CAutoPtr<E> > :
0176         mpl::identity<E>
0177     { };
0178 
0179     template< class T >
0180     struct pointee< ATL::CComPtr<T> > :
0181         mpl::identity<T>
0182     { };
0183 
0184     template< class T, const IID *piid >
0185     struct pointee< ATL::CComQIPtr<T, piid> > :
0186         mpl::identity<T>
0187     { };
0188 
0189     template< class E, class Allocator >
0190     struct pointee< ATL::CHeapPtr<E, Allocator> > :
0191         mpl::identity<E>
0192     { };
0193 
0194     template< class T >
0195     struct pointee< ATL::CAdapt<T> > :
0196         pointee<T>
0197     { };
0198 
0199 
0200 } // namespace boost
0201 
0202 
0203 
0204 
0205 // extended customizations
0206 //
0207 
0208 
0209 #include <boost/iterator/indirect_iterator.hpp>
0210 #include <boost/iterator/zip_iterator.hpp>
0211 #include <boost/range/detail/microsoft.hpp>
0212 #include <boost/tuple/tuple.hpp>
0213 #include <atlbase.h> // CComBSTR
0214 
0215 
0216 namespace boost { namespace range_detail_microsoft {
0217 
0218 
0219 #if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS)
0220 
0221 
0222     // arrays
0223     //
0224 
0225     struct atl_array_functions :
0226         array_functions
0227     {
0228         template< class Iterator, class X >
0229         Iterator end(X& x) // redefine
0230         {
0231             return x.GetData() + x.GetCount(); // no 'GetSize()'
0232         }
0233     };
0234 
0235 
0236     template< class E, class ETraits >
0237     struct customization< ATL::CAtlArray<E, ETraits> > :
0238         atl_array_functions
0239     {
0240         template< class X >
0241         struct meta
0242         {
0243             typedef E val_t;
0244 
0245             typedef val_t *mutable_iterator;
0246             typedef val_t const *const_iterator;
0247         };
0248     };
0249 
0250 
0251     template< class E >
0252     struct customization< ATL::CAutoPtrArray<E> > :
0253         atl_array_functions
0254     {
0255         template< class X >
0256         struct meta
0257         {
0258             // ATL::CAutoPtr/CHeapPtr is no assignable.
0259             typedef ATL::CAutoPtr<E> val_t;
0260             typedef val_t *miter_t;
0261             typedef val_t const *citer_t;
0262 
0263             typedef indirect_iterator<miter_t> mutable_iterator;
0264             typedef indirect_iterator<citer_t> const_iterator;
0265         };
0266     };
0267 
0268 
0269     template< class I, const IID *piid >
0270     struct customization< ATL::CInterfaceArray<I, piid> > :
0271         atl_array_functions
0272     {
0273         template< class X >
0274         struct meta
0275         {
0276             typedef ATL::CComQIPtr<I, piid> val_t;
0277 
0278             typedef val_t *mutable_iterator;
0279             typedef val_t const *const_iterator;
0280         };
0281     };
0282 
0283 
0284     template< class E, class ETraits >
0285     struct customization< ATL::CAtlList<E, ETraits> > :
0286         list_functions
0287     {
0288         template< class X >
0289         struct meta
0290         {
0291             typedef E val_t;
0292 
0293             typedef list_iterator<X, val_t> mutable_iterator;
0294             typedef list_iterator<X const, val_t const> const_iterator;
0295         };
0296     };
0297 
0298 
0299     struct indirected_list_functions
0300     {
0301         template< class Iterator, class X >
0302         Iterator begin(X& x)
0303         {
0304             typedef typename Iterator::base_type base_t; // == list_iterator
0305             return Iterator(base_t(x, x.GetHeadPosition()));
0306         }
0307 
0308         template< class Iterator, class X >
0309         Iterator end(X& x)
0310         {
0311             typedef typename Iterator::base_type base_t;
0312             return Iterator(base_t(x, POSITION(0)));
0313         }
0314     };
0315 
0316 
0317     template< class E >
0318     struct customization< ATL::CAutoPtrList<E> > :
0319         indirected_list_functions
0320     {
0321         template< class X >
0322         struct meta
0323         {
0324             typedef ATL::CAutoPtr<E> val_t;
0325             typedef list_iterator<X, val_t> miter_t;
0326             typedef list_iterator<X const, val_t const> citer_t;
0327 
0328             typedef indirect_iterator<miter_t> mutable_iterator;
0329             typedef indirect_iterator<citer_t> const_iterator;
0330         };
0331     };
0332 
0333 
0334     template< class E, class Allocator >
0335     struct customization< ATL::CHeapPtrList<E, Allocator> > :
0336         indirected_list_functions
0337     {
0338         template< class X >
0339         struct meta
0340         {
0341             typedef ATL::CHeapPtr<E, Allocator> val_t;
0342             typedef list_iterator<X, val_t> miter_t;
0343             typedef list_iterator<X const, val_t const> citer_t;
0344 
0345             typedef indirect_iterator<miter_t> mutable_iterator;
0346             typedef indirect_iterator<citer_t> const_iterator;
0347         };
0348     };
0349 
0350 
0351     template< class I, const IID *piid >
0352     struct customization< ATL::CInterfaceList<I, piid> > :
0353         list_functions
0354     {
0355         template< class X >
0356         struct meta
0357         {
0358             typedef ATL::CComQIPtr<I, piid> val_t;
0359 
0360             typedef list_iterator<X, val_t> mutable_iterator;
0361             typedef list_iterator<X const, val_t const> const_iterator;
0362         };
0363     };
0364 
0365 
0366     // maps
0367     //
0368 
0369     struct atl_rb_tree_tag
0370     { };
0371 
0372     template< >
0373     struct customization< atl_rb_tree_tag > :
0374         indirected_list_functions
0375     {
0376         template< class X >
0377         struct meta
0378         {
0379             typedef typename X::CPair val_t;
0380 
0381             typedef list_iterator<X, val_t *, val_t *> miter_t;
0382             typedef list_iterator<X const, val_t const *, val_t const *> citer_t;
0383             
0384             typedef indirect_iterator<miter_t> mutable_iterator;
0385             typedef indirect_iterator<citer_t> const_iterator;
0386         };
0387     };
0388 
0389 
0390     template< class K, class V, class KTraits, class VTraits >
0391     struct customization< ATL::CAtlMap<K, V, KTraits, VTraits> > :
0392         customization< atl_rb_tree_tag >
0393     {
0394         template< class Iterator, class X >
0395         Iterator begin(X& x) // redefine
0396         {
0397             typedef typename Iterator::base_type base_t; // == list_iterator
0398             return Iterator(base_t(x, x.GetStartPosition())); // no 'GetHeadPosition'
0399         }
0400     };
0401 
0402 
0403     // strings
0404     //
0405 
0406     struct atl_string_tag
0407     { };
0408 
0409     template< >
0410     struct customization< atl_string_tag >
0411     {
0412         template< class X >
0413         struct meta
0414         {
0415             typedef typename X::PXSTR mutable_iterator;
0416             typedef typename X::PCXSTR const_iterator;
0417         };
0418 
0419         template< class Iterator, class X >
0420         typename mutable_<Iterator, X>::type begin(X& x)
0421         {
0422             return x.GetBuffer(0);
0423         }
0424 
0425         template< class Iterator, class X >
0426         Iterator begin(X const& x)
0427         {
0428             return x.GetString();
0429         }
0430 
0431         template< class Iterator, class X >
0432         Iterator end(X& x)
0433         {
0434             return begin<Iterator>(x) + x.GetLength();
0435         }
0436     };
0437 
0438 
0439     template< class BaseType, const int t_nSize >
0440     struct customization< ATL::CStaticString<BaseType, t_nSize> >
0441     {
0442         template< class X >
0443         struct meta
0444         {
0445             typedef BaseType const *mutable_iterator;
0446             typedef mutable_iterator const_iterator;
0447         };
0448 
0449         template< class Iterator, class X >
0450         Iterator begin(X const& x)
0451         {
0452             return x;
0453         }
0454 
0455         template< class Iterator, class X >
0456         Iterator end(X const& x)
0457         {
0458             return begin<Iterator>(x) + X::GetLength();
0459         }
0460     };
0461 
0462 
0463 #endif // !defined(BOOST_RANGE_ATL_NO_COLLECTIONS)
0464 
0465 
0466     template< >
0467     struct customization< ATL::CComBSTR >
0468     {
0469         template< class X >
0470         struct meta
0471         {
0472             typedef OLECHAR *mutable_iterator;
0473             typedef OLECHAR const *const_iterator;
0474         };
0475 
0476         template< class Iterator, class X >
0477         Iterator begin(X& x)
0478         {
0479             return x.operator BSTR();
0480         }
0481 
0482         template< class Iterator, class X >
0483         Iterator end(X& x)
0484         {
0485             return begin<Iterator>(x) + x.Length();
0486         }
0487     };
0488 
0489 
0490     // simples
0491     //
0492 
0493 #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0494     template< class T, class TEqual >
0495     struct customization< ATL::CSimpleArray<T, TEqual> > :
0496 #else
0497     template< class T >
0498     struct customization< ATL::CSimpleArray<T> > :
0499 #endif
0500         array_functions
0501     {
0502         template< class X >
0503         struct meta
0504         {
0505             typedef T val_t;
0506 
0507             typedef val_t *mutable_iterator;
0508             typedef val_t const *const_iterator;
0509         };
0510     };
0511 
0512 
0513 #if defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0514 
0515     template< class T >
0516     struct customization< ATL::CSimpleValArray<T> > :
0517         array_functions
0518     {
0519         template< class X >
0520         struct meta
0521         {
0522             typedef T val_t;
0523 
0524             typedef val_t *mutable_iterator;
0525             typedef val_t const *const_iterator;
0526         };
0527     };
0528 
0529 #endif // defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0530 
0531 
0532 #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0533     template< class TKey, class TVal, class TEqual >
0534     struct customization< ATL::CSimpleMap<TKey, TVal, TEqual> >
0535 #else
0536     template< class TKey, class TVal >
0537     struct customization< ATL::CSimpleMap<TKey, TVal> >
0538 #endif
0539     {
0540         template< class X >
0541         struct meta
0542         {
0543             typedef TKey k_val_t;
0544             typedef k_val_t *k_miter_t;
0545             typedef k_val_t const *k_citer_t;
0546 
0547             typedef TVal v_val_t;
0548             typedef v_val_t *v_miter_t;
0549             typedef v_val_t const *v_citer_t;
0550 
0551             // Topic:
0552             // 'std::pair' can't contain references
0553             // because of reference to reference problem.
0554 
0555             typedef zip_iterator< tuple<k_miter_t, v_miter_t> > mutable_iterator;
0556             typedef zip_iterator< tuple<k_citer_t, v_citer_t> > const_iterator;
0557         };
0558 
0559         template< class Iterator, class X >
0560         Iterator begin(X& x)
0561         {
0562             return Iterator(boost::make_tuple(x.m_aKey, x.m_aVal));
0563         }
0564 
0565         template< class Iterator, class X >
0566         Iterator end(X& x)
0567         {
0568             return Iterator(boost::make_tuple(x.m_aKey + x.GetSize(), x.m_aVal + x.GetSize()));
0569         }
0570     };
0571 
0572 
0573 } } // namespace boost::range_detail_microsoft
0574 
0575 
0576 
0577 
0578 // range customizations
0579 //
0580 
0581 
0582 #if !defined(BOOST_RANGE_ATL_NO_COLLECTIONS)
0583 
0584 
0585     // arrays
0586     //
0587     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0588         boost::range_detail_microsoft::using_type_as_tag,
0589         (ATL, BOOST_PP_NIL), CAtlArray, 2
0590     )
0591 
0592     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0593         boost::range_detail_microsoft::using_type_as_tag,
0594         (ATL, BOOST_PP_NIL), CAutoPtrArray, 1
0595     )
0596 
0597     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0598         boost::range_detail_microsoft::using_type_as_tag,
0599         (ATL, BOOST_PP_NIL), CInterfaceArray, (class)(const IID *)
0600     )
0601 
0602 
0603     // lists
0604     //
0605     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0606         boost::range_detail_microsoft::using_type_as_tag,
0607         (ATL, BOOST_PP_NIL), CAtlList, 2
0608     )
0609 
0610     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0611         boost::range_detail_microsoft::using_type_as_tag,
0612         (ATL, BOOST_PP_NIL), CAutoPtrList, 1
0613     )
0614 
0615     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0616         boost::range_detail_microsoft::using_type_as_tag,
0617         (ATL, BOOST_PP_NIL), CHeapPtrList, 2
0618     )
0619 
0620     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0621         boost::range_detail_microsoft::using_type_as_tag,
0622         (ATL, BOOST_PP_NIL), CInterfaceList, (class)(const IID *)
0623     )
0624 
0625 
0626     //maps
0627     //
0628     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0629         boost::range_detail_microsoft::using_type_as_tag,
0630         (ATL, BOOST_PP_NIL), CAtlMap, 4
0631     )
0632 
0633     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0634         boost::range_detail_microsoft::atl_rb_tree_tag,
0635         (ATL, BOOST_PP_NIL), CRBTree, 4
0636     )
0637 
0638     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0639         boost::range_detail_microsoft::atl_rb_tree_tag,
0640         (ATL, BOOST_PP_NIL), CRBMap, 4
0641     )
0642 
0643     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0644         boost::range_detail_microsoft::atl_rb_tree_tag,
0645         (ATL, BOOST_PP_NIL), CRBMultiMap, 4
0646     )
0647 
0648 
0649     // strings
0650     //
0651     #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLESTRING)
0652         BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0653             boost::range_detail_microsoft::atl_string_tag,
0654             (ATL, BOOST_PP_NIL), CSimpleStringT, (class)(bool)
0655         )
0656     #else
0657         BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0658             boost::range_detail_microsoft::atl_string_tag,
0659             (ATL, BOOST_PP_NIL), CSimpleStringT, 1
0660         )
0661     #endif
0662 
0663     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0664         boost::range_detail_microsoft::atl_string_tag,
0665         (ATL, BOOST_PP_NIL), CStringT, 2
0666     )
0667 
0668     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0669         boost::range_detail_microsoft::atl_string_tag,
0670         (ATL, BOOST_PP_NIL), CFixedStringT, (class)(int)
0671     )
0672 
0673     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0674         boost::range_detail_microsoft::using_type_as_tag,
0675         (ATL, BOOST_PP_NIL), CStaticString, (class)(const int)
0676     )
0677 
0678 
0679 #endif // !defined(BOOST_RANGE_ATL_NO_COLLECTIONS)
0680 
0681 
0682 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE(
0683     boost::range_detail_microsoft::using_type_as_tag,
0684     (ATL, BOOST_PP_NIL), CComBSTR
0685 )
0686 
0687 
0688 // simples
0689 //
0690 #if !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0691 
0692     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0693         boost::range_detail_microsoft::using_type_as_tag,
0694         (ATL, BOOST_PP_NIL), CSimpleArray, 2
0695     )
0696 
0697     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0698         boost::range_detail_microsoft::using_type_as_tag,
0699         (ATL, BOOST_PP_NIL), CSimpleMap, 3
0700     )
0701 
0702 #else
0703 
0704     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0705         boost::range_detail_microsoft::using_type_as_tag,
0706         (ATL, BOOST_PP_NIL), CSimpleArray, 1
0707     )
0708 
0709     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0710         boost::range_detail_microsoft::using_type_as_tag,
0711         (ATL, BOOST_PP_NIL), CSimpleMap, 2
0712     )
0713 
0714     BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(
0715         boost::range_detail_microsoft::using_type_as_tag,
0716         (ATL, BOOST_PP_NIL), CSimpleValArray, 1
0717     )
0718 
0719 #endif // !defined(BOOST_RANGE_ATL_HAS_OLD_CSIMPLE_XXX)
0720 
0721 
0722 
0723 
0724 #endif