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_INTERVAL_BOUNDS_HPP_JOFA_100330
9 #define BOOST_ICL_INTERVAL_BOUNDS_HPP_JOFA_100330
10 
11 #include <boost/utility/enable_if.hpp>
12 #include <boost/icl/detail/design_config.hpp>
13 
14 namespace boost{namespace icl
15 {
16 
17 typedef unsigned char bound_type;
18 
19 class interval_bounds
20 {
21 public:
22     BOOST_STATIC_CONSTANT(bound_type, static_open       = 0);
23     BOOST_STATIC_CONSTANT(bound_type, static_left_open  = 1);
24     BOOST_STATIC_CONSTANT(bound_type, static_right_open = 2);
25     BOOST_STATIC_CONSTANT(bound_type, static_closed     = 3);
26     BOOST_STATIC_CONSTANT(bound_type, dynamic           = 4);
27     BOOST_STATIC_CONSTANT(bound_type, undefined         = 5);
28 
29     BOOST_STATIC_CONSTANT(bound_type, _open       = 0);
30     BOOST_STATIC_CONSTANT(bound_type, _left_open  = 1);
31     BOOST_STATIC_CONSTANT(bound_type, _right_open = 2);
32     BOOST_STATIC_CONSTANT(bound_type, _closed     = 3);
33 
34     BOOST_STATIC_CONSTANT(bound_type, _right     = 1);
35     BOOST_STATIC_CONSTANT(bound_type, _left      = 2);
36     BOOST_STATIC_CONSTANT(bound_type, _all       = 3);
37 
38 public:
interval_bounds()39     interval_bounds():_bits(){}
interval_bounds(bound_type bounds)40     explicit interval_bounds(bound_type bounds): _bits(bounds){}
all() const41     interval_bounds all  ()const { return interval_bounds(_bits & _all  ); }
left() const42     interval_bounds left ()const { return interval_bounds(_bits & _left ); }
right() const43     interval_bounds right()const { return interval_bounds(_bits & _right); }
reverse_left() const44     interval_bounds reverse_left ()const { return interval_bounds((bound_type(~_bits)>>1) & _right); }
reverse_right() const45     interval_bounds reverse_right()const { return interval_bounds((bound_type(~_bits)<<1) & _left ); }
46 
bits() const47     bound_type bits()const{ return _bits; }
48 
open()49     static interval_bounds open()      { return interval_bounds(_open);     }
left_open()50     static interval_bounds left_open() { return interval_bounds(_left_open); }
right_open()51     static interval_bounds right_open(){ return interval_bounds(_right_open);}
closed()52     static interval_bounds closed()    { return interval_bounds(_closed);   }
53 
54 public:
55     bound_type _bits;
56 };
57 
58 
59 template<class DomainT>
60 class bounded_value
61 {
62 public:
63     typedef DomainT domain_type;
64     typedef bounded_value<DomainT> type;
65 public:
bounded_value(const domain_type & value,interval_bounds bound)66     bounded_value(const domain_type& value, interval_bounds bound)
67         : _value(value), _bound(bound) {}
68 
value() const69     domain_type     value()const { return _value; }
bound() const70     interval_bounds bound()const { return _bound; }
71 
72 private:
73     domain_type     _value;
74     interval_bounds _bound;
75 };
76 
77 }} // namespace icl boost
78 
79 #endif
80 
81