shared_container_iterator.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // See http://www.boost.org/libs/utility/shared_container_iterator.html for documentation.
  6. #ifndef BOOST_SHARED_CONTAINER_ITERATOR_HPP
  7. #define BOOST_SHARED_CONTAINER_ITERATOR_HPP
  8. #include "boost/iterator_adaptors.hpp"
  9. #include "boost/shared_ptr.hpp"
  10. #include <utility>
  11. namespace boost {
  12. namespace iterators {
  13. template <typename Container>
  14. class shared_container_iterator : public iterator_adaptor<
  15. shared_container_iterator<Container>,
  16. typename Container::iterator> {
  17. typedef iterator_adaptor<
  18. shared_container_iterator<Container>,
  19. typename Container::iterator> super_t;
  20. typedef typename Container::iterator iterator_t;
  21. typedef boost::shared_ptr<Container> container_ref_t;
  22. container_ref_t container_ref;
  23. public:
  24. shared_container_iterator() { }
  25. shared_container_iterator(iterator_t const& x,container_ref_t const& c) :
  26. super_t(x), container_ref(c) { }
  27. };
  28. template <typename Container>
  29. inline shared_container_iterator<Container>
  30. make_shared_container_iterator(typename Container::iterator iter,
  31. boost::shared_ptr<Container> const& container) {
  32. typedef shared_container_iterator<Container> iterator;
  33. return iterator(iter,container);
  34. }
  35. template <typename Container>
  36. inline std::pair<
  37. shared_container_iterator<Container>,
  38. shared_container_iterator<Container> >
  39. make_shared_container_range(boost::shared_ptr<Container> const& container) {
  40. return
  41. std::make_pair(
  42. make_shared_container_iterator(container->begin(),container),
  43. make_shared_container_iterator(container->end(),container));
  44. }
  45. } // namespace iterators
  46. using iterators::shared_container_iterator;
  47. using iterators::make_shared_container_iterator;
  48. using iterators::make_shared_container_range;
  49. } // namespace boost
  50. #endif