doxygen_5.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. OBSOLETE
  2. // Boost.Geometry (aka GGL, Generic Geometry Library)
  3. //
  4. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  5. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Doxygen Examples, for Geometry Concepts
  11. #include <boost/geometry/geometry.hpp>
  12. #include <boost/geometry/geometries/register/point.hpp>
  13. #include <boost/geometry/geometries/register/linestring.hpp>
  14. #include <boost/geometry/geometries/geometries.hpp>
  15. struct legacy_point1
  16. {
  17. double x, y;
  18. };
  19. // adapt legacy_point1
  20. namespace boost { namespace geometry { namespace traits
  21. {
  22. template <> struct tag<legacy_point1> { typedef point_tag type; };
  23. template <> struct coordinate_type<legacy_point1> { typedef double type; };
  24. template <> struct coordinate_system<legacy_point1> { typedef cs::cartesian type; };
  25. template <> struct dimension<legacy_point1>: boost::mpl::int_<2> {};
  26. template <> struct access<legacy_point1, 0>
  27. {
  28. static double get(legacy_point1 const& p) { return p.x; }
  29. static void set(legacy_point1& p, double const& value) { p.x = value; }
  30. };
  31. template <> struct access<legacy_point1, 1>
  32. {
  33. static double get(legacy_point1 const& p) { return p.y; }
  34. static void set(legacy_point1& p, double const& value) { p.y = value; }
  35. };
  36. }}} // namespace boost::geometry::traits
  37. // end adaptation
  38. namespace example_legacy_point1
  39. {
  40. // The first way to check a concept at compile time: checking if the input is parameter
  41. // or return type is OK.
  42. template <typename P>
  43. BOOST_CONCEPT_REQUIRES(((boost::geometry::concepts::Point<P>)), (void))
  44. test1(P& p)
  45. {
  46. }
  47. // The second way to check a concept at compile time: checking if the provided type,
  48. // inside the function, if OK
  49. template <typename P>
  50. void test2(P& p)
  51. {
  52. BOOST_CONCEPT_ASSERT((boost::geometry::concepts::Point<P>));
  53. }
  54. void example()
  55. {
  56. legacy_point1 p;
  57. test1(p);
  58. test2(p);
  59. }
  60. }
  61. // leave comment below for (strange behaviour of) doxygen
  62. class legacy_point2
  63. {
  64. public :
  65. double x() const;
  66. double y() const;
  67. };
  68. // adapt legacy_point2
  69. BOOST_GEOMETRY_REGISTER_POINT_2D_CONST(legacy_point2, double, boost::geometry::cs::cartesian, x(), y() )
  70. // end adaptation
  71. double legacy_point2::x() const { return 0; }
  72. double legacy_point2::y() const { return 0; }
  73. namespace example_legacy_point2
  74. {
  75. // test it using boost concept requires
  76. template <typename P>
  77. BOOST_CONCEPT_REQUIRES(((boost::geometry::concepts::ConstPoint<P>)), (double))
  78. test3(P& p)
  79. {
  80. return boost::geometry::get<0>(p);
  81. }
  82. void example()
  83. {
  84. legacy_point2 p;
  85. test3(p);
  86. }
  87. }
  88. template <typename P>
  89. struct custom_linestring1 : std::deque<P>
  90. {
  91. int id;
  92. };
  93. // adapt custom_linestring1
  94. namespace boost { namespace geometry { namespace traits
  95. {
  96. template <typename P>
  97. struct tag< custom_linestring1<P> > { typedef linestring_tag type; };
  98. }}} // namespace boost::geometry::traits
  99. // end adaptation
  100. namespace example_custom_linestring1
  101. {
  102. void example()
  103. {
  104. typedef custom_linestring1<legacy_point1> L;
  105. BOOST_CONCEPT_ASSERT((boost::geometry::concepts::Linestring<L>));
  106. }
  107. }
  108. int main(void)
  109. {
  110. example_legacy_point1::example();
  111. example_legacy_point2::example();
  112. example_custom_linestring1::example();
  113. return 0;
  114. }