1 | // (C) Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and |
2 | // distribute this software is granted provided this copyright notice appears |
3 | // in all copies. This software is provided "as is" without express or implied |
4 | // warranty, and with no claim as to its suitability for any purpose. |
5 | |
6 | // See http://www.boost.org/libs/utility/shared_container_iterator.html for documentation. |
7 | |
8 | #ifndef SHARED_CONTAINER_ITERATOR_RG08102002_HPP |
9 | #define SHARED_CONTAINER_ITERATOR_RG08102002_HPP |
10 | |
11 | #include "boost/iterator_adaptors.hpp" |
12 | #include "boost/shared_ptr.hpp" |
13 | #include <utility> |
14 | |
15 | namespace boost { |
16 | namespace iterators { |
17 | |
18 | template <typename Container> |
19 | class shared_container_iterator : public iterator_adaptor< |
20 | shared_container_iterator<Container>, |
21 | typename Container::iterator> { |
22 | |
23 | typedef iterator_adaptor< |
24 | shared_container_iterator<Container>, |
25 | typename Container::iterator> super_t; |
26 | |
27 | typedef typename Container::iterator iterator_t; |
28 | typedef boost::shared_ptr<Container> container_ref_t; |
29 | |
30 | container_ref_t container_ref; |
31 | public: |
32 | shared_container_iterator() { } |
33 | |
34 | shared_container_iterator(iterator_t const& x,container_ref_t const& c) : |
35 | super_t(x), container_ref(c) { } |
36 | |
37 | |
38 | }; |
39 | |
40 | template <typename Container> |
41 | inline shared_container_iterator<Container> |
42 | make_shared_container_iterator(typename Container::iterator iter, |
43 | boost::shared_ptr<Container> const& container) { |
44 | typedef shared_container_iterator<Container> iterator; |
45 | return iterator(iter,container); |
46 | } |
47 | |
48 | |
49 | |
50 | template <typename Container> |
51 | inline std::pair< |
52 | shared_container_iterator<Container>, |
53 | shared_container_iterator<Container> > |
54 | make_shared_container_range(boost::shared_ptr<Container> const& container) { |
55 | return |
56 | std::make_pair( |
57 | make_shared_container_iterator(container->begin(),container), |
58 | make_shared_container_iterator(container->end(),container)); |
59 | } |
60 | |
61 | } // namespace iterators |
62 | |
63 | using iterators::shared_container_iterator; |
64 | using iterators::make_shared_container_iterator; |
65 | using iterators::make_shared_container_range; |
66 | |
67 | } // namespace boost |
68 | |
69 | #endif // SHARED_CONTAINER_ITERATOR_RG08102002_HPP |
70 | |