comparison DEPENDENCIES/generic/include/boost/icl/closed_interval.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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_CLOSED_INTERVAL_HPP_JOFA_100324
9 #define BOOST_ICL_CLOSED_INTERVAL_HPP_JOFA_100324
10
11 #include <boost/icl/concept/interval.hpp>
12 #include <boost/icl/type_traits/value_size.hpp>
13 #include <boost/icl/type_traits/type_to_string.hpp>
14
15 namespace boost{namespace icl
16 {
17
18 template <class DomainT,
19 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
20 class closed_interval
21 {
22 public:
23 typedef closed_interval<DomainT,Compare> type;
24 typedef DomainT domain_type;
25 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
26
27 public:
28 //==========================================================================
29 //= Construct, copy, destruct
30 //==========================================================================
31 /** Default constructor; yields an empty interval <tt>[0,0)</tt>. */
32 closed_interval()
33 : _lwb(unit_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
34 {
35 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
36 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
37 BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
38 }
39
40 //NOTE: Compiler generated copy constructor is used
41
42 /** Constructor for a closed singleton interval <tt>[val,val]</tt> */
43 explicit closed_interval(const DomainT& val)
44 : _lwb(val), _upb(val)
45 {
46 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
47 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
48 BOOST_STATIC_ASSERT((!icl::is_continuous<DomainT>::value));
49 }
50
51 /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
52 closed_interval(const DomainT& low, const DomainT& up) :
53 _lwb(low), _upb(up)
54 {
55 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
56 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
57 }
58
59 DomainT lower()const{ return _lwb; }
60 DomainT upper()const{ return _upb; }
61
62 DomainT first()const{ return _lwb; }
63 DomainT last() const{ return _upb; }
64
65 private:
66 DomainT _lwb;
67 DomainT _upb;
68 };
69
70
71 //==============================================================================
72 //=T closed_interval -> concept intervals
73 //==============================================================================
74 template<class DomainT, ICL_COMPARE Compare>
75 struct interval_traits< icl::closed_interval<DomainT, Compare> >
76 {
77 typedef DomainT domain_type;
78 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
79 typedef icl::closed_interval<DomainT, Compare> interval_type;
80
81 static interval_type construct(const domain_type& lo, const domain_type& up)
82 {
83 return interval_type(lo, up);
84 }
85
86 static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); };
87 static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); };
88 };
89
90 //==============================================================================
91 //= Type traits
92 //==============================================================================
93 template <class DomainT, ICL_COMPARE Compare>
94 struct interval_bound_type< closed_interval<DomainT,Compare> >
95 {
96 typedef interval_bound_type type;
97 BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_closed);
98 };
99
100 template <class DomainT, ICL_COMPARE Compare>
101 struct type_to_string<icl::closed_interval<DomainT,Compare> >
102 {
103 static std::string apply()
104 { return "[I]<"+ type_to_string<DomainT>::apply() +">"; }
105 };
106
107 template<class DomainT>
108 struct value_size<icl::closed_interval<DomainT> >
109 {
110 static std::size_t apply(const icl::closed_interval<DomainT>&)
111 { return 2; }
112 };
113
114 }} // namespace icl boost
115
116 #endif
117