Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/iterator/shared_container_iterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // (C) Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and
0002 // distribute this software is granted provided this copyright notice appears
0003 // in all copies. This software is provided "as is" without express or implied
0004 // warranty, and with no claim as to its suitability for any purpose.
0005 
0006 // See http://www.boost.org/libs/utility/shared_container_iterator.html for documentation.
0007 
0008 #ifndef BOOST_ITERATOR_SHARED_CONTAINER_ITERATOR_HPP_INCLUDED_
0009 #define BOOST_ITERATOR_SHARED_CONTAINER_ITERATOR_HPP_INCLUDED_
0010 
0011 #include <memory>
0012 #include <utility>
0013 #include <boost/iterator/iterator_adaptor.hpp>
0014 
0015 namespace boost {
0016 
0017 // For backward compatibility with boost::shared_ptr
0018 template< class T >
0019 class shared_ptr;
0020 
0021 namespace iterators {
0022 namespace detail {
0023 
0024 // Fake deleter that holds an instance of boost::shared_ptr and through it keeps the pointed object from deletion
0025 template< typename T >
0026 class shared_container_iterator_bsptr_holder
0027 {
0028 private:
0029     boost::shared_ptr< T > m_ptr;
0030 
0031 public:
0032     explicit shared_container_iterator_bsptr_holder(boost::shared_ptr< T > const& ptr) :
0033         m_ptr(ptr)
0034     {}
0035 
0036     void operator()(T*) const noexcept {}
0037 };
0038 
0039 } // namespace detail
0040 
0041 template< typename Container >
0042 class shared_container_iterator :
0043     public iterator_adaptor<
0044         shared_container_iterator< Container >,
0045         typename Container::iterator
0046     >
0047 {
0048 private:
0049     using super_t = iterator_adaptor<
0050         shared_container_iterator< Container >,
0051         typename Container::iterator
0052     >;
0053 
0054     using iterator_t = typename Container::iterator;
0055     using container_ref_t = std::shared_ptr< Container >;
0056 
0057 public:
0058     shared_container_iterator() = default;
0059 
0060     shared_container_iterator(iterator_t const& x, container_ref_t const& c) :
0061         super_t(x),
0062         m_container_ref(c)
0063     {}
0064 
0065     // Constructor for backward compatibility with boost::shared_ptr
0066     shared_container_iterator(iterator_t const& x, boost::shared_ptr< Container > const& c) :
0067         super_t(x),
0068         m_container_ref(c.get(), detail::shared_container_iterator_bsptr_holder< Container >(c))
0069     {}
0070 
0071 private:
0072     container_ref_t m_container_ref;
0073 };
0074 
0075 template< typename Container >
0076 inline shared_container_iterator< Container >
0077 make_shared_container_iterator(typename Container::iterator iter, std::shared_ptr< Container > const& container)
0078 {
0079     return shared_container_iterator< Container >(iter, container);
0080 }
0081 
0082 template< typename Container >
0083 inline std::pair< shared_container_iterator< Container >, shared_container_iterator< Container > >
0084 make_shared_container_range(std::shared_ptr< Container > const& container)
0085 {
0086     return std::make_pair
0087     (
0088         iterators::make_shared_container_iterator(container->begin(), container),
0089         iterators::make_shared_container_iterator(container->end(), container)
0090     );
0091 }
0092 
0093 // Factory functions for backward compatibility with boost::shared_ptr
0094 template< typename Container >
0095 inline shared_container_iterator< Container >
0096 make_shared_container_iterator(typename Container::iterator iter, boost::shared_ptr< Container > const& container)
0097 {
0098     return shared_container_iterator< Container >(iter, container);
0099 }
0100 
0101 template< typename Container >
0102 inline std::pair< shared_container_iterator< Container >, shared_container_iterator< Container > >
0103 make_shared_container_range(boost::shared_ptr< Container > const& container)
0104 {
0105     std::shared_ptr< Container > c(container.get(), detail::shared_container_iterator_bsptr_holder< Container >(container));
0106     return iterators::make_shared_container_range(std::move(c));
0107 }
0108 
0109 } // namespace iterators
0110 
0111 using iterators::shared_container_iterator;
0112 using iterators::make_shared_container_iterator;
0113 using iterators::make_shared_container_range;
0114 
0115 } // namespace boost
0116 
0117 #endif // BOOST_ITERATOR_SHARED_CONTAINER_ITERATOR_HPP_INCLUDED_