File indexing completed on 2025-01-18 09:38:18
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_ICL_CONCEPT_INTERVAL_ASSOCIATOR_BASE_HPP_JOFA_110301
0009 #define BOOST_ICL_CONCEPT_INTERVAL_ASSOCIATOR_BASE_HPP_JOFA_110301
0010
0011 #include <boost/icl/type_traits/domain_type_of.hpp>
0012 #include <boost/icl/type_traits/interval_type_of.hpp>
0013 #include <boost/icl/type_traits/is_combinable.hpp>
0014 #include <boost/icl/concept/set_value.hpp>
0015 #include <boost/icl/concept/map_value.hpp>
0016 #include <boost/icl/concept/interval.hpp>
0017
0018 namespace boost{ namespace icl
0019 {
0020
0021
0022
0023
0024 template<class Type> inline
0025 typename enable_if<mpl::and_< is_interval_container<Type>
0026 , is_discrete<typename domain_type_of<Type>::type>
0027 >
0028 , typename Type::const_iterator>::type
0029 find(const Type& object, const typename domain_type_of<Type>::type& key_val)
0030 {
0031
0032 typedef typename Type::interval_type interval_type;
0033 return object.find(icl::detail::unit_trail<interval_type>(key_val));
0034 }
0035
0036 template<class Type> inline
0037 typename enable_if<mpl::and_< is_interval_container<Type>
0038 , is_continuous<typename domain_type_of<Type>::type>
0039 , has_dynamic_bounds<typename interval_type_of<Type>::type>
0040 >
0041 , typename Type::const_iterator>::type
0042 find(const Type& object, const typename domain_type_of<Type>::type& key_val)
0043 {
0044
0045 typedef typename Type::interval_type interval_type;
0046 return object.find(icl::singleton<interval_type>(key_val));
0047 }
0048
0049 template<class Type> inline
0050 typename enable_if<mpl::and_< is_interval_container<Type>
0051 , is_continuous<typename domain_type_of<Type>::type>
0052 , is_static_right_open<typename interval_type_of<Type>::type>
0053 , boost::detail::is_incrementable<typename domain_type_of<Type>::type>
0054 >
0055 , typename Type::const_iterator>::type
0056 find(const Type& object, const typename domain_type_of<Type>::type& key_val)
0057 {
0058 typedef typename Type::const_iterator const_iterator;
0059 typedef typename Type::interval_type interval_type;
0060 const_iterator first_collision = object.lower_bound(icl::detail::unit_trail<interval_type>(key_val));
0061
0062
0063 return ( first_collision == object.end()
0064 || icl::contains(key_value<Type>(first_collision), key_val) )
0065 ? first_collision
0066 : object.end();
0067 }
0068
0069 template<class Type> inline
0070 typename enable_if<mpl::and_< is_interval_container<Type>
0071 , is_continuous<typename domain_type_of<Type>::type>
0072 , is_static_left_open<typename interval_type_of<Type>::type>
0073 , boost::detail::is_incrementable<typename domain_type_of<Type>::type>
0074 >
0075 , typename Type::const_iterator>::type
0076 find(const Type& object, const typename domain_type_of<Type>::type& key_val)
0077 {
0078 typedef typename Type::const_iterator const_iterator;
0079 typedef typename Type::interval_type interval_type;
0080 const_iterator last_collision = object.upper_bound(icl::detail::unit_trail<interval_type>(key_val));
0081 if(last_collision != object.begin())
0082 --last_collision;
0083
0084
0085 return ( last_collision == object.end()
0086 || icl::contains(key_value<Type>(last_collision), key_val) )
0087 ? last_collision
0088 : object.end();
0089 }
0090
0091
0092
0093
0094 template<class Type> inline
0095 typename enable_if< is_interval_container<Type>
0096 , typename Type::const_iterator>::type
0097 find(const Type& object, const typename interval_type_of<Type>::type& inter_val)
0098 {
0099 return object.find(inter_val);
0100 }
0101
0102
0103
0104
0105 template<class Type>
0106 typename enable_if<is_interval_container<Type>, Type>::type&
0107 join(Type& object)
0108 {
0109 typedef typename Type::interval_type interval_type;
0110 typedef typename Type::iterator iterator;
0111
0112 iterator it_ = object.begin();
0113 if(it_ == object.end())
0114 return object;
0115
0116 iterator next_ = it_; next_++;
0117
0118 while(next_ != object.end())
0119 {
0120 if( segmental::is_joinable<Type>(it_, next_) )
0121 {
0122 iterator fst_mem = it_;
0123
0124
0125 it_++; next_++;
0126 while( next_ != object.end()
0127 && segmental::is_joinable<Type>(it_, next_) )
0128 { it_++; next_++; }
0129
0130
0131
0132 const_cast<interval_type&>(key_value<Type>(it_))
0133 = hull(key_value<Type>(it_), key_value<Type>(fst_mem));
0134 object.erase(fst_mem, it_);
0135
0136 it_++; next_=it_;
0137 if(next_!=object.end())
0138 next_++;
0139 }
0140 else { it_++; next_++; }
0141 }
0142 return object;
0143 }
0144
0145 }}
0146
0147 #endif
0148
0149