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-2018.
7 // Modifications copyright (c) 2013-2018 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 // --------------- COMPILE-TIME MASK ----------------
659 // static_check_characters
663 typename First = typename boost::mpl::begin<Seq>::type,
664 typename Last = typename boost::mpl::end<Seq>::type
666 struct static_check_characters
667 : static_check_characters
670 typename boost::mpl::next<First>::type
673 typedef typename boost::mpl::deref<First>::type type;
674 static const char value = type::value;
675 static const bool is_valid = (value >= '0' && value <= '9')
676 || value == 'T' || value == 'F' || value == '*';
677 BOOST_MPL_ASSERT_MSG((is_valid),
678 INVALID_STATIC_MASK_CHARACTER,
682 template <typename Seq, typename Last>
683 struct static_check_characters<Seq, Last, Last>
692 std::size_t Width = Height
696 static const std::size_t static_width = Width;
697 static const std::size_t static_height = Height;
698 static const std::size_t static_size = Width * Height;
701 std::size_t(boost::mpl::size<Seq>::type::value) == static_size);
703 template <detail::relate::field F1, detail::relate::field F2>
706 BOOST_STATIC_ASSERT(std::size_t(F1) < static_height);
707 BOOST_STATIC_ASSERT(std::size_t(F2) < static_width);
709 static const char value
710 = boost::mpl::at_c<Seq, F1 * static_width + F2>::type::value;
714 // check static_mask characters
715 enum { mask_check = sizeof(static_check_characters<Seq>) };
718 // static_should_handle_element
720 template <typename StaticMask, field F1, field F2, bool IsSequence>
721 struct static_should_handle_element_dispatch
723 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
724 static const bool value = mask_el == 'F'
726 || ( mask_el >= '0' && mask_el <= '9' );
729 template <typename First, typename Last, field F1, field F2>
730 struct static_should_handle_element_sequence
732 typedef typename boost::mpl::deref<First>::type StaticMask;
734 static const bool value
735 = static_should_handle_element_dispatch
739 boost::mpl::is_sequence<StaticMask>::value
741 || static_should_handle_element_sequence
743 typename boost::mpl::next<First>::type,
749 template <typename Last, field F1, field F2>
750 struct static_should_handle_element_sequence<Last, Last, F1, F2>
752 static const bool value = false;
755 template <typename StaticMask, field F1, field F2>
756 struct static_should_handle_element_dispatch<StaticMask, F1, F2, true>
758 static const bool value
759 = static_should_handle_element_sequence
761 typename boost::mpl::begin<StaticMask>::type,
762 typename boost::mpl::end<StaticMask>::type,
767 template <typename StaticMask, field F1, field F2>
768 struct static_should_handle_element
770 static const bool value
771 = static_should_handle_element_dispatch
775 boost::mpl::is_sequence<StaticMask>::value
781 template <typename StaticMask, char V, field F1, field F2, bool InterruptEnabled, bool IsSequence>
782 struct static_interrupt_dispatch
784 static const bool value = false;
787 template <typename StaticMask, char V, field F1, field F2, bool IsSequence>
788 struct static_interrupt_dispatch<StaticMask, V, F1, F2, true, IsSequence>
790 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
792 static const bool value
793 = ( V >= '0' && V <= '9' ) ?
794 ( mask_el == 'F' || ( mask_el < V && mask_el >= '0' && mask_el <= '9' ) ) :
795 ( ( V == 'T' ) ? mask_el == 'F' : false );
798 template <typename First, typename Last, char V, field F1, field F2>
799 struct static_interrupt_sequence
801 typedef typename boost::mpl::deref<First>::type StaticMask;
803 static const bool value
804 = static_interrupt_dispatch
809 boost::mpl::is_sequence<StaticMask>::value
811 && static_interrupt_sequence
813 typename boost::mpl::next<First>::type,
819 template <typename Last, char V, field F1, field F2>
820 struct static_interrupt_sequence<Last, Last, V, F1, F2>
822 static const bool value = true;
825 template <typename StaticMask, char V, field F1, field F2>
826 struct static_interrupt_dispatch<StaticMask, V, F1, F2, true, true>
828 static const bool value
829 = static_interrupt_sequence
831 typename boost::mpl::begin<StaticMask>::type,
832 typename boost::mpl::end<StaticMask>::type,
837 template <typename StaticMask, char V, field F1, field F2, bool EnableInterrupt>
838 struct static_interrupt
840 static const bool value
841 = static_interrupt_dispatch
846 boost::mpl::is_sequence<StaticMask>::value
852 template <typename StaticMask, char D, field F1, field F2, bool IsSequence>
853 struct static_may_update_dispatch
855 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
856 static const int version
859 : mask_el >= '0' && mask_el <= '9' ? 2
862 template <typename Matrix>
863 static inline bool apply(Matrix const& matrix)
865 return apply_dispatch(matrix, integral_constant<int, version>());
869 template <typename Matrix>
870 static inline bool apply_dispatch(Matrix const& , integral_constant<int, 0>)
875 template <typename Matrix>
876 static inline bool apply_dispatch(Matrix const& matrix, integral_constant<int, 1>)
878 char const c = matrix.template get<F1, F2>();
879 return c == 'F'; // if it's T or between 0 and 9, the result will be the same
881 // mask_el >= '0' && mask_el <= '9'
882 template <typename Matrix>
883 static inline bool apply_dispatch(Matrix const& matrix, integral_constant<int, 2>)
885 char const c = matrix.template get<F1, F2>();
886 return D > c || c > '9';
889 template <typename Matrix>
890 static inline bool apply_dispatch(Matrix const&, integral_constant<int, 3>)
896 template <typename First, typename Last, char D, field F1, field F2>
897 struct static_may_update_sequence
899 typedef typename boost::mpl::deref<First>::type StaticMask;
901 template <typename Matrix>
902 static inline bool apply(Matrix const& matrix)
904 return static_may_update_dispatch
908 boost::mpl::is_sequence<StaticMask>::value
910 || static_may_update_sequence
912 typename boost::mpl::next<First>::type,
919 template <typename Last, char D, field F1, field F2>
920 struct static_may_update_sequence<Last, Last, D, F1, F2>
922 template <typename Matrix>
923 static inline bool apply(Matrix const& /*matrix*/)
929 template <typename StaticMask, char D, field F1, field F2>
930 struct static_may_update_dispatch<StaticMask, D, F1, F2, true>
932 template <typename Matrix>
933 static inline bool apply(Matrix const& matrix)
935 return static_may_update_sequence
937 typename boost::mpl::begin<StaticMask>::type,
938 typename boost::mpl::end<StaticMask>::type,
944 template <typename StaticMask, char D, field F1, field F2>
945 struct static_may_update
947 template <typename Matrix>
948 static inline bool apply(Matrix const& matrix)
950 return static_may_update_dispatch
954 boost::mpl::is_sequence<StaticMask>::value
959 // static_check_matrix
961 template <typename StaticMask, bool IsSequence>
962 struct static_check_dispatch
964 template <typename Matrix>
965 static inline bool apply(Matrix const& matrix)
967 return per_one<interior, interior>::apply(matrix)
968 && per_one<interior, boundary>::apply(matrix)
969 && per_one<interior, exterior>::apply(matrix)
970 && per_one<boundary, interior>::apply(matrix)
971 && per_one<boundary, boundary>::apply(matrix)
972 && per_one<boundary, exterior>::apply(matrix)
973 && per_one<exterior, interior>::apply(matrix)
974 && per_one<exterior, boundary>::apply(matrix)
975 && per_one<exterior, exterior>::apply(matrix);
978 template <field F1, field F2>
981 static const char mask_el = StaticMask::template static_get<F1, F2>::value;
982 static const int version
985 : mask_el >= '0' && mask_el <= '9' ? 2
988 template <typename Matrix>
989 static inline bool apply(Matrix const& matrix)
991 const char el = matrix.template get<F1, F2>();
992 return apply_dispatch(el, integral_constant<int, version>());
996 static inline bool apply_dispatch(char el, integral_constant<int, 0>)
1001 static inline bool apply_dispatch(char el, integral_constant<int, 1>)
1003 return el == 'T' || ( el >= '0' && el <= '9' );
1005 // mask_el >= '0' && mask_el <= '9'
1006 static inline bool apply_dispatch(char el, integral_constant<int, 2>)
1008 return el == mask_el;
1011 static inline bool apply_dispatch(char /*el*/, integral_constant<int, 3>)
1018 template <typename First, typename Last>
1019 struct static_check_sequence
1021 typedef typename boost::mpl::deref<First>::type StaticMask;
1023 template <typename Matrix>
1024 static inline bool apply(Matrix const& matrix)
1026 return static_check_dispatch
1029 boost::mpl::is_sequence<StaticMask>::value
1031 || static_check_sequence
1033 typename boost::mpl::next<First>::type,
1039 template <typename Last>
1040 struct static_check_sequence<Last, Last>
1042 template <typename Matrix>
1043 static inline bool apply(Matrix const& /*matrix*/)
1049 template <typename StaticMask>
1050 struct static_check_dispatch<StaticMask, true>
1052 template <typename Matrix>
1053 static inline bool apply(Matrix const& matrix)
1055 return static_check_sequence
1057 typename boost::mpl::begin<StaticMask>::type,
1058 typename boost::mpl::end<StaticMask>::type
1063 template <typename StaticMask>
1064 struct static_check_matrix
1066 template <typename Matrix>
1067 static inline bool apply(Matrix const& matrix)
1069 return static_check_dispatch
1072 boost::mpl::is_sequence<StaticMask>::value
1077 // static_mask_handler
1079 template <typename StaticMask, bool Interrupt>
1080 class static_mask_handler
1081 : private matrix_handler< matrix<3> >
1083 typedef matrix_handler< relate::matrix<3> > base_type;
1086 typedef bool result_type;
1090 inline static_mask_handler()
1094 inline explicit static_mask_handler(StaticMask const& /*dummy*/)
1098 result_type result() const
1100 return (!Interrupt || !interrupt)
1101 && static_check_matrix<StaticMask>::apply(base_type::matrix());
1104 template <field F1, field F2, char D>
1105 inline bool may_update() const
1107 return static_may_update<StaticMask, D, F1, F2>::
1108 apply(base_type::matrix());
1111 template <field F1, field F2>
1112 static inline bool expects()
1114 return static_should_handle_element<StaticMask, F1, F2>::value;
1117 template <field F1, field F2, char V>
1120 static const bool interrupt_c = static_interrupt<StaticMask, V, F1, F2, Interrupt>::value;
1121 static const bool should_handle = static_should_handle_element<StaticMask, F1, F2>::value;
1122 static const int version = interrupt_c ? 0
1126 set_dispatch<F1, F2, V>(integral_constant<int, version>());
1129 template <field F1, field F2, char V>
1130 inline void update()
1132 static const bool interrupt_c = static_interrupt<StaticMask, V, F1, F2, Interrupt>::value;
1133 static const bool should_handle = static_should_handle_element<StaticMask, F1, F2>::value;
1134 static const int version = interrupt_c ? 0
1138 update_dispatch<F1, F2, V>(integral_constant<int, version>());
1142 // Interrupt && interrupt
1143 template <field F1, field F2, char V>
1144 inline void set_dispatch(integral_constant<int, 0>)
1148 // else should_handle
1149 template <field F1, field F2, char V>
1150 inline void set_dispatch(integral_constant<int, 1>)
1152 base_type::template set<F1, F2, V>();
1155 template <field F1, field F2, char V>
1156 inline void set_dispatch(integral_constant<int, 2>)
1159 // Interrupt && interrupt
1160 template <field F1, field F2, char V>
1161 inline void update_dispatch(integral_constant<int, 0>)
1165 // else should_handle
1166 template <field F1, field F2, char V>
1167 inline void update_dispatch(integral_constant<int, 1>)
1169 base_type::template update<F1, F2, V>();
1172 template <field F1, field F2, char V>
1173 inline void update_dispatch(integral_constant<int, 2>)
1177 // --------------- UTIL FUNCTIONS ----------------
1181 template <field F1, field F2, char V, typename Result>
1182 inline void set(Result & res)
1184 res.template set<F1, F2, V>();
1187 template <field F1, field F2, char V, bool Transpose>
1190 template <typename Result>
1191 static inline void apply(Result & res)
1193 res.template set<F1, F2, V>();
1197 template <field F1, field F2, char V>
1198 struct set_dispatch<F1, F2, V, true>
1200 template <typename Result>
1201 static inline void apply(Result & res)
1203 res.template set<F2, F1, V>();
1207 template <field F1, field F2, char V, bool Transpose, typename Result>
1208 inline void set(Result & res)
1210 set_dispatch<F1, F2, V, Transpose>::apply(res);
1215 template <field F1, field F2, char D, typename Result>
1216 inline void update(Result & res)
1218 res.template update<F1, F2, D>();
1221 template <field F1, field F2, char D, bool Transpose>
1222 struct update_result_dispatch
1224 template <typename Result>
1225 static inline void apply(Result & res)
1227 update<F1, F2, D>(res);
1231 template <field F1, field F2, char D>
1232 struct update_result_dispatch<F1, F2, D, true>
1234 template <typename Result>
1235 static inline void apply(Result & res)
1237 update<F2, F1, D>(res);
1241 template <field F1, field F2, char D, bool Transpose, typename Result>
1242 inline void update(Result & res)
1244 update_result_dispatch<F1, F2, D, Transpose>::apply(res);
1249 template <field F1, field F2, char D, typename Result>
1250 inline bool may_update(Result const& res)
1252 return res.template may_update<F1, F2, D>();
1255 template <field F1, field F2, char D, bool Transpose>
1256 struct may_update_result_dispatch
1258 template <typename Result>
1259 static inline bool apply(Result const& res)
1261 return may_update<F1, F2, D>(res);
1265 template <field F1, field F2, char D>
1266 struct may_update_result_dispatch<F1, F2, D, true>
1268 template <typename Result>
1269 static inline bool apply(Result const& res)
1271 return may_update<F2, F1, D>(res);
1275 template <field F1, field F2, char D, bool Transpose, typename Result>
1276 inline bool may_update(Result const& res)
1278 return may_update_result_dispatch<F1, F2, D, Transpose>::apply(res);
1283 template <typename Geometry>
1284 struct result_dimension
1286 BOOST_STATIC_ASSERT(geometry::dimension<Geometry>::value >= 0);
1287 static const char value
1288 = ( geometry::dimension<Geometry>::value <= 9 ) ?
1289 ( '0' + geometry::dimension<Geometry>::value ) :
1293 }} // namespace detail::relate
1294 #endif // DOXYGEN_NO_DETAIL
1296 }} // namespace boost::geometry
1298 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_RESULT_HPP