Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / concepts / point.hpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #ifndef BOOST_GIL_CONCEPTS_POINT_HPP
9 #define BOOST_GIL_CONCEPTS_POINT_HPP
10
11 #include <boost/gil/concepts/basic.hpp>
12 #include <boost/gil/concepts/concept_check.hpp>
13
14 #include <cstddef>
15
16 #if defined(BOOST_CLANG)
17 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
19 #endif
20
21 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
22 #pragma GCC diagnostic push
23 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
24 #endif
25
26 namespace boost { namespace gil {
27
28 // Forward declarations
29 template <typename T>
30 class point;
31
32 template <std::size_t K, typename T>
33 T const& axis_value(point<T> const& p);
34
35 template <std::size_t K, typename T>
36 T& axis_value(point<T>& p);
37
38 /// \brief N-dimensional point concept
39 /// \code
40 /// concept PointNDConcept<typename T> : Regular<T>
41 /// {
42 ///     // the type of a coordinate along each axis
43 ///     template <size_t K>
44 ///     struct axis; where Metafunction<axis>;
45 ///
46 ///     const size_t num_dimensions;
47 ///
48 ///     // accessor/modifier of the value of each axis.
49 ///
50 ///     template <size_t K>
51 ///     typename axis<K>::type const& T::axis_value() const;
52 ///
53 ///     template <size_t K>
54 ///     typename axis<K>::type& T::axis_value();
55 /// };
56 /// \endcode
57 /// \ingroup PointConcept
58 ///
59 template <typename P>
60 struct PointNDConcept
61 {
62     void constraints()
63     {
64         gil_function_requires<Regular<P>>();
65
66         using value_type = typename P::value_type;
67         ignore_unused_variable_warning(value_type{});
68
69         static const std::size_t N = P::num_dimensions;
70         ignore_unused_variable_warning(N);
71         using FT = typename P::template axis<0>::coord_t;
72         using LT = typename P::template axis<N - 1>::coord_t;
73         FT ft = gil::axis_value<0>(point);
74         axis_value<0>(point) = ft;
75         LT lt = axis_value<N - 1>(point);
76         axis_value<N - 1>(point) = lt;
77
78         //value_type v=point[0];
79         //ignore_unused_variable_warning(v);
80     }
81     P point;
82 };
83
84 /// \brief 2-dimensional point concept
85 /// \code
86 /// concept Point2DConcept<typename T> : PointNDConcept<T>
87 /// {
88 ///     where num_dimensions == 2;
89 ///     where SameType<axis<0>::type, axis<1>::type>;
90 ///
91 ///     typename value_type = axis<0>::type;
92 ///
93 ///     value_type const& operator[](T const&, size_t i);
94 ///     value_type& operator[](T&, size_t i);
95 ///
96 ///     value_type x,y;
97 /// };
98 /// \endcode
99 /// \ingroup PointConcept
100 ///
101 template <typename P>
102 struct Point2DConcept
103 {
104     void constraints()
105     {
106         gil_function_requires<PointNDConcept<P>>();
107         static_assert(P::num_dimensions == 2, "");
108         point.x = point.y;
109         point[0] = point[1];
110     }
111     P point;
112 };
113
114 }} // namespace boost::gil
115
116 #if defined(BOOST_CLANG)
117 #pragma clang diagnostic pop
118 #endif
119
120 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
121 #pragma GCC diagnostic pop
122 #endif
123
124 #endif