~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to include/ggl/core/concepts/point_concept.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Generic Geometry Library Point concept
 
2
//
 
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)
 
8
 
 
9
#ifndef GGL_CORE_CONCEPTS_POINT_CONCEPT_HPP
 
10
#define GGL_CORE_CONCEPTS_POINT_CONCEPT_HPP
 
11
 
 
12
#include <cstddef>
 
13
 
 
14
#include <boost/concept_check.hpp>
 
15
 
 
16
#include <ggl/core/access.hpp>
 
17
#include <ggl/core/coordinate_dimension.hpp>
 
18
#include <ggl/core/coordinate_system.hpp>
 
19
 
 
20
 
 
21
/*!
 
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)
 
25
*/
 
26
 
 
27
namespace ggl { namespace concept {
 
28
 
 
29
/*!
 
30
    \brief Checks point concept, using Boost Concept Check Library and metafunctions
 
31
    \ingroup concepts
 
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
 
37
 
 
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
 
43
    metafunction.
 
44
 
 
45
    \par Example:
 
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
 
49
    \skip example_point_1
 
50
    \until //:\\
 
51
    \par Example:
 
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
 
56
    \line {
 
57
    \until //:\\
 
58
*/
 
59
 
 
60
template <typename X>
 
61
struct Point
 
62
{
 
63
private:
 
64
 
 
65
    typedef typename coordinate_type<X>::type ctype;
 
66
    typedef typename coordinate_system<X>::type csystem;
 
67
 
 
68
    enum { ccount = dimension<X>::value };
 
69
 
 
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
 
73
    {
 
74
        static void check()
 
75
        {
 
76
            P* p;
 
77
            ggl::set<I>(*p, ggl::get<I>(*p));
 
78
            dimension_checker<P, I+1, Count>::check();
 
79
        }
 
80
    };
 
81
 
 
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>
 
85
    {
 
86
        static void check() {}
 
87
    };
 
88
 
 
89
public:
 
90
 
 
91
    /// BCCL macro to check the Point concept
 
92
    BOOST_CONCEPT_USAGE(Point)
 
93
    {
 
94
        dimension_checker<X, 0, ccount>::check();
 
95
    }
 
96
};
 
97
 
 
98
 
 
99
/*!
 
100
    \brief Checks point concept (const version)
 
101
    \ingroup concepts
 
102
    \details The ConstPoint concept check the same as the Point concept,
 
103
    but does not check write access.
 
104
*/
 
105
template <typename X>
 
106
struct ConstPoint
 
107
{
 
108
private:
 
109
 
 
110
    typedef typename coordinate_type<X>::type ctype;
 
111
    typedef typename coordinate_system<X>::type csystem;
 
112
 
 
113
    enum { ccount = dimension<X>::value };
 
114
 
 
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
 
118
    {
 
119
        static void check()
 
120
        {
 
121
            const P* p = 0;
 
122
            ctype coord(ggl::get<I>(*p));
 
123
            boost::ignore_unused_variable_warning(coord);
 
124
            dimension_checker<P, I+1, Count>::check();
 
125
        }
 
126
    };
 
127
 
 
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>
 
131
    {
 
132
        static void check() {}
 
133
    };
 
134
 
 
135
public:
 
136
 
 
137
    /// BCCL macro to check the ConstPoint concept
 
138
    BOOST_CONCEPT_USAGE(ConstPoint)
 
139
    {
 
140
        dimension_checker<X, 0, ccount>::check();
 
141
    }
 
142
};
 
143
 
 
144
}} // namespace ggl::concept
 
145
 
 
146
#endif // GGL_CORE_CONCEPTS_POINT_CONCEPT_HPP