File indexing completed on 2025-01-30 09:43:57
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_ICL_CLOSED_INTERVAL_HPP_JOFA_100324
0009 #define BOOST_ICL_CLOSED_INTERVAL_HPP_JOFA_100324
0010
0011 #include <functional>
0012 #include <boost/static_assert.hpp>
0013 #include <boost/concept/assert.hpp>
0014 #include <boost/icl/detail/concept_check.hpp>
0015 #include <boost/icl/concept/interval.hpp>
0016 #include <boost/icl/type_traits/succ_pred.hpp>
0017 #include <boost/icl/type_traits/value_size.hpp>
0018 #include <boost/icl/type_traits/type_to_string.hpp>
0019
0020 namespace boost{namespace icl
0021 {
0022
0023 template <class DomainT,
0024 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
0025 class closed_interval
0026 {
0027 public:
0028 typedef closed_interval<DomainT,Compare> type;
0029 typedef DomainT domain_type;
0030 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0031
0032 public:
0033
0034
0035
0036
0037 closed_interval()
0038 : _lwb(unit_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
0039 {
0040 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0041 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0042 BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
0043 }
0044
0045
0046
0047
0048 explicit closed_interval(const DomainT& val)
0049 : _lwb(val), _upb(val)
0050 {
0051 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0052 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0053 BOOST_STATIC_ASSERT((!icl::is_continuous<DomainT>::value));
0054 }
0055
0056
0057 closed_interval(const DomainT& low, const DomainT& up) :
0058 _lwb(low), _upb(up)
0059 {
0060 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0061 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0062 }
0063
0064 DomainT lower()const{ return _lwb; }
0065 DomainT upper()const{ return _upb; }
0066
0067 DomainT first()const{ return _lwb; }
0068 DomainT last() const{ return _upb; }
0069
0070 private:
0071 DomainT _lwb;
0072 DomainT _upb;
0073 };
0074
0075
0076
0077
0078
0079 template<class DomainT, ICL_COMPARE Compare>
0080 struct interval_traits< icl::closed_interval<DomainT, Compare> >
0081 {
0082 typedef DomainT domain_type;
0083 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0084 typedef icl::closed_interval<DomainT, Compare> interval_type;
0085
0086 static interval_type construct(const domain_type& lo, const domain_type& up)
0087 {
0088 return interval_type(lo, up);
0089 }
0090
0091 static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); }
0092 static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); }
0093 };
0094
0095
0096
0097
0098 template <class DomainT, ICL_COMPARE Compare>
0099 struct interval_bound_type< closed_interval<DomainT,Compare> >
0100 {
0101 typedef interval_bound_type type;
0102 BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_closed);
0103 };
0104
0105 template <class DomainT, ICL_COMPARE Compare>
0106 struct type_to_string<icl::closed_interval<DomainT,Compare> >
0107 {
0108 static std::string apply()
0109 { return "[I]<"+ type_to_string<DomainT>::apply() +">"; }
0110 };
0111
0112 template<class DomainT>
0113 struct value_size<icl::closed_interval<DomainT> >
0114 {
0115 static std::size_t apply(const icl::closed_interval<DomainT>&)
0116 { return 2; }
0117 };
0118
0119 }}
0120
0121 #endif