]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323 | |
9 | #define BOOST_ICL_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323 | |
10 | ||
11 | #include <functional> | |
1e59de90 | 12 | #include <boost/static_assert.hpp> |
7c673cae | 13 | #include <boost/concept/assert.hpp> |
1e59de90 | 14 | #include <boost/icl/detail/concept_check.hpp> |
7c673cae FG |
15 | #include <boost/icl/concept/interval.hpp> |
16 | #include <boost/icl/type_traits/succ_pred.hpp> | |
17 | #include <boost/icl/type_traits/value_size.hpp> | |
18 | #include <boost/icl/type_traits/type_to_string.hpp> | |
19 | ||
20 | namespace boost{namespace icl | |
21 | { | |
22 | ||
1e59de90 | 23 | template <class DomainT, |
7c673cae FG |
24 | ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)> |
25 | class right_open_interval | |
26 | { | |
27 | public: | |
28 | typedef right_open_interval<DomainT,Compare> type; | |
29 | typedef DomainT domain_type; | |
30 | typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; | |
31 | ||
32 | public: | |
33 | //========================================================================== | |
34 | //= Construct, copy, destruct | |
35 | //========================================================================== | |
36 | /** Default constructor; yields an empty interval <tt>[0,0)</tt>. */ | |
1e59de90 TL |
37 | right_open_interval() |
38 | : _lwb(identity_element<DomainT>::value()), _upb(identity_element<DomainT>::value()) | |
7c673cae FG |
39 | { |
40 | BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>)); | |
41 | BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>)); | |
42 | } | |
43 | ||
44 | //NOTE: Compiler generated copy constructor is used | |
45 | ||
46 | /** Constructor for a singleton interval <tt>[val,val+1)</tt> */ | |
47 | explicit right_open_interval(const DomainT& val) | |
48 | : _lwb(val), _upb(icl::successor<DomainT,domain_compare>::apply(val)) | |
49 | { | |
50 | BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>)); | |
51 | BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>)); | |
1e59de90 | 52 | // Only for discrete types this ctor creates an interval containing |
7c673cae FG |
53 | // a single element only. |
54 | BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value)); | |
55 | } | |
56 | ||
57 | /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */ | |
58 | right_open_interval(const DomainT& low, const DomainT& up) : | |
59 | _lwb(low), _upb(up) | |
60 | { | |
61 | BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>)); | |
62 | BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>)); | |
63 | } | |
64 | ||
65 | domain_type lower()const{ return _lwb; } | |
66 | domain_type upper()const{ return _upb; } | |
67 | ||
68 | private: | |
69 | domain_type _lwb; | |
70 | domain_type _upb; | |
71 | }; | |
72 | ||
73 | //============================================================================== | |
74 | //=T right_open_interval -> concept intervals | |
75 | //============================================================================== | |
76 | template<class DomainT, ICL_COMPARE Compare> | |
77 | struct interval_traits< icl::right_open_interval<DomainT, Compare> > | |
78 | { | |
79 | typedef DomainT domain_type; | |
80 | typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; | |
81 | typedef icl::right_open_interval<DomainT, Compare> interval_type; | |
82 | ||
83 | static interval_type construct(const domain_type& lo, const domain_type& up) | |
84 | { | |
85 | return interval_type(lo, up); | |
86 | } | |
87 | ||
f67539c2 TL |
88 | static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); } |
89 | static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); } | |
7c673cae FG |
90 | }; |
91 | ||
92 | ||
93 | //============================================================================== | |
94 | //= Type traits | |
95 | //============================================================================== | |
1e59de90 | 96 | template <class DomainT, ICL_COMPARE Compare> |
7c673cae FG |
97 | struct interval_bound_type< right_open_interval<DomainT,Compare> > |
98 | { | |
99 | typedef interval_bound_type type; | |
100 | BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_right_open); | |
101 | }; | |
102 | ||
103 | template <class DomainT, ICL_COMPARE Compare> | |
104 | struct type_to_string<icl::right_open_interval<DomainT,Compare> > | |
105 | { | |
106 | static std::string apply() | |
107 | { return "[I)<"+ type_to_string<DomainT>::apply() +">"; } | |
108 | }; | |
109 | ||
1e59de90 | 110 | template<class DomainT, ICL_COMPARE Compare> |
7c673cae FG |
111 | struct value_size<icl::right_open_interval<DomainT,Compare> > |
112 | { | |
1e59de90 | 113 | static std::size_t apply(const icl::right_open_interval<DomainT>&) |
7c673cae FG |
114 | { return 2; } |
115 | }; | |
116 | ||
117 | }} // namespace icl boost | |
118 | ||
119 | #endif |