1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
6 // This file was modified by Oracle on 2013-2019.
7 // Modifications copyright (c) 2013-2019 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
15 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_RESULT_HPP
16 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_RESULT_HPP
21 #include <boost/mpl/assert.hpp>
22 #include <boost/mpl/at.hpp>
23 #include <boost/mpl/begin.hpp>
24 #include <boost/mpl/deref.hpp>
25 #include <boost/mpl/end.hpp>
26 #include <boost/mpl/is_sequence.hpp>
27 #include <boost/mpl/next.hpp>
28 #include <boost/mpl/size.hpp>
29 #include <boost/static_assert.hpp>
30 #include <boost/throw_exception.hpp>
31 #include <boost/tuple/tuple.hpp>
32 #include <boost/type_traits/integral_constant.hpp>
34 #include <boost/geometry/core/assert.hpp>
35 #include <boost/geometry/core/coordinate_dimension.hpp>
36 #include <boost/geometry/core/exception.hpp>
37 #include <boost/geometry/util/condition.hpp>
39 namespace boost { namespace geometry {
41 #ifndef DOXYGEN_NO_DETAIL
42 namespace detail { namespace relate {
44 enum field { interior = 0, boundary = 1, exterior = 2 };
46 // TODO: IF THE RESULT IS UPDATED WITH THE MAX POSSIBLE VALUE FOR SOME PAIR OF GEOEMTRIES
47 // THE VALUE ALREADY STORED MUSN'T BE CHECKED
48 // update() calls chould be replaced with set() in those cases
49 // but for safety reasons (STATIC_ASSERT) we should check if parameter D is valid and set() doesn't do that
50 // so some additional function could be added, e.g. set_dim()
52 // --------------- MATRIX ----------------
56 template <std::size_t Height, std::size_t Width = Height>
60 typedef char value_type;
61 typedef std::size_t size_type;
62 typedef const char * const_iterator;
63 typedef const_iterator iterator;
65 static const std::size_t static_width = Width;
66 static const std::size_t static_height = Height;
67 static const std::size_t static_size = Width * Height;
71 ::memset(m_array, 'F', static_size);
74 template <field F1, field F2>
75 inline char get() const
77 BOOST_STATIC_ASSERT(F1 < Height && F2 < Width);
78 static const std::size_t index = F1 * Width + F2;
79 BOOST_STATIC_ASSERT(index < static_size);
80 return m_array[index];
83 template <field F1, field F2, char V>
86 BOOST_STATIC_ASSERT(F1 < Height && F2 < Width);
87 static const std::size_t index = F1 * Width + F2;
88 BOOST_STATIC_ASSERT(index < static_size);
92 inline char operator[](std::size_t index) const
94 BOOST_GEOMETRY_ASSERT(index < static_size);
95 return m_array[index];
98 inline const_iterator begin() const
103 inline const_iterator end() const
105 return m_array + static_size;
108 inline static std::size_t size()
113 inline const char * data() const
118 inline std::string str() const
120 return std::string(m_array, static_size);
124 char m_array[static_size];
129 template <typename Matrix>
133 typedef Matrix result_type;
135 static const bool interrupt = false;
140 result_type const& result() const
145 result_type const& matrix() const
150 result_type & matrix()
155 template <field F1, field F2, char D>
156 inline bool may_update() const
158 BOOST_STATIC_ASSERT('0' <= D && D <= '9');
160 char const c = m_matrix.template get<F1, F2>();
161 return D > c || c > '9';
164 template <field F1, field F2, char V>
167 static const bool in_bounds = F1 < Matrix::static_height
168 && F2 < Matrix::static_width;
169 typedef boost::integral_constant<bool, in_bounds> in_bounds_t;
170 set_dispatch<F1, F2, V>(in_bounds_t());
173 template <field F1, field F2, char D>
176 static const bool in_bounds = F1 < Matrix::static_height
177 && F2 < Matrix::static_width;
178 typedef boost::integral_constant<bool, in_bounds> in_bounds_t;
179 update_dispatch<F1, F2, D>(in_bounds_t());
183 template <field F1, field F2, char V>
184 inline void set_dispatch(integral_constant<bool, true>)
186 static const std::size_t index = F1 * Matrix::static_width + F2;
187 BOOST_STATIC_ASSERT(index < Matrix::static_size);
188 BOOST_STATIC_ASSERT(('0' <= V && V <= '9') || V == 'T' || V == 'F');
189 m_matrix.template set<F1, F2, V>();
191 template <field F1, field F2, char V>
192 inline void set_dispatch(integral_constant<bool, false>)
195 template <field F1, field F2, char D>
196 inline void update_dispatch(integral_constant<bool, true>)
198 static const std::size_t index = F1 * Matrix::static_width + F2;
199 BOOST_STATIC_ASSERT(index < Matrix::static_size);
200 BOOST_STATIC_ASSERT('0' <= D && D <= '9');
201 char const c = m_matrix.template get<F1, F2>();
202 if ( D > c || c > '9')
203 m_matrix.template set<F1, F2, D>();
205 template <field F1, field F2, char D>
206 inline void update_dispatch(integral_constant<bool, false>)
212 // --------------- RUN-TIME MASK ----------------
216 template <std::size_t Height, std::size_t Width = Height>
220 static const std::size_t static_width = Width;
221 static const std::size_t static_height = Height;
222 static const std::size_t static_size = Width * Height;
224 inline mask(const char * s)
227 char * const last = m_array + static_size;
228 for ( ; it != last && *s != '\0' ; ++it, ++s )
236 ::memset(it, '*', last - it);
240 inline mask(const char * s, std::size_t count)
242 if ( count > static_size )
248 std::for_each(s, s + count, check_char);
249 ::memcpy(m_array, s, count);
251 if ( count < static_size )
253 ::memset(m_array + count, '*', static_size - count);
257 template <field F1, field F2>
258 inline char get() const
260 BOOST_STATIC_ASSERT(F1 < Height && F2 < Width);
261 static const std::size_t index = F1 * Width + F2;
262 BOOST_STATIC_ASSERT(index < static_size);
263 return m_array[index];
267 static inline void check_char(char c)
269 bool const is_valid = c == '*' || c == 'T' || c == 'F'
270 || ( c >= '0' && c <= '9' );
273 BOOST_THROW_EXCEPTION(geometry::invalid_input_exception());
277 char m_array[static_size];
282 template <typename Mask, bool InterruptEnabled>
283 struct interrupt_dispatch
285 template <field F1, field F2, char V>
286 static inline bool apply(Mask const&)
292 template <typename Mask>
293 struct interrupt_dispatch<Mask, true>
295 template <field F1, field F2, char V>
296 static inline bool apply(Mask const& mask)
298 char m = mask.template get<F1, F2>();
299 return check_element<V>(m);
303 static inline bool check_element(char m)
305 if ( BOOST_GEOMETRY_CONDITION(V >= '0' && V <= '9') )
307 return m == 'F' || ( m < V && m >= '0' && m <= '9' );
309 else if ( BOOST_GEOMETRY_CONDITION(V == 'T') )
317 template <typename Masks, int I = 0, int N = boost::tuples::length<Masks>::value>
318 struct interrupt_dispatch_tuple
320 template <field F1, field F2, char V>
321 static inline bool apply(Masks const& masks)
323 typedef typename boost::tuples::element<I, Masks>::type mask_type;
324 mask_type const& mask = boost::get<I>(masks);
325 return interrupt_dispatch<mask_type, true>::template apply<F1, F2, V>(mask)
326 && interrupt_dispatch_tuple<Masks, I+1>::template apply<F1, F2, V>(masks);
330 template <typename Masks, int N>
331 struct interrupt_dispatch_tuple<Masks, N, N>
333 template <field F1, field F2, char V>
334 static inline bool apply(Masks const& )
340 //template <typename T0, typename T1, typename T2, typename T3, typename T4,
341 // typename T5, typename T6, typename T7, typename T8, typename T9>
342 //struct interrupt_dispatch<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, true>
344 // typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> mask_type;
346 // template <field F1, field F2, char V>
347 // static inline bool apply(mask_type const& mask)
349 // return interrupt_dispatch_tuple<mask_type>::template apply<F1, F2, V>(mask);
353 template <typename Head, typename Tail>
354 struct interrupt_dispatch<boost::tuples::cons<Head, Tail>, true>
356 typedef boost::tuples::cons<Head, Tail> mask_type;
358 template <field F1, field F2, char V>
359 static inline bool apply(mask_type const& mask)
361 return interrupt_dispatch_tuple<mask_type>::template apply<F1, F2, V>(mask);
365 template <field F1, field F2, char V, bool InterruptEnabled, typename Mask>
366 inline bool interrupt(Mask const& mask)
368 return interrupt_dispatch<Mask, InterruptEnabled>
369 ::template apply<F1, F2, V>(mask);
374 template <typename Mask>
375 struct may_update_dispatch
377 template <field F1, field F2, char D, typename Matrix>
378 static inline bool apply(Mask const& mask, Matrix const& matrix)
380 BOOST_STATIC_ASSERT('0' <= D && D <= '9');
382 char const m = mask.template get<F1, F2>();
390 char const c = matrix.template get<F1, F2>();
391 return c == 'F'; // if it's T or between 0 and 9, the result will be the same
393 else if ( m >= '0' && m <= '9' )
395 char const c = matrix.template get<F1, F2>();
396 return D > c || c > '9';
403 template <typename Masks, int I = 0, int N = boost::tuples::length<Masks>::value>
404 struct may_update_dispatch_tuple
406 template <field F1, field F2, char D, typename Matrix>
407 static inline bool apply(Masks const& masks, Matrix const& matrix)
409 typedef typename boost::tuples::element<I, Masks>::type mask_type;
410 mask_type const& mask = boost::get<I>(masks);
411 return may_update_dispatch<mask_type>::template apply<F1, F2, D>(mask, matrix)
412 || may_update_dispatch_tuple<Masks, I+1>::template apply<F1, F2, D>(masks, matrix);
416 template <typename Masks, int N>
417 struct may_update_dispatch_tuple<Masks, N, N>
419 template <field F1, field F2, char D, typename Matrix>
420 static inline bool apply(Masks const& , Matrix const& )
426 //template <typename T0, typename T1, typename T2, typename T3, typename T4,
427 // typename T5, typename T6, typename T7, typename T8, typename T9>
428 //struct may_update_dispatch< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
430 // typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> mask_type;
432 // template <field F1, field F2, char D, typename Matrix>
433 // static inline bool apply(mask_type const& mask, Matrix const& matrix)
435 // return may_update_dispatch_tuple<mask_type>::template apply<F1, F2, D>(mask, matrix);
439 template <typename Head, typename Tail>
440 struct may_update_dispatch< boost::tuples::cons<Head, Tail> >
442 typedef boost::tuples::cons<Head, Tail> mask_type;
444 template <field F1, field F2, char D, typename Matrix>
445 static inline bool apply(mask_type const& mask, Matrix const& matrix)
447 return may_update_dispatch_tuple<mask_type>::template apply<F1, F2, D>(mask, matrix);
451 template <field F1, field F2, char D, typename Mask, typename Matrix>
452 inline bool may_update(Mask const& mask, Matrix const& matrix)
454 return may_update_dispatch<Mask>
455 ::template apply<F1, F2, D>(mask, matrix);
460 template <typename Mask>
461 struct check_dispatch
463 template <typename Matrix>
464 static inline bool apply(Mask const& mask, Matrix const& matrix)
466 return per_one<interior, interior>(mask, matrix)
467 && per_one<interior, boundary>(mask, matrix)
468 && per_one<interior, exterior>(mask, matrix)
469 && per_one<boundary, interior>(mask, matrix)
470 && per_one<boundary, boundary>(mask, matrix)
471 && per_one<boundary, exterior>(mask, matrix)
472 && per_one<exterior, interior>(mask, matrix)
473 && per_one<exterior, boundary>(mask, matrix)
474 && per_one<exterior, exterior>(mask, matrix);
477 template <field F1, field F2, typename Matrix>
478 static inline bool per_one(Mask const& mask, Matrix const& matrix)
480 const char mask_el = mask.template get<F1, F2>();
481 const char el = matrix.template get<F1, F2>();
483 if ( mask_el == 'F' )
487 else if ( mask_el == 'T' )
489 return el == 'T' || ( el >= '0' && el <= '9' );
491 else if ( mask_el >= '0' && mask_el <= '9' )
493 return el == mask_el;
500 template <typename Masks, int I = 0, int N = boost::tuples::length<Masks>::value>
501 struct check_dispatch_tuple
503 template <typename Matrix>
504 static inline bool apply(Masks const& masks, Matrix const& matrix)
506 typedef typename boost::tuples::element<I, Masks>::type mask_type;
507 mask_type const& mask = boost::get<I>(masks);
508 return check_dispatch<mask_type>::apply(mask, matrix)
509 || check_dispatch_tuple<Masks, I+1>::apply(masks, matrix);
513 template <typename Masks, int N>
514 struct check_dispatch_tuple<Masks, N, N>
516 template <typename Matrix>
517 static inline bool apply(Masks const&, Matrix const&)
523 //template <typename T0, typename T1, typename T2, typename T3, typename T4,
524 // typename T5, typename T6, typename T7, typename T8, typename T9>
525 //struct check_dispatch< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
527 // typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> mask_type;
529 // template <typename Matrix>
530 // static inline bool apply(mask_type const& mask, Matrix const& matrix)
532 // return check_dispatch_tuple<mask_type>::apply(mask, matrix);
536 template <typename Head, typename Tail>
537 struct check_dispatch< boost::tuples::cons<Head, Tail> >
539 typedef boost::tuples::cons<Head, Tail> mask_type;
541 template <typename Matrix>
542 static inline bool apply(mask_type const& mask, Matrix const& matrix)
544 return check_dispatch_tuple<mask_type>::apply(mask, matrix);
548 template <typename Mask, typename Matrix>
549 inline bool check_matrix(Mask const& mask, Matrix const& matrix)
551 return check_dispatch<Mask>::apply(mask, matrix);
556 template <typename MatrixOrMask>
559 static const std::size_t value = MatrixOrMask::static_width;
562 template <typename Tuple,
564 int N = boost::tuples::length<Tuple>::value>
565 struct matrix_width_tuple
567 static const std::size_t
568 current = matrix_width<typename boost::tuples::element<I, Tuple>::type>::value;
569 static const std::size_t
570 next = matrix_width_tuple<Tuple, I+1>::value;
572 static const std::size_t
573 value = current > next ? current : next;
576 template <typename Tuple, int N>
577 struct matrix_width_tuple<Tuple, N, N>
579 static const std::size_t value = 0;
582 template <typename Head, typename Tail>
583 struct matrix_width< boost::tuples::cons<Head, Tail> >
585 static const std::size_t
586 value = matrix_width_tuple< boost::tuples::cons<Head, Tail> >::value;
591 template <typename Mask, bool Interrupt>
593 : private matrix_handler
595 relate::matrix<matrix_width<Mask>::value>
598 typedef matrix_handler
600 relate::matrix<matrix_width<Mask>::value>
604 typedef bool result_type;
608 inline explicit mask_handler(Mask const& m)
613 result_type result() const
616 && check_matrix(m_mask, base_t::matrix());
619 template <field F1, field F2, char D>
620 inline bool may_update() const
622 return detail::relate::may_update<F1, F2, D>(
623 m_mask, base_t::matrix()
627 template <field F1, field F2, char V>
630 if ( relate::interrupt<F1, F2, V, Interrupt>(m_mask) )
636 base_t::template set<F1, F2, V>();
640 template <field F1, field F2, char V>
643 if ( relate::interrupt<F1, F2, V, Interrupt>(m_mask) )
649 base_t::template update<F1, F2, V>();
657 // --------------- FALSE MASK ----------------
659 struct false_mask {};
661 // --------------- COMPILE-TIME MASK ----------------
663 // static_check_characters
667 typename First = typename boost::mpl::begin<Seq>::type,
668 typename Last = typename boost::mpl::end<Seq>::type
670 struct static_check_characters
671 : static_check_characters
674 typename boost::mpl::next<First>::type
677 typedef typename boost::mpl::deref<First>::type type;
678 static const char value = type::value;
679 static const bool is_valid = (value >= '0' && value <= '9')
680 || value == 'T' || value == 'F' || value == '*';
681 BOOST_MPL_ASSERT_MSG((is_valid),
682 INVALID_STATIC_MASK_CHARACTER,
686 template <typename Seq, typename Last>
687 struct static_check_characters<Seq, Last, Last>
696 std::size_t Width = Height
700 static const std::size_t static_width = Width;
701 static const std::size_t static_height = Height;
702 static const std::size_t static_size = Width * Height;
705 std::size_t(boost::mpl::size<Seq>::type::value) == static_size);
707 template <detail::relate::field F1, detail::relate::field F2>
710 BOOST_STATIC_ASSERT(std::size_t(F1) < static_height);
711 BOOST_STATIC_ASSERT(std::size_t(F2) < static_width);
713 static const char value
714 = boost::mpl::at_c<Seq, F1 * static_width + F2>::type::value;
718 // check static_mask characters
719 enum { mask_check = sizeof(static_check_characters<Seq>) };
722 // static_should_handle_element
724 template <typename StaticMask, field F1, field F2, bool IsSequence>
725 struct static_should_handle_element_dispatch
727 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
728 static const bool value = mask_el == 'F'
730 || ( mask_el >= '0' && mask_el <= '9' );
733 template <typename First, typename Last, field F1, field F2>
734 struct static_should_handle_element_sequence
736 typedef typename boost::mpl::deref<First>::type StaticMask;
738 static const bool value
739 = static_should_handle_element_dispatch
743 boost::mpl::is_sequence<StaticMask>::value
745 || static_should_handle_element_sequence
747 typename boost::mpl::next<First>::type,
753 template <typename Last, field F1, field F2>
754 struct static_should_handle_element_sequence<Last, Last, F1, F2>
756 static const bool value = false;
759 template <typename StaticMask, field F1, field F2>
760 struct static_should_handle_element_dispatch<StaticMask, F1, F2, true>
762 static const bool value
763 = static_should_handle_element_sequence
765 typename boost::mpl::begin<StaticMask>::type,
766 typename boost::mpl::end<StaticMask>::type,
771 template <typename StaticMask, field F1, field F2>
772 struct static_should_handle_element
774 static const bool value
775 = static_should_handle_element_dispatch
779 boost::mpl::is_sequence<StaticMask>::value
785 template <typename StaticMask, char V, field F1, field F2, bool InterruptEnabled, bool IsSequence>
786 struct static_interrupt_dispatch
788 static const bool value = false;
791 template <typename StaticMask, char V, field F1, field F2, bool IsSequence>
792 struct static_interrupt_dispatch<StaticMask, V, F1, F2, true, IsSequence>
794 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
796 static const bool value
797 = ( V >= '0' && V <= '9' ) ?
798 ( mask_el == 'F' || ( mask_el < V && mask_el >= '0' && mask_el <= '9' ) ) :
799 ( ( V == 'T' ) ? mask_el == 'F' : false );
802 template <typename First, typename Last, char V, field F1, field F2>
803 struct static_interrupt_sequence
805 typedef typename boost::mpl::deref<First>::type StaticMask;
807 static const bool value
808 = static_interrupt_dispatch
813 boost::mpl::is_sequence<StaticMask>::value
815 && static_interrupt_sequence
817 typename boost::mpl::next<First>::type,
823 template <typename Last, char V, field F1, field F2>
824 struct static_interrupt_sequence<Last, Last, V, F1, F2>
826 static const bool value = true;
829 template <typename StaticMask, char V, field F1, field F2>
830 struct static_interrupt_dispatch<StaticMask, V, F1, F2, true, true>
832 static const bool value
833 = static_interrupt_sequence
835 typename boost::mpl::begin<StaticMask>::type,
836 typename boost::mpl::end<StaticMask>::type,
841 template <typename StaticMask, char V, field F1, field F2, bool EnableInterrupt>
842 struct static_interrupt
844 static const bool value
845 = static_interrupt_dispatch
850 boost::mpl::is_sequence<StaticMask>::value
856 template <typename StaticMask, char D, field F1, field F2, bool IsSequence>
857 struct static_may_update_dispatch
859 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
860 static const int version
863 : mask_el >= '0' && mask_el <= '9' ? 2
866 template <typename Matrix>
867 static inline bool apply(Matrix const& matrix)
869 return apply_dispatch(matrix, integral_constant<int, version>());
873 template <typename Matrix>
874 static inline bool apply_dispatch(Matrix const& , integral_constant<int, 0>)
879 template <typename Matrix>
880 static inline bool apply_dispatch(Matrix const& matrix, integral_constant<int, 1>)
882 char const c = matrix.template get<F1, F2>();
883 return c == 'F'; // if it's T or between 0 and 9, the result will be the same
885 // mask_el >= '0' && mask_el <= '9'
886 template <typename Matrix>
887 static inline bool apply_dispatch(Matrix const& matrix, integral_constant<int, 2>)
889 char const c = matrix.template get<F1, F2>();
890 return D > c || c > '9';
893 template <typename Matrix>
894 static inline bool apply_dispatch(Matrix const&, integral_constant<int, 3>)
900 template <typename First, typename Last, char D, field F1, field F2>
901 struct static_may_update_sequence
903 typedef typename boost::mpl::deref<First>::type StaticMask;
905 template <typename Matrix>
906 static inline bool apply(Matrix const& matrix)
908 return static_may_update_dispatch
912 boost::mpl::is_sequence<StaticMask>::value
914 || static_may_update_sequence
916 typename boost::mpl::next<First>::type,
923 template <typename Last, char D, field F1, field F2>
924 struct static_may_update_sequence<Last, Last, D, F1, F2>
926 template <typename Matrix>
927 static inline bool apply(Matrix const& /*matrix*/)
933 template <typename StaticMask, char D, field F1, field F2>
934 struct static_may_update_dispatch<StaticMask, D, F1, F2, true>
936 template <typename Matrix>
937 static inline bool apply(Matrix const& matrix)
939 return static_may_update_sequence
941 typename boost::mpl::begin<StaticMask>::type,
942 typename boost::mpl::end<StaticMask>::type,
948 template <typename StaticMask, char D, field F1, field F2>
949 struct static_may_update
951 template <typename Matrix>
952 static inline bool apply(Matrix const& matrix)
954 return static_may_update_dispatch
958 boost::mpl::is_sequence<StaticMask>::value
963 // static_check_matrix
965 template <typename StaticMask, bool IsSequence>
966 struct static_check_dispatch
968 template <typename Matrix>
969 static inline bool apply(Matrix const& matrix)
971 return per_one<interior, interior>::apply(matrix)
972 && per_one<interior, boundary>::apply(matrix)
973 && per_one<interior, exterior>::apply(matrix)
974 && per_one<boundary, interior>::apply(matrix)
975 && per_one<boundary, boundary>::apply(matrix)
976 && per_one<boundary, exterior>::apply(matrix)
977 && per_one<exterior, interior>::apply(matrix)
978 && per_one<exterior, boundary>::apply(matrix)
979 && per_one<exterior, exterior>::apply(matrix);
982 template <field F1, field F2>
985 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
986 static const int version
989 : mask_el >= '0' && mask_el <= '9' ? 2
992 template <typename Matrix>
993 static inline bool apply(Matrix const& matrix)
995 const char el = matrix.template get<F1, F2>();
996 return apply_dispatch(el, integral_constant<int, version>());
1000 static inline bool apply_dispatch(char el, integral_constant<int, 0>)
1005 static inline bool apply_dispatch(char el, integral_constant<int, 1>)
1007 return el == 'T' || ( el >= '0' && el <= '9' );
1009 // mask_el >= '0' && mask_el <= '9'
1010 static inline bool apply_dispatch(char el, integral_constant<int, 2>)
1012 return el == mask_el;
1015 static inline bool apply_dispatch(char /*el*/, integral_constant<int, 3>)
1022 template <typename First, typename Last>
1023 struct static_check_sequence
1025 typedef typename boost::mpl::deref<First>::type StaticMask;
1027 template <typename Matrix>
1028 static inline bool apply(Matrix const& matrix)
1030 return static_check_dispatch
1033 boost::mpl::is_sequence<StaticMask>::value
1035 || static_check_sequence
1037 typename boost::mpl::next<First>::type,
1043 template <typename Last>
1044 struct static_check_sequence<Last, Last>
1046 template <typename Matrix>
1047 static inline bool apply(Matrix const& /*matrix*/)
1053 template <typename StaticMask>
1054 struct static_check_dispatch<StaticMask, true>
1056 template <typename Matrix>
1057 static inline bool apply(Matrix const& matrix)
1059 return static_check_sequence
1061 typename boost::mpl::begin<StaticMask>::type,
1062 typename boost::mpl::end<StaticMask>::type
1067 template <typename StaticMask>
1068 struct static_check_matrix
1070 template <typename Matrix>
1071 static inline bool apply(Matrix const& matrix)
1073 return static_check_dispatch
1076 boost::mpl::is_sequence<StaticMask>::value
1081 // static_mask_handler
1083 template <typename StaticMask, bool Interrupt>
1084 class static_mask_handler
1085 : private matrix_handler< matrix<3> >
1087 typedef matrix_handler< relate::matrix<3> > base_type;
1090 typedef bool result_type;
1094 inline static_mask_handler()
1098 inline explicit static_mask_handler(StaticMask const& /*dummy*/)
1102 result_type result() const
1104 return (!Interrupt || !interrupt)
1105 && static_check_matrix<StaticMask>::apply(base_type::matrix());
1108 template <field F1, field F2, char D>
1109 inline bool may_update() const
1111 return static_may_update<StaticMask, D, F1, F2>::
1112 apply(base_type::matrix());
1115 template <field F1, field F2>
1116 static inline bool expects()
1118 return static_should_handle_element<StaticMask, F1, F2>::value;
1121 template <field F1, field F2, char V>
1124 static const bool interrupt_c = static_interrupt<StaticMask, V, F1, F2, Interrupt>::value;
1125 static const bool should_handle = static_should_handle_element<StaticMask, F1, F2>::value;
1126 static const int version = interrupt_c ? 0
1130 set_dispatch<F1, F2, V>(integral_constant<int, version>());
1133 template <field F1, field F2, char V>
1134 inline void update()
1136 static const bool interrupt_c = static_interrupt<StaticMask, V, F1, F2, Interrupt>::value;
1137 static const bool should_handle = static_should_handle_element<StaticMask, F1, F2>::value;
1138 static const int version = interrupt_c ? 0
1142 update_dispatch<F1, F2, V>(integral_constant<int, version>());
1146 // Interrupt && interrupt
1147 template <field F1, field F2, char V>
1148 inline void set_dispatch(integral_constant<int, 0>)
1152 // else should_handle
1153 template <field F1, field F2, char V>
1154 inline void set_dispatch(integral_constant<int, 1>)
1156 base_type::template set<F1, F2, V>();
1159 template <field F1, field F2, char V>
1160 inline void set_dispatch(integral_constant<int, 2>)
1163 // Interrupt && interrupt
1164 template <field F1, field F2, char V>
1165 inline void update_dispatch(integral_constant<int, 0>)
1169 // else should_handle
1170 template <field F1, field F2, char V>
1171 inline void update_dispatch(integral_constant<int, 1>)
1173 base_type::template update<F1, F2, V>();
1176 template <field F1, field F2, char V>
1177 inline void update_dispatch(integral_constant<int, 2>)
1181 // --------------- UTIL FUNCTIONS ----------------
1185 template <field F1, field F2, char V, typename Result>
1186 inline void set(Result & res)
1188 res.template set<F1, F2, V>();
1191 template <field F1, field F2, char V, bool Transpose>
1194 template <typename Result>
1195 static inline void apply(Result & res)
1197 res.template set<F1, F2, V>();
1201 template <field F1, field F2, char V>
1202 struct set_dispatch<F1, F2, V, true>
1204 template <typename Result>
1205 static inline void apply(Result & res)
1207 res.template set<F2, F1, V>();
1211 template <field F1, field F2, char V, bool Transpose, typename Result>
1212 inline void set(Result & res)
1214 set_dispatch<F1, F2, V, Transpose>::apply(res);
1219 template <field F1, field F2, char D, typename Result>
1220 inline void update(Result & res)
1222 res.template update<F1, F2, D>();
1225 template <field F1, field F2, char D, bool Transpose>
1226 struct update_result_dispatch
1228 template <typename Result>
1229 static inline void apply(Result & res)
1231 update<F1, F2, D>(res);
1235 template <field F1, field F2, char D>
1236 struct update_result_dispatch<F1, F2, D, true>
1238 template <typename Result>
1239 static inline void apply(Result & res)
1241 update<F2, F1, D>(res);
1245 template <field F1, field F2, char D, bool Transpose, typename Result>
1246 inline void update(Result & res)
1248 update_result_dispatch<F1, F2, D, Transpose>::apply(res);
1253 template <field F1, field F2, char D, typename Result>
1254 inline bool may_update(Result const& res)
1256 return res.template may_update<F1, F2, D>();
1259 template <field F1, field F2, char D, bool Transpose>
1260 struct may_update_result_dispatch
1262 template <typename Result>
1263 static inline bool apply(Result const& res)
1265 return may_update<F1, F2, D>(res);
1269 template <field F1, field F2, char D>
1270 struct may_update_result_dispatch<F1, F2, D, true>
1272 template <typename Result>
1273 static inline bool apply(Result const& res)
1275 return may_update<F2, F1, D>(res);
1279 template <field F1, field F2, char D, bool Transpose, typename Result>
1280 inline bool may_update(Result const& res)
1282 return may_update_result_dispatch<F1, F2, D, Transpose>::apply(res);
1287 template <typename Geometry>
1288 struct result_dimension
1290 BOOST_STATIC_ASSERT(geometry::dimension<Geometry>::value >= 0);
1291 static const char value
1292 = ( geometry::dimension<Geometry>::value <= 9 ) ?
1293 ( '0' + geometry::dimension<Geometry>::value ) :
1297 }} // namespace detail::relate
1298 #endif // DOXYGEN_NO_DETAIL
1300 }} // namespace boost::geometry
1302 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_RESULT_HPP