is_interval.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2010-2010: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_TYPE_TRAITS_IS_INTERVAL_HPP_JOFA_100327
  9. #define BOOST_ICL_TYPE_TRAITS_IS_INTERVAL_HPP_JOFA_100327
  10. #include <boost/mpl/or.hpp>
  11. #include <boost/icl/interval_bounds.hpp>
  12. #include <boost/icl/interval_traits.hpp>
  13. namespace boost{ namespace icl
  14. {
  15. template <class Type>
  16. struct interval_bound_type
  17. {
  18. typedef interval_bound_type type;
  19. BOOST_STATIC_CONSTANT(bound_type, value = (interval_bounds::undefined));
  20. };
  21. template <class Type> struct is_interval
  22. {
  23. typedef is_interval<Type> type;
  24. BOOST_STATIC_CONSTANT(bool,
  25. value = ((interval_bound_type<Type>::value) < interval_bounds::undefined));
  26. };
  27. template <class Type> struct has_static_bounds
  28. {
  29. typedef has_static_bounds<Type> type;
  30. BOOST_STATIC_CONSTANT(bool,
  31. value = ((interval_bound_type<Type>::value) < interval_bounds::dynamic));
  32. };
  33. template <class Type> struct has_dynamic_bounds
  34. {
  35. typedef has_dynamic_bounds<Type> type;
  36. BOOST_STATIC_CONSTANT(bool,
  37. value = (interval_bound_type<Type>::value == interval_bounds::dynamic));
  38. };
  39. template <class Type> struct has_asymmetric_bounds
  40. {
  41. typedef has_asymmetric_bounds<Type> type;
  42. BOOST_STATIC_CONSTANT(bound_type, bounds = (interval_bound_type<Type>::value));
  43. BOOST_STATIC_CONSTANT(bool,
  44. value = ( bounds == interval_bounds::static_left_open
  45. || bounds == interval_bounds::static_right_open));
  46. };
  47. template <class Type> struct has_symmetric_bounds
  48. {
  49. typedef has_symmetric_bounds<Type> type;
  50. BOOST_STATIC_CONSTANT(bound_type, bounds = (interval_bound_type<Type>::value));
  51. BOOST_STATIC_CONSTANT(bool,
  52. value = ( bounds == interval_bounds::static_closed
  53. || bounds == interval_bounds::static_open));
  54. };
  55. //------------------------------------------------------------------------------
  56. template <class Type> struct is_discrete_static
  57. {
  58. typedef is_discrete_static type;
  59. typedef typename interval_traits<Type>::domain_type domain_type;
  60. BOOST_STATIC_CONSTANT(bool,
  61. value = (mpl::and_< has_static_bounds<Type>
  62. , is_discrete<domain_type> >::value) );
  63. };
  64. //------------------------------------------------------------------------------
  65. template <class Type> struct is_continuous_static
  66. {
  67. typedef is_continuous_static type;
  68. typedef typename interval_traits<Type>::domain_type domain_type;
  69. BOOST_STATIC_CONSTANT(bool,
  70. value = (mpl::and_< has_static_bounds<Type>
  71. , is_continuous<domain_type>
  72. , has_asymmetric_bounds<Type> >::value) );
  73. };
  74. //------------------------------------------------------------------------------
  75. template <class Type> struct is_static_right_open
  76. {
  77. typedef is_static_right_open<Type> type;
  78. BOOST_STATIC_CONSTANT(bool,
  79. value = (interval_bound_type<Type>::value == interval_bounds::static_right_open));
  80. };
  81. template <class Type> struct is_static_left_open
  82. {
  83. typedef is_static_left_open<Type> type;
  84. BOOST_STATIC_CONSTANT(bool,
  85. value = (interval_bound_type<Type>::value == interval_bounds::static_left_open));
  86. };
  87. template <class Type> struct is_static_open
  88. {
  89. typedef is_static_open<Type> type;
  90. BOOST_STATIC_CONSTANT(bool,
  91. value = (interval_bound_type<Type>::value == interval_bounds::static_open));
  92. };
  93. template <class Type> struct is_static_closed
  94. {
  95. typedef is_static_closed<Type> type;
  96. BOOST_STATIC_CONSTANT(bool,
  97. value = (interval_bound_type<Type>::value == interval_bounds::static_closed));
  98. };
  99. template <class Type> struct is_discrete_static_closed
  100. {
  101. typedef is_static_closed<Type> type;
  102. typedef typename interval_traits<Type>::domain_type domain_type;
  103. BOOST_STATIC_CONSTANT( bool,
  104. value = (mpl::and_< is_static_closed<Type>
  105. , is_discrete<domain_type> >::value) );
  106. };
  107. template <class Type> struct is_discrete_static_open
  108. {
  109. typedef is_static_closed<Type> type;
  110. typedef typename interval_traits<Type>::domain_type domain_type;
  111. BOOST_STATIC_CONSTANT( bool,
  112. value = (mpl::and_< is_static_open<Type>
  113. , is_discrete<domain_type> >::value) );
  114. };
  115. //------------------------------------------------------------------------------
  116. template <class Type> struct is_continuous_right_open
  117. {
  118. typedef is_continuous_right_open<Type> type;
  119. typedef typename interval_traits<Type>::domain_type domain_type;
  120. BOOST_STATIC_CONSTANT(bool,
  121. value = (mpl::and_<is_static_right_open<Type>, is_continuous<domain_type> >::value));
  122. };
  123. template <class Type> struct is_continuous_left_open
  124. {
  125. typedef is_continuous_left_open<Type> type;
  126. typedef typename interval_traits<Type>::domain_type domain_type;
  127. BOOST_STATIC_CONSTANT(bool,
  128. value = (mpl::and_<is_static_left_open<Type>, is_continuous<domain_type> >::value));
  129. };
  130. //------------------------------------------------------------------------------
  131. template <class Type> struct is_singelizable
  132. {
  133. typedef is_singelizable type;
  134. typedef typename interval_traits<Type>::domain_type domain_type;
  135. BOOST_STATIC_CONSTANT(bool,
  136. value =
  137. (mpl::or_< has_dynamic_bounds<Type>
  138. , is_discrete<domain_type>
  139. >::value)
  140. );
  141. };
  142. }} // namespace boost icl
  143. #endif