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