Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:21

0001 /*-----------------------------------------------------------------------------+
0002 Copyright (c) 2010-2010: Joachim Faulhaber
0003 +------------------------------------------------------------------------------+
0004    Distributed under the Boost Software License, Version 1.0.
0005       (See accompanying file LICENCE.txt or copy at
0006            http://www.boost.org/LICENSE_1_0.txt)
0007 +-----------------------------------------------------------------------------*/
0008 #ifndef BOOST_ICL_DISCRETE_INTERVAL_HPP_JOFA_100403
0009 #define BOOST_ICL_DISCRETE_INTERVAL_HPP_JOFA_100403
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/type_traits/succ_pred.hpp>
0016 #include <boost/icl/concept/interval.hpp>
0017 #include <boost/icl/type_traits/value_size.hpp>
0018 #include <boost/icl/type_traits/type_to_string.hpp>
0019 #include <boost/icl/type_traits/is_continuous.hpp>
0020 #include <boost/icl/type_traits/is_discrete_interval.hpp>
0021 #include <boost/icl/interval_bounds.hpp>
0022 
0023 namespace boost{namespace icl
0024 {
0025 
0026 template <class DomainT, 
0027           ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
0028 class discrete_interval
0029 {
0030 public:
0031     typedef discrete_interval<DomainT,Compare> type;
0032     typedef DomainT domain_type;
0033     typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0034     typedef typename bounded_value<DomainT>::type bounded_domain_type;
0035 
0036 public:
0037     //==========================================================================
0038     //= Construct, copy, destruct
0039     //==========================================================================
0040     /** Default constructor; yields an empty interval <tt>[0,0)</tt>. */
0041     discrete_interval()
0042         : _lwb(identity_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
0043         , _bounds(interval_bounds::right_open())
0044     {
0045         BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0046         BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0047         BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
0048     }
0049 
0050     //NOTE: Compiler generated copy constructor is used
0051 
0052     /** Constructor for a closed singleton interval <tt>[val,val]</tt> */
0053     explicit discrete_interval(const DomainT& val)
0054         : _lwb(val), _upb(val), _bounds(interval_bounds::closed())
0055     {
0056         BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0057         BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0058         BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
0059     }
0060 
0061     /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
0062     discrete_interval(const DomainT& low, const DomainT& up, 
0063                       interval_bounds bounds = interval_bounds::right_open(),
0064                       discrete_interval* = 0)
0065         : _lwb(low), _upb(up), _bounds(bounds)
0066     {
0067         BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0068         BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0069         BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
0070     }
0071 
0072     domain_type     lower()const { return _lwb; }
0073     domain_type     upper()const { return _upb; }
0074     interval_bounds bounds()const{ return _bounds; }
0075 
0076     static discrete_interval open      (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::open());      }
0077     static discrete_interval right_open(const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::right_open());}
0078     static discrete_interval left_open (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::left_open()); }
0079     static discrete_interval closed    (const DomainT& lo, const DomainT& up){ return discrete_interval(lo, up, interval_bounds::closed());    }
0080 
0081 private:
0082     domain_type     _lwb;
0083     domain_type     _upb;
0084     interval_bounds _bounds;
0085 };
0086 
0087 //==============================================================================
0088 //=T discrete_interval -> concept intervals
0089 //==============================================================================
0090 template<class DomainT, ICL_COMPARE Compare>
0091 struct interval_traits< icl::discrete_interval<DomainT, Compare> >
0092 {
0093     typedef interval_traits type;
0094     typedef DomainT domain_type;
0095     typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0096     typedef icl::discrete_interval<DomainT, Compare> interval_type;
0097 
0098     static interval_type construct(const domain_type& lo, const domain_type& up)
0099     {
0100         return interval_type(lo, up);
0101     }
0102 
0103     static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); }
0104     static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); }
0105 };
0106 
0107 //==============================================================================
0108 //=T discrete_interval -> concept dynamic_interval_traits
0109 //==============================================================================
0110 template<class DomainT, ICL_COMPARE Compare>
0111 struct dynamic_interval_traits<boost::icl::discrete_interval<DomainT,Compare> >
0112 {
0113     typedef dynamic_interval_traits type;
0114     typedef boost::icl::discrete_interval<DomainT,Compare> interval_type;
0115     typedef DomainT domain_type;
0116     typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0117 
0118     static interval_type construct(const domain_type& lo, const domain_type& up, interval_bounds bounds)
0119     {
0120         return interval_type(lo, up, bounds, static_cast<interval_type*>(0) );
0121     }
0122 
0123     static interval_type construct_bounded(const bounded_value<DomainT>& lo, 
0124                                            const bounded_value<DomainT>& up)
0125     {
0126         return  interval_type
0127                 (
0128                     lo.value(), up.value(),
0129                     lo.bound().left() | up.bound().right(),
0130                     static_cast<interval_type* >(0) 
0131                 );
0132     }
0133 };
0134 
0135 //==============================================================================
0136 //= Type traits
0137 //==============================================================================
0138 template <class DomainT, ICL_COMPARE Compare> 
0139 struct interval_bound_type< discrete_interval<DomainT,Compare> >
0140 {
0141     typedef interval_bound_type type;
0142     BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::dynamic);
0143 };
0144 
0145 template <class DomainT, ICL_COMPARE Compare> 
0146 struct is_discrete_interval<discrete_interval<DomainT,Compare> >
0147 {
0148     typedef is_discrete_interval<discrete_interval<DomainT,Compare> > type;
0149     BOOST_STATIC_CONSTANT(bool, value = is_discrete<DomainT>::value);
0150 };
0151 
0152 template <class DomainT, ICL_COMPARE Compare>
0153 struct type_to_string<icl::discrete_interval<DomainT,Compare> >
0154 {
0155     static std::string apply()
0156     { return "dI<"+ type_to_string<DomainT>::apply() +">"; }
0157 };
0158 
0159 template<class DomainT> 
0160 struct value_size<icl::discrete_interval<DomainT> >
0161 {
0162     static std::size_t apply(const icl::discrete_interval<DomainT>&) 
0163     { return 2; }
0164 };
0165 
0166 }} // namespace icl boost
0167 
0168 #endif
0169