1
// Generic Geometry Library Point concept
3
// Copyright Bruno Lalande 2008, 2009
4
// Copyright Barend Gehrels 1995-2009, Geodan Holding B.V. Amsterdam, the Netherlands.
5
// Use, modification and distribution is subject to the Boost Software License,
6
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7
// http://www.boost.org/LICENSE_1_0.txt)
9
#ifndef GGL_CORE_CONCEPTS_POINT_CONCEPT_HPP
10
#define GGL_CORE_CONCEPTS_POINT_CONCEPT_HPP
14
#include <boost/concept_check.hpp>
16
#include <ggl/core/access.hpp>
17
#include <ggl/core/coordinate_dimension.hpp>
18
#include <ggl/core/coordinate_system.hpp>
22
\defgroup concepts concept checking
23
Concepts are used to check if pointtypes provide required implementation. Concept checking
24
is done using BCCL (Boost Concept Check Library) and MPL (Meta Programming Library)
27
namespace ggl { namespace concept {
30
\brief Checks point concept, using Boost Concept Check Library and metafunctions
32
\details The concept is separated into 4 metafunctions:
33
- \ref ggl::traits::coordinate_type "coordinate_type": provides the type of the coordinates of a point
34
- \ref ggl::traits::coordinate_system "coordinate system": provides the coordinate system in which the point is placed
35
- \ref ggl::traits::dimension "dimension": provides the number of coordinates of a point
36
- \ref ggl::traits::access "access": provides access to the coordinates of a point
38
In MPL, a metafunction that provides a type must expose is as "type"
39
and a metafunction that provides a value must expose it as "value", so
40
here the same convention are used: coordinate_type<P>::type and
41
dimension<P>::value provide the type and number of coordinates. This
42
makes them compatible with any MPL and Fusion algorithm and
46
First example, using an own pointtype, for example a legacy point, defining the necessary
47
properties outside the pointtype in a traits class
48
\dontinclude doxygen_examples.cpp
52
Second example, deriving a pointtype from boost::tuple. It defines the necessary properties
53
itself, so a separate traits class is not necessary.
54
\dontinclude doxygen_examples.cpp
55
\skip example_own_point2
65
typedef typename coordinate_type<X>::type ctype;
66
typedef typename coordinate_system<X>::type csystem;
68
enum { ccount = dimension<X>::value };
70
/// Internal structure to check if access is OK for all dimensions
71
template <typename P, std::size_t I, std::size_t Count>
72
struct dimension_checker
77
ggl::set<I>(*p, ggl::get<I>(*p));
78
dimension_checker<P, I+1, Count>::check();
82
/// Internal structure to check if access is OK for all dimensions
83
template <typename P, std::size_t Count>
84
struct dimension_checker<P, Count, Count>
86
static void check() {}
91
/// BCCL macro to check the Point concept
92
BOOST_CONCEPT_USAGE(Point)
94
dimension_checker<X, 0, ccount>::check();
100
\brief Checks point concept (const version)
102
\details The ConstPoint concept check the same as the Point concept,
103
but does not check write access.
105
template <typename X>
110
typedef typename coordinate_type<X>::type ctype;
111
typedef typename coordinate_system<X>::type csystem;
113
enum { ccount = dimension<X>::value };
115
/// Internal structure to check if access is OK for all dimensions
116
template <typename P, std::size_t I, std::size_t Count>
117
struct dimension_checker
122
ctype coord(ggl::get<I>(*p));
123
boost::ignore_unused_variable_warning(coord);
124
dimension_checker<P, I+1, Count>::check();
128
/// Internal structure to check if access is OK for all dimensions
129
template <typename P, std::size_t Count>
130
struct dimension_checker<P, Count, Count>
132
static void check() {}
137
/// BCCL macro to check the ConstPoint concept
138
BOOST_CONCEPT_USAGE(ConstPoint)
140
dimension_checker<X, 0, ccount>::check();
144
}} // namespace ggl::concept
146
#endif // GGL_CORE_CONCEPTS_POINT_CONCEPT_HPP