inserter.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Boost.Geometry Index
  2. //
  3. // Insert iterator
  4. //
  5. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_INDEX_INSERTER_HPP
  11. #define BOOST_GEOMETRY_INDEX_INSERTER_HPP
  12. #include <iterator>
  13. /*!
  14. \defgroup inserters Inserters (boost::geometry::index::)
  15. */
  16. namespace boost { namespace geometry { namespace index {
  17. template <class Container>
  18. class insert_iterator
  19. {
  20. public:
  21. typedef std::output_iterator_tag iterator_category;
  22. typedef void value_type;
  23. typedef void difference_type;
  24. typedef void pointer;
  25. typedef void reference;
  26. typedef Container container_type;
  27. inline explicit insert_iterator(Container & c)
  28. : container(&c)
  29. {}
  30. insert_iterator & operator=(typename Container::value_type const& value)
  31. {
  32. container->insert(value);
  33. return *this;
  34. }
  35. insert_iterator & operator* ()
  36. {
  37. return *this;
  38. }
  39. insert_iterator & operator++ ()
  40. {
  41. return *this;
  42. }
  43. insert_iterator operator++(int)
  44. {
  45. return *this;
  46. }
  47. private:
  48. Container * container;
  49. };
  50. /*!
  51. \brief Insert iterator generator.
  52. Returns insert iterator capable to insert values to the container
  53. (spatial index) which has member function insert(value_type const&) defined.
  54. \ingroup inserters
  55. \param c The reference to the container (spatial index) to which values will be inserted.
  56. \return The insert iterator inserting values to the container.
  57. */
  58. template <typename Container>
  59. insert_iterator<Container> inserter(Container & c)
  60. {
  61. return insert_iterator<Container>(c);
  62. }
  63. }}} // namespace boost::geometry::index
  64. #endif // BOOST_GEOMETRY_INDEX_INSERTER_HPP