2f6f11a00e3173cddf569b1e3d26241e8c3d26c6
[senf.git] / boost / multi_index / detail / safe_ctr_proxy.hpp
1 /* Copyright 2003-2006 Joaquín M López Muñoz.
2  * Distributed under the Boost Software License, Version 1.0.
3  * (See accompanying file LICENSE_1_0.txt or copy at
4  * http://www.boost.org/LICENSE_1_0.txt)
5  *
6  * See http://www.boost.org/libs/multi_index for library home page.
7  */
8
9 #ifndef BOOST_MULTI_INDEX_DETAIL_SAFE_CTR_PROXY_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_SAFE_CTR_PROXY_HPP
11
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
13 #pragma once
14 #endif
15
16 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
17 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
18 #include <boost/detail/workaround.hpp>
19
20 #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
21 #include <boost/multi_index/detail/safe_mode.hpp>
22
23 namespace boost{
24
25 namespace multi_index{
26
27 namespace detail{
28
29 /* A safe iterator is instantiated in the form
30  * safe_iterator<Iterator,Container>: MSVC++ 6.0 has serious troubles with
31  * the resulting symbols names, given that index names (which stand for
32  * Container) are fairly long themselves. safe_ctr_proxy does not statically
33  * depend on Container, and provides the necessary methods (begin and end) to
34  * the safe mode framework via an abstract interface. With safe_ctr_proxy,
35  * instead of deriving from safe_container<Container> the following base class
36  * must be used:
37  *
38  *   safe_ctr_proxy_impl<Iterator,Container>
39  *
40  * where Iterator is the type of the *unsafe* iterator being wrapped.
41  * The corresponding safe iterator instantiation is then
42  * 
43  *   safe_iterator<Iterator,safe_ctr_proxy<Iterator> >,
44  *
45  * which does not include the name of Container.
46  */
47
48 template<typename Iterator>
49 class safe_ctr_proxy:
50   public safe_mode::safe_container<safe_ctr_proxy<Iterator> >
51 {
52 public:
53   typedef safe_mode::safe_iterator<Iterator,safe_ctr_proxy> iterator;
54   typedef iterator                                          const_iterator;
55
56   iterator       begin(){return begin_impl();}
57   const_iterator begin()const{return begin_impl();}
58   iterator       end(){return end_impl();}
59   const_iterator end()const{return end_impl();}
60
61 protected:
62   virtual iterator       begin_impl()=0;
63   virtual const_iterator begin_impl()const=0;
64   virtual iterator       end_impl()=0;
65   virtual const_iterator end_impl()const=0;
66 };
67
68 template<typename Iterator,typename Container>
69 class safe_ctr_proxy_impl:public safe_ctr_proxy<Iterator>
70 {
71   typedef safe_ctr_proxy<Iterator> super;
72   typedef Container                container_type;
73
74 public:
75   typedef typename super::iterator       iterator;
76   typedef typename super::const_iterator const_iterator;
77
78   virtual iterator       begin_impl(){return container().begin();}
79   virtual const_iterator begin_impl()const{return container().begin();}
80   virtual iterator       end_impl(){return container().end();}
81   virtual const_iterator end_impl()const{return container().end();}
82
83 private:
84   container_type& container()
85   {
86     return *static_cast<container_type*>(this);
87   }
88   
89   const container_type& container()const
90   {
91     return *static_cast<const container_type*>(this);
92   }
93 };
94
95 } /* namespace multi_index::detail */
96
97 } /* namespace multi_index */
98
99 } /* namespace boost */
100
101 #endif /* workaround */
102
103 #endif /* BOOST_MULTI_INDEX_ENABLE_SAFE_MODE */
104
105 #endif