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_CONTINUOUS_INTERVAL_HPP_JOFA_100327
0009 #define BOOST_ICL_CONTINUOUS_INTERVAL_HPP_JOFA_100327
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/concept/container.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_continuous_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 continuous_interval
0029 {
0030 public:
0031     typedef continuous_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     continuous_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_continuous<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 continuous_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_continuous<DomainT>::value));
0059     }
0060 
0061     /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
0062     continuous_interval(const DomainT& low, const DomainT& up, 
0063                       interval_bounds bounds = interval_bounds::right_open(),
0064                       continuous_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_continuous<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 continuous_interval open     (const DomainT& lo, const DomainT& up){ return continuous_interval(lo, up, interval_bounds::open());      }
0077     static continuous_interval right_open(const DomainT& lo, const DomainT& up){ return continuous_interval(lo, up, interval_bounds::right_open());}
0078     static continuous_interval left_open (const DomainT& lo, const DomainT& up){ return continuous_interval(lo, up, interval_bounds::left_open()); }
0079     static continuous_interval closed   (const DomainT& lo, const DomainT& up){ return continuous_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 //==============================================================================
0089 //=T continuous_interval -> concept interval
0090 //==============================================================================
0091 template<class DomainT, ICL_COMPARE Compare>
0092 struct interval_traits< icl::continuous_interval<DomainT, Compare> >
0093 {
0094     typedef interval_traits type;
0095     typedef DomainT domain_type;
0096     typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0097     typedef icl::continuous_interval<DomainT, Compare> interval_type;
0098 
0099     static interval_type construct(const domain_type& lo, const domain_type& up)
0100     {
0101         return interval_type(lo, up);
0102     }
0103 
0104     static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); }
0105     static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); }
0106 };
0107 
0108 
0109 //==============================================================================
0110 //=T continuous_interval -> concept dynamic_interval
0111 //==============================================================================
0112 template<class DomainT, ICL_COMPARE Compare>
0113 struct dynamic_interval_traits<boost::icl::continuous_interval<DomainT,Compare> >
0114 {
0115     typedef dynamic_interval_traits type;
0116     typedef boost::icl::continuous_interval<DomainT,Compare> interval_type;
0117     typedef DomainT domain_type;
0118     typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0119 
0120     static interval_type construct(const domain_type lo, const domain_type up, interval_bounds bounds)
0121     {
0122         return icl::continuous_interval<DomainT,Compare>(lo, up, bounds,
0123             static_cast<icl::continuous_interval<DomainT,Compare>* >(0) );
0124     }
0125 
0126     static interval_type construct_bounded(const bounded_value<DomainT>& lo, 
0127                                            const bounded_value<DomainT>& up)
0128     {
0129         return  icl::continuous_interval<DomainT,Compare>
0130                 (
0131                     lo.value(), up.value(),
0132                     lo.bound().left() | up.bound().right(),
0133                     static_cast<icl::continuous_interval<DomainT,Compare>* >(0) 
0134                 );
0135     }
0136 };
0137 
0138 //==============================================================================
0139 //= Type traits
0140 //==============================================================================
0141 template <class DomainT, ICL_COMPARE Compare> 
0142 struct interval_bound_type< continuous_interval<DomainT,Compare> >
0143 {
0144     typedef interval_bound_type type;
0145     BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::dynamic);
0146 };
0147 
0148 template <class DomainT, ICL_COMPARE Compare> 
0149 struct is_continuous_interval<continuous_interval<DomainT,Compare> >
0150 {
0151     typedef is_continuous_interval<continuous_interval<DomainT,Compare> > type;
0152     BOOST_STATIC_CONSTANT(bool, value = true);
0153 };
0154 
0155 template <class DomainT, ICL_COMPARE Compare>
0156 struct type_to_string<icl::continuous_interval<DomainT,Compare> >
0157 {
0158     static std::string apply()
0159     { return "cI<"+ type_to_string<DomainT>::apply() +">"; }
0160 };
0161 
0162 template<class DomainT> 
0163 struct value_size<icl::continuous_interval<DomainT> >
0164 {
0165     static std::size_t apply(const icl::continuous_interval<DomainT>&) 
0166     { return 2; }
0167 };
0168 
0169 }} // namespace icl boost
0170 
0171 #endif
0172