1
// Generic Geometry Library
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_ACCESS_HPP
10
#define GGL_CORE_ACCESS_HPP
14
#include <boost/type_traits/remove_const.hpp>
15
#include <boost/concept_check.hpp>
17
#include <ggl/core/coordinate_type.hpp>
18
#include <ggl/core/point_type.hpp>
19
#include <ggl/core/tag.hpp>
24
const int min_corner = 0;
25
const int max_corner = 1;
31
\brief Traits class which gives access (get,set) to points
35
- n-sphere (circle,sphere) for their center
36
\par Specializations should provide:
37
- static inline T get<I>(const G&)
38
- static inline void set<I>(G&, const T&)
46
\brief Traits class defining "get" and "set" to get and set point coordinate values
47
\tparam G geometry (box, segment)
48
\tparam I index (min_corner/max_corner for box, 0/1 for segment)
53
\par Specializations should provide:
54
- static inline T get(const G&)
55
- static inline void set(G&, const T&)
58
template <typename G, std::size_t I, std::size_t D>
59
struct indexed_access {};
63
\brief Traits class, optional, indicating that the std-library should be used
64
\details The default geometry (linestring, ring, multi*) follow std:: for
65
its modifying operations (push_back, clear, size, resize, reserve, etc)
66
If they NOT follow the std:: library they should specialize this traits
72
\par Specializations should provide:
73
- value (defaults to true)
78
static const bool value = true;
84
#ifndef DOXYGEN_NO_DISPATCH
85
namespace core_dispatch
87
template <typename Tag, typename G, typename T, std::size_t D>
90
//static inline T get(const G& ) {}
91
//static inline void set(G& g, const T& value) {}
94
template <typename Tag, typename G, typename T, std::size_t I, std::size_t D>
97
//static inline T get(const G& ) {}
98
//static inline void set(G& g, const T& value) {}
101
template <typename P, typename T, std::size_t D>
102
struct access<point_tag, P, T, D>
104
static inline T get(const P& p)
106
return traits::access<P>::template get<D>(p);
108
static inline void set(P& p, const T& value)
110
traits::access<P>::template set<D>(p, value);
114
template <typename S, typename T, std::size_t D>
115
struct access<nsphere_tag, S, T, D>
117
static inline T get(const S& s)
119
return traits::access<S>::template get<D>(s);
121
static inline void set(S& s, const T& value)
123
traits::access<S>::template set<D>(s, value);
127
template <typename B, typename T, std::size_t I, std::size_t D>
128
struct indexed_access<box_tag, B, T, I, D>
130
static inline T get(const B& b)
132
return traits::indexed_access<B, I, D>::get(b);
134
static inline void set(B& b, const T& value)
136
traits::indexed_access<B, I, D>::set(b, value);
140
template <typename S, typename T, std::size_t I, std::size_t D>
141
struct indexed_access<segment_tag, S, T, I, D>
143
static inline T get(const S& segment)
145
return traits::indexed_access<S, I, D>::get(segment);
147
static inline void set(S& segment, const T& value)
149
traits::indexed_access<S, I, D>::set(segment, value);
153
} // namespace core_dispatch
154
#endif // DOXYGEN_NO_DISPATCH
157
#ifndef DOXYGEN_NO_DETAIL
161
// Two dummy tags to distinguish get/set variants below.
162
// They don't have to be specified by the user. The functions are distinguished
163
// by template signature also, but for e.g. GCC this is not enough. So give them
164
// a different signature.
165
struct signature_getset_dimension {};
166
struct signature_getset_index_dimension {};
168
} // namespace detail
169
#endif // DOXYGEN_NO_DETAIL
173
\brief get a coordinate value of a point / nsphere
174
\return coordinate value
178
\param geometry geometry to get coordinate value from
179
\param dummy does not have to be specified
181
template <std::size_t D, typename G>
182
inline typename coordinate_type<G>::type get(const G& geometry,
183
detail::signature_getset_dimension* dummy = 0)
185
boost::ignore_unused_variable_warning(dummy);
187
typedef typename boost::remove_const<G>::type ncg_type;
189
typedef core_dispatch::access
191
typename tag<G>::type,
193
typename coordinate_type<ncg_type>::type,
197
return coord_access_type::get(geometry);
202
\brief assign coordinate value to a point / sphere
206
\param geometry geometry to assign coordinate to
207
\param value coordinate value to assign
208
\param dummy does not have to be specified
210
template <std::size_t D, typename G>
211
inline void set(G& geometry, const typename coordinate_type<G>::type& value,
212
detail::signature_getset_dimension* dummy = 0)
214
boost::ignore_unused_variable_warning(dummy);
216
typedef typename boost::remove_const<G>::type ncg_type;
218
typedef core_dispatch::access
220
typename tag<G>::type,
222
typename coordinate_type<ncg_type>::type,
226
coord_access_type::set(geometry, value);
229
// Note: doxygen needs a construct to distinguish get/set (like the gcc compiler)
232
\brief get a coordinate value of a box / segment
233
\return coordinate value
235
\tparam I index, for boxes: min_corner or max_corner. For segment: 0 / 1
238
\param geometry geometry to get coordinate value from
239
\param dummy does not have to be specified
241
template <std::size_t I, std::size_t D, typename G>
242
inline typename coordinate_type<G>::type get(const G& geometry,
243
detail::signature_getset_index_dimension* dummy = 0)
245
boost::ignore_unused_variable_warning(dummy);
247
typedef typename boost::remove_const<G>::type ncg_type;
249
typedef core_dispatch::indexed_access
251
typename tag<G>::type,
253
typename coordinate_type<ncg_type>::type,
258
return coord_access_type::get(geometry);
262
\brief assign a coordinate value of a box / segment
264
\tparam I index, for boxes: min_corner or max_corner. For segment: 0 / 1
267
\param geometry geometry to assign coordinate to
268
\param value coordinate value to assign
269
\param dummy does not have to be specified
271
template <std::size_t I, std::size_t D, typename G>
272
inline void set(G& geometry, const typename coordinate_type<G>::type& value,
273
detail::signature_getset_index_dimension* dummy = 0)
275
boost::ignore_unused_variable_warning(dummy);
277
typedef typename boost::remove_const<G>::type ncg_type;
279
typedef core_dispatch::indexed_access
281
typename tag<G>::type, ncg_type,
282
typename coordinate_type<ncg_type>::type,
287
coord_access_type::set(geometry, value);
292
#endif // GGL_CORE_ACCESS_HPP