linestring_concept.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  3. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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_GEOMETRIES_CONCEPTS_LINESTRING_CONCEPT_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_LINESTRING_CONCEPT_HPP
  12. #include <boost/concept_check.hpp>
  13. #include <boost/range/concepts.hpp>
  14. #include <boost/type_traits/remove_const.hpp>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/mutable_range.hpp>
  17. #include <boost/geometry/core/point_type.hpp>
  18. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  19. namespace boost { namespace geometry { namespace concepts
  20. {
  21. /*!
  22. \brief Linestring concept
  23. \ingroup concepts
  24. \par Formal definition:
  25. The linestring concept is defined as following:
  26. - there must be a specialization of traits::tag defining linestring_tag as type
  27. - it must behave like a Boost.Range
  28. - it must implement a std::back_insert_iterator
  29. - either by implementing push_back
  30. - or by specializing std::back_insert_iterator
  31. \note to fulfill the concepts, no traits class has to be specialized to
  32. define the point type.
  33. \par Example:
  34. A custom linestring, defining the necessary specializations to fulfill to the concept.
  35. Suppose that the following linestring is defined:
  36. \dontinclude doxygen_5.cpp
  37. \skip custom_linestring1
  38. \until };
  39. It can then be adapted to the concept as following:
  40. \dontinclude doxygen_5.cpp
  41. \skip adapt custom_linestring1
  42. \until }}
  43. \note
  44. - There is also the registration macro BOOST_GEOMETRY_REGISTER_LINESTRING
  45. - For registration of std::vector<P> (and deque, and list) it is enough to
  46. include the header-file geometries/adapted/std_as_linestring.hpp. That registers
  47. a vector as a linestring (so it cannot be registered as a linear ring then,
  48. in the same source code).
  49. */
  50. template <typename Geometry>
  51. class Linestring
  52. {
  53. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  54. typedef typename point_type<Geometry>::type point_type;
  55. BOOST_CONCEPT_ASSERT( (concepts::Point<point_type>) );
  56. BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept<Geometry>) );
  57. public :
  58. BOOST_CONCEPT_USAGE(Linestring)
  59. {
  60. Geometry* ls = 0;
  61. traits::clear<Geometry>::apply(*ls);
  62. traits::resize<Geometry>::apply(*ls, 0);
  63. point_type* point = 0;
  64. traits::push_back<Geometry>::apply(*ls, *point);
  65. }
  66. #endif
  67. };
  68. /*!
  69. \brief Linestring concept (const version)
  70. \ingroup const_concepts
  71. \details The ConstLinestring concept check the same as the Linestring concept,
  72. but does not check write access.
  73. */
  74. template <typename Geometry>
  75. class ConstLinestring
  76. {
  77. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  78. typedef typename point_type<Geometry>::type point_type;
  79. BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<point_type>) );
  80. //BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept<Geometry>) );
  81. // Relaxed the concept.
  82. BOOST_CONCEPT_ASSERT( (boost::ForwardRangeConcept<Geometry>) );
  83. public :
  84. BOOST_CONCEPT_USAGE(ConstLinestring)
  85. {
  86. }
  87. #endif
  88. };
  89. }}} // namespace boost::geometry::concepts
  90. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_LINESTRING_CONCEPT_HPP