Chris@16: /*-----------------------------------------------------------------------------+ Chris@16: Copyright (c) 2010-2010: Joachim Faulhaber Chris@16: +------------------------------------------------------------------------------+ Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENCE.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt) Chris@16: +-----------------------------------------------------------------------------*/ Chris@16: #ifndef BOOST_ICL_INTERVAL_HPP_JOFA_101014 Chris@16: #define BOOST_ICL_INTERVAL_HPP_JOFA_101014 Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost{ namespace icl Chris@16: { Chris@16: Chris@16: template Chris@16: struct static_interval; Chris@16: Chris@16: template Chris@16: struct interval Chris@16: { Chris@16: typedef typename interval_type_default::type interval_type; Chris@16: typedef interval_type type; Chris@16: Chris@16: #ifdef BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS Chris@16: Chris@16: static inline interval_type open(const DomainT& low, const DomainT& up) Chris@16: { Chris@16: return Chris@16: static_interval Chris@16: < interval_type // if the domain_type is discrete ... Chris@16: , is_discrete::domain_type>::value Chris@16: , interval_bounds::static_open // 'pretended' bounds will be transformed to Chris@16: , interval_bound_type::value // the represented bounds Chris@16: > Chris@16: ::construct(low, up); Chris@16: } Chris@16: Chris@16: static inline interval_type left_open(const DomainT& low, const DomainT& up) Chris@16: { Chris@16: return Chris@16: static_interval Chris@16: < interval_type Chris@16: , is_discrete::domain_type>::value Chris@16: , interval_bounds::static_left_open Chris@16: , interval_bound_type::value Chris@16: > Chris@16: ::construct(low, up); Chris@16: } Chris@16: Chris@16: static inline interval_type right_open(const DomainT& low, const DomainT& up) Chris@16: { Chris@16: return Chris@16: static_interval Chris@16: < interval_type Chris@16: , is_discrete::domain_type>::value Chris@16: , interval_bounds::static_right_open Chris@16: , interval_bound_type::value Chris@16: > Chris@16: ::construct(low, up); Chris@16: } Chris@16: Chris@16: static inline interval_type closed(const DomainT& low, const DomainT& up) Chris@16: { Chris@16: return Chris@16: static_interval Chris@16: < interval_type Chris@16: , is_discrete::domain_type>::value Chris@16: , interval_bounds::static_closed Chris@16: , interval_bound_type::value Chris@16: > Chris@16: ::construct(low, up); Chris@16: } Chris@16: Chris@16: static inline interval_type construct(const DomainT& low, const DomainT& up) Chris@16: { return icl::construct(low, up); } Chris@16: Chris@16: #else // ICL_USE_DYNAMIC_INTERVAL_BORDER_DEFAULTS Chris@16: static inline interval_type right_open(const DomainT& low, const DomainT& up) Chris@16: { return icl::construct(low, up, interval_bounds::right_open()); } Chris@16: Chris@16: static inline interval_type left_open(const DomainT& low, const DomainT& up) Chris@16: { return icl::construct(low, up, interval_bounds::left_open()); } Chris@16: Chris@16: static inline interval_type open(const DomainT& low, const DomainT& up) Chris@16: { return icl::construct(low, up, interval_bounds::open()); } Chris@16: Chris@16: static inline interval_type closed(const DomainT& low, const DomainT& up) Chris@16: { return icl::construct(low, up, interval_bounds::closed()); } Chris@16: Chris@16: static inline interval_type construct(const DomainT& low, const DomainT& up) Chris@16: { return icl::construct(low, up); } Chris@16: Chris@16: #endif Chris@16: }; Chris@16: Chris@16: template Chris@16: struct static_interval Chris@16: {// is_discrete> Chris@16: typedef typename interval_traits::domain_type domain_type; Chris@16: Chris@16: static inline IntervalT construct(const domain_type& low, const domain_type& up) Chris@16: { Chris@16: return icl::construct( Chris@16: shift_lower(interval_bounds(PretendedBounds), interval_bounds(RepresentedBounds), low) Chris@16: , shift_upper(interval_bounds(PretendedBounds), interval_bounds(RepresentedBounds), up ) Chris@16: ); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct static_interval Chris@16: {// !is_discrete> Chris@16: typedef typename interval_traits::domain_type domain_type; Chris@16: Chris@16: static inline IntervalT construct(const domain_type& low, const domain_type& up) Chris@16: { Chris@16: BOOST_STATIC_ASSERT((is_discrete::value || PretendedBounds==RepresentedBounds)); Chris@16: // For domain_types that are not discrete, e.g. interval Chris@16: // one of the following must hold: If you call Chris@16: // interval::right_open(x,y) then interval::type must be static_right_open Chris@16: // interval::left_open(x,y) then interval::type must be static_left_open Chris@16: // interval::open(x,y) then interval::type must be static_open Chris@16: // interval::closed(x,y) then interval::type must be static_closed Chris@16: // Conversion between 'PretendedBounds' and 'RepresentedBounds' is only possible Chris@16: // for discrete domain_types. Chris@16: return icl::construct(low, up); Chris@16: } Chris@16: }; Chris@16: Chris@16: }} // namespace boost icl Chris@16: Chris@16: #endif // BOOST_ICL_INTERVAL_HPP_JOFA_101014 Chris@16: