interval_bounds.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <boost/utility/enable_if.hpp>
  11. #include <boost/icl/detail/design_config.hpp>
  12. namespace boost{namespace icl
  13. {
  14. typedef unsigned char bound_type;
  15. class interval_bounds
  16. {
  17. public:
  18. BOOST_STATIC_CONSTANT(bound_type, static_open = 0);
  19. BOOST_STATIC_CONSTANT(bound_type, static_left_open = 1);
  20. BOOST_STATIC_CONSTANT(bound_type, static_right_open = 2);
  21. BOOST_STATIC_CONSTANT(bound_type, static_closed = 3);
  22. BOOST_STATIC_CONSTANT(bound_type, dynamic = 4);
  23. BOOST_STATIC_CONSTANT(bound_type, undefined = 5);
  24. BOOST_STATIC_CONSTANT(bound_type, _open = 0);
  25. BOOST_STATIC_CONSTANT(bound_type, _left_open = 1);
  26. BOOST_STATIC_CONSTANT(bound_type, _right_open = 2);
  27. BOOST_STATIC_CONSTANT(bound_type, _closed = 3);
  28. BOOST_STATIC_CONSTANT(bound_type, _right = 1);
  29. BOOST_STATIC_CONSTANT(bound_type, _left = 2);
  30. BOOST_STATIC_CONSTANT(bound_type, _all = 3);
  31. public:
  32. interval_bounds():_bits(){}
  33. explicit interval_bounds(bound_type bounds): _bits(bounds){}
  34. interval_bounds all ()const { return interval_bounds(_bits & _all ); }
  35. interval_bounds left ()const { return interval_bounds(_bits & _left ); }
  36. interval_bounds right()const { return interval_bounds(_bits & _right); }
  37. interval_bounds reverse_left ()const { return interval_bounds((bound_type(~_bits)>>1) & _right); }
  38. interval_bounds reverse_right()const { return interval_bounds((bound_type(~_bits)<<1) & _left ); }
  39. bound_type bits()const{ return _bits; }
  40. static interval_bounds open() { return interval_bounds(_open); }
  41. static interval_bounds left_open() { return interval_bounds(_left_open); }
  42. static interval_bounds right_open(){ return interval_bounds(_right_open);}
  43. static interval_bounds closed() { return interval_bounds(_closed); }
  44. public:
  45. bound_type _bits;
  46. };
  47. template<class DomainT>
  48. class bounded_value
  49. {
  50. public:
  51. typedef DomainT domain_type;
  52. typedef bounded_value<DomainT> type;
  53. public:
  54. bounded_value(const domain_type& value, interval_bounds bound)
  55. : _value(value), _bound(bound) {}
  56. domain_type value()const { return _value; }
  57. interval_bounds bound()const { return _bound; }
  58. private:
  59. domain_type _value;
  60. interval_bounds _bound;
  61. };
  62. }} // namespace icl boost
  63. #endif