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_INTERVAL_HPP_JOFA_101014
0009 #define BOOST_ICL_INTERVAL_HPP_JOFA_101014
0010 
0011 
0012 #include <boost/icl/type_traits/interval_type_default.hpp>
0013 
0014 
0015 namespace boost{ namespace icl
0016 {
0017 
0018     template <class IntervalT, bool IsDiscrete, bound_type PretendedBounds, bound_type RepresentedBounds> 
0019     struct static_interval;
0020 
0021     template <class DomainT, ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)> 
0022     struct interval
0023     {
0024         typedef typename interval_type_default<DomainT,Compare>::type interval_type;
0025         typedef interval_type type;
0026 
0027 #ifdef BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS
0028 
0029         static inline interval_type open(const DomainT& low, const DomainT& up)
0030         {
0031             return 
0032                 static_interval
0033                 < interval_type                // if the domain_type is discrete ...
0034                 , is_discrete<typename interval_traits<interval_type>::domain_type>::value
0035                 , interval_bounds::static_open // 'pretended' bounds will be transformed to
0036                 , interval_bound_type<interval_type>::value // the represented bounds
0037                 >
0038                 ::construct(low, up); 
0039         }
0040 
0041         static inline interval_type left_open(const DomainT& low, const DomainT& up)
0042         {
0043             return 
0044                 static_interval
0045                 < interval_type
0046                 , is_discrete<typename interval_traits<interval_type>::domain_type>::value
0047                 , interval_bounds::static_left_open
0048                 , interval_bound_type<interval_type>::value
0049                 >
0050                 ::construct(low, up); 
0051         }
0052 
0053         static inline interval_type right_open(const DomainT& low, const DomainT& up)
0054         {
0055             return 
0056                 static_interval
0057                 < interval_type
0058                 , is_discrete<typename interval_traits<interval_type>::domain_type>::value
0059                 , interval_bounds::static_right_open
0060                 , interval_bound_type<interval_type>::value
0061                 >
0062                 ::construct(low, up); 
0063         }
0064 
0065         static inline interval_type closed(const DomainT& low, const DomainT& up)
0066         {
0067             return 
0068                 static_interval
0069                 < interval_type
0070                 , is_discrete<typename interval_traits<interval_type>::domain_type>::value
0071                 , interval_bounds::static_closed
0072                 , interval_bound_type<interval_type>::value
0073                 >
0074                 ::construct(low, up); 
0075         }
0076 
0077         static inline interval_type construct(const DomainT& low, const DomainT& up)
0078         { return icl::construct<interval_type>(low, up); }
0079 
0080 #else // ICL_USE_DYNAMIC_INTERVAL_BORDER_DEFAULTS
0081         static inline interval_type right_open(const DomainT& low, const DomainT& up)
0082         { return icl::construct<interval_type>(low, up, interval_bounds::right_open()); }
0083 
0084         static inline interval_type left_open(const DomainT& low, const DomainT& up)
0085         { return icl::construct<interval_type>(low, up, interval_bounds::left_open()); }
0086 
0087         static inline interval_type open(const DomainT& low, const DomainT& up)
0088         { return icl::construct<interval_type>(low, up, interval_bounds::open()); }
0089 
0090         static inline interval_type closed(const DomainT& low, const DomainT& up)
0091         { return icl::construct<interval_type>(low, up, interval_bounds::closed()); }
0092 
0093         static inline interval_type construct(const DomainT& low, const DomainT& up)
0094         { return icl::construct<interval_type>(low, up); }
0095 
0096 #endif 
0097     };
0098 
0099     template <class IntervalT, bound_type PretendedBounds, bound_type RepresentedBounds> 
0100     struct static_interval<IntervalT, true, PretendedBounds, RepresentedBounds>
0101     {// is_discrete<domain_type<IntervalT>>
0102         typedef typename interval_traits<IntervalT>::domain_type domain_type;
0103 
0104         static inline IntervalT construct(const domain_type& low, const domain_type& up)
0105         {
0106             return icl::construct<IntervalT>(
0107                   shift_lower(interval_bounds(PretendedBounds), interval_bounds(RepresentedBounds), low)
0108                 , shift_upper(interval_bounds(PretendedBounds), interval_bounds(RepresentedBounds), up )
0109                 ); 
0110         }
0111     };
0112 
0113     template <class IntervalT, bound_type PretendedBounds, bound_type RepresentedBounds> 
0114     struct static_interval<IntervalT, false, PretendedBounds, RepresentedBounds>
0115     {// !is_discrete<domain_type<IntervalT>>
0116         typedef typename interval_traits<IntervalT>::domain_type domain_type;
0117 
0118         static inline IntervalT construct(const domain_type& low, const domain_type& up)
0119         {
0120             BOOST_STATIC_ASSERT((is_discrete<domain_type>::value || PretendedBounds==RepresentedBounds));
0121             // For domain_types that are not discrete, e.g. interval<float> 
0122             // one of the following must hold: If you call
0123             // interval<T>::right_open(x,y) then interval<T>::type must be static_right_open
0124             // interval<T>::left_open(x,y)  then interval<T>::type must be static_left_open
0125             // interval<T>::open(x,y)       then interval<T>::type must be static_open
0126             // interval<T>::closed(x,y)     then interval<T>::type must be static_closed
0127             // Conversion between 'PretendedBounds' and 'RepresentedBounds' is only possible
0128             // for discrete domain_types.
0129             return icl::construct<IntervalT>(low, up);
0130         }
0131     };
0132 
0133 }} // namespace boost icl
0134 
0135 #endif // BOOST_ICL_INTERVAL_HPP_JOFA_101014
0136