1 OBSOLETE
2
3 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 //
5 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
6 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
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 //
11 // Doxygen Examples, for Geometry Concepts
12
13 #include <boost/geometry/geometry.hpp>
14 #include <boost/geometry/geometries/register/point.hpp>
15 #include <boost/geometry/geometries/register/linestring.hpp>
16 #include <boost/geometry/geometries/geometries.hpp>
17
18
19
20 struct legacy_point1
21 {
22 double x, y;
23 };
24
25 // adapt legacy_point1
26 namespace boost { namespace geometry { namespace traits
27 {
28 template <> struct tag<legacy_point1> { typedef point_tag type; };
29 template <> struct coordinate_type<legacy_point1> { typedef double type; };
30 template <> struct coordinate_system<legacy_point1> { typedef cs::cartesian type; };
31 template <> struct dimension<legacy_point1>: boost::mpl::int_<2> {};
32 template <> struct access<legacy_point1, 0>
33 {
getboost::geometry::traits::access34 static double get(legacy_point1 const& p) { return p.x; }
setboost::geometry::traits::access35 static void set(legacy_point1& p, double const& value) { p.x = value; }
36 };
37 template <> struct access<legacy_point1, 1>
38 {
getboost::geometry::traits::access39 static double get(legacy_point1 const& p) { return p.y; }
setboost::geometry::traits::access40 static void set(legacy_point1& p, double const& value) { p.y = value; }
41 };
42 }}} // namespace boost::geometry::traits
43 // end adaptation
44
45 namespace example_legacy_point1
46 {
47 // The first way to check a concept at compile time: checking if the input is parameter
48 // or return type is OK.
49 template <typename P>
50 BOOST_CONCEPT_REQUIRES(((boost::geometry::concepts::Point<P>)), (void))
test1(P & p)51 test1(P& p)
52 {
53 }
54
55 // The second way to check a concept at compile time: checking if the provided type,
56 // inside the function, if OK
57 template <typename P>
test2(P & p)58 void test2(P& p)
59 {
60 BOOST_CONCEPT_ASSERT((boost::geometry::concepts::Point<P>));
61 }
62
63
example()64 void example()
65 {
66 legacy_point1 p;
67 test1(p);
68 test2(p);
69 }
70 }
71
72 // leave comment below for (strange behaviour of) doxygen
73 class legacy_point2
74 {
75 public :
76 double x() const;
77 double y() const;
78 };
79
80 // adapt legacy_point2
BOOST_GEOMETRY_REGISTER_POINT_2D_CONST(legacy_point2,double,boost::geometry::cs::cartesian,x (),y ())81 BOOST_GEOMETRY_REGISTER_POINT_2D_CONST(legacy_point2, double, boost::geometry::cs::cartesian, x(), y() )
82 // end adaptation
83
84
85 double legacy_point2::x() const { return 0; }
y() const86 double legacy_point2::y() const { return 0; }
87
88 namespace example_legacy_point2
89 {
90 // test it using boost concept requires
91
92 template <typename P>
93 BOOST_CONCEPT_REQUIRES(((boost::geometry::concepts::ConstPoint<P>)), (double))
test3(P & p)94 test3(P& p)
95 {
96 return boost::geometry::get<0>(p);
97 }
98
example()99 void example()
100 {
101 legacy_point2 p;
102 test3(p);
103 }
104 }
105
106
107 template <typename P>
108 struct custom_linestring1 : std::deque<P>
109 {
110 int id;
111 };
112
113 // adapt custom_linestring1
114 namespace boost { namespace geometry { namespace traits
115 {
116 template <typename P>
117 struct tag< custom_linestring1<P> > { typedef linestring_tag type; };
118 }}} // namespace boost::geometry::traits
119 // end adaptation
120
121 namespace example_custom_linestring1
122 {
example()123 void example()
124 {
125 typedef custom_linestring1<legacy_point1> L;
126 BOOST_CONCEPT_ASSERT((boost::geometry::concepts::Linestring<L>));
127
128 }
129 }
130
main(void)131 int main(void)
132 {
133 example_legacy_point1::example();
134 example_legacy_point2::example();
135 example_custom_linestring1::example();
136
137 return 0;
138 }
139