[857] | 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 |
|
---|
| 17 | template <typename Container>
|
---|
| 18 | class shared_container_iterator : public iterator_adaptor<
|
---|
| 19 | shared_container_iterator<Container>,
|
---|
| 20 | typename Container::iterator> {
|
---|
| 21 |
|
---|
| 22 | typedef iterator_adaptor<
|
---|
| 23 | shared_container_iterator<Container>,
|
---|
| 24 | typename Container::iterator> super_t;
|
---|
| 25 |
|
---|
| 26 | typedef typename Container::iterator iterator_t;
|
---|
| 27 | typedef boost::shared_ptr<Container> container_ref_t;
|
---|
| 28 |
|
---|
| 29 | container_ref_t container_ref;
|
---|
| 30 | public:
|
---|
| 31 | shared_container_iterator() { }
|
---|
| 32 |
|
---|
| 33 | shared_container_iterator(iterator_t const& x,container_ref_t const& c) :
|
---|
| 34 | super_t(x), container_ref(c) { }
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | };
|
---|
| 38 |
|
---|
| 39 | template <typename Container>
|
---|
| 40 | shared_container_iterator<Container>
|
---|
| 41 | make_shared_container_iterator(typename Container::iterator iter,
|
---|
| 42 | boost::shared_ptr<Container> const& container) {
|
---|
| 43 | typedef shared_container_iterator<Container> iterator;
|
---|
| 44 | return iterator(iter,container);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | template <typename Container>
|
---|
| 50 | std::pair<
|
---|
| 51 | shared_container_iterator<Container>,
|
---|
| 52 | shared_container_iterator<Container> >
|
---|
| 53 | make_shared_container_range(boost::shared_ptr<Container> const& container) {
|
---|
| 54 | return
|
---|
| 55 | std::make_pair(
|
---|
| 56 | make_shared_container_iterator(container->begin(),container),
|
---|
| 57 | make_shared_container_iterator(container->end(),container));
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | } // namespace boost
|
---|
| 62 | #endif // SHARED_CONTAINER_ITERATOR_RG08102002_HPP
|
---|