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 
11 #include <boost/mpl/or.hpp>
12 #include <boost/icl/interval_bounds.hpp>
13 #include <boost/icl/interval_traits.hpp>
14 
15 namespace boost{ namespace icl
16 {
17 
18 template <class Type>
19 struct interval_bound_type
20 {
21     typedef interval_bound_type type;
22     BOOST_STATIC_CONSTANT(bound_type, value = (interval_bounds::undefined));
23 };
24 
25 template <class Type> struct is_interval
26 {
27     typedef is_interval<Type> type;
28     BOOST_STATIC_CONSTANT(bool,
29         value = ((interval_bound_type<Type>::value) < interval_bounds::undefined));
30 };
31 
32 
33 template <class Type> struct has_static_bounds
34 {
35     typedef has_static_bounds<Type> type;
36     BOOST_STATIC_CONSTANT(bool,
37         value = ((interval_bound_type<Type>::value) < interval_bounds::dynamic));
38 };
39 
40 template <class Type> struct has_dynamic_bounds
41 {
42     typedef has_dynamic_bounds<Type> type;
43     BOOST_STATIC_CONSTANT(bool,
44         value = (interval_bound_type<Type>::value == interval_bounds::dynamic));
45 };
46 
47 template <class Type> struct has_asymmetric_bounds
48 {
49     typedef has_asymmetric_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_left_open
53                  || bounds == interval_bounds::static_right_open));
54 };
55 
56 template <class Type> struct has_symmetric_bounds
57 {
58     typedef has_symmetric_bounds<Type> type;
59     BOOST_STATIC_CONSTANT(bound_type, bounds = (interval_bound_type<Type>::value));
60     BOOST_STATIC_CONSTANT(bool,
61         value = (   bounds == interval_bounds::static_closed
62                  || bounds == interval_bounds::static_open));
63 };
64 
65 //------------------------------------------------------------------------------
66 template <class Type> struct is_discrete_static
67 {
68     typedef is_discrete_static type;
69     typedef typename interval_traits<Type>::domain_type domain_type;
70     BOOST_STATIC_CONSTANT(bool,
71         value = (mpl::and_< has_static_bounds<Type>
72                           , is_discrete<domain_type> >::value) );
73 };
74 
75 //------------------------------------------------------------------------------
76 template <class Type> struct is_continuous_static
77 {
78     typedef is_continuous_static type;
79     typedef typename interval_traits<Type>::domain_type domain_type;
80     BOOST_STATIC_CONSTANT(bool,
81         value = (mpl::and_< has_static_bounds<Type>
82                           , is_continuous<domain_type>
83                           , has_asymmetric_bounds<Type> >::value) );
84 };
85 
86 //------------------------------------------------------------------------------
87 template <class Type> struct is_static_right_open
88 {
89     typedef is_static_right_open<Type> type;
90     BOOST_STATIC_CONSTANT(bool,
91         value = (interval_bound_type<Type>::value == interval_bounds::static_right_open));
92 };
93 
94 template <class Type> struct is_static_left_open
95 {
96     typedef is_static_left_open<Type> type;
97     BOOST_STATIC_CONSTANT(bool,
98         value = (interval_bound_type<Type>::value == interval_bounds::static_left_open));
99 };
100 
101 template <class Type> struct is_static_open
102 {
103     typedef is_static_open<Type> type;
104     BOOST_STATIC_CONSTANT(bool,
105         value = (interval_bound_type<Type>::value == interval_bounds::static_open));
106 };
107 
108 template <class Type> struct is_static_closed
109 {
110     typedef is_static_closed<Type> type;
111     BOOST_STATIC_CONSTANT(bool,
112         value = (interval_bound_type<Type>::value == interval_bounds::static_closed));
113 };
114 
115 template <class Type> struct is_discrete_static_closed
116 {
117     typedef is_static_closed<Type> type;
118     typedef typename interval_traits<Type>::domain_type domain_type;
119 
120     BOOST_STATIC_CONSTANT( bool,
121         value = (mpl::and_< is_static_closed<Type>
122                           , is_discrete<domain_type> >::value) );
123 };
124 
125 template <class Type> struct is_discrete_static_open
126 {
127     typedef is_static_closed<Type> type;
128     typedef typename interval_traits<Type>::domain_type domain_type;
129 
130     BOOST_STATIC_CONSTANT( bool,
131         value = (mpl::and_< is_static_open<Type>
132                           , is_discrete<domain_type> >::value) );
133 };
134 
135 //------------------------------------------------------------------------------
136 template <class Type> struct is_continuous_right_open
137 {
138     typedef is_continuous_right_open<Type> type;
139     typedef typename interval_traits<Type>::domain_type domain_type;
140     BOOST_STATIC_CONSTANT(bool,
141         value = (mpl::and_<is_static_right_open<Type>, is_continuous<domain_type> >::value));
142 };
143 
144 template <class Type> struct is_continuous_left_open
145 {
146     typedef is_continuous_left_open<Type> type;
147     typedef typename interval_traits<Type>::domain_type domain_type;
148     BOOST_STATIC_CONSTANT(bool,
149         value = (mpl::and_<is_static_left_open<Type>, is_continuous<domain_type> >::value));
150 };
151 
152 //------------------------------------------------------------------------------
153 
154 template <class Type> struct is_singelizable
155 {
156     typedef is_singelizable type;
157     typedef typename interval_traits<Type>::domain_type domain_type;
158 
159     BOOST_STATIC_CONSTANT(bool,
160         value =
161             (mpl::or_< has_dynamic_bounds<Type>
162                      , is_discrete<domain_type>
163                      >::value)
164     );
165 };
166 
167 }} // namespace boost icl
168 
169 #endif
170 
171 
172