Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*-----------------------------------------------------------------------------+    
0002 Copyright (c) 2011-2011: 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_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 //= Selection<IntervalSet|IntervalMap>
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     //CL typedef typename Type::const_iterator const_iterator;
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     //CL typedef typename Type::const_iterator const_iterator;
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     // A part of the unit_trail(key_value)-interval may be found in the container, that
0062     // does not contain key_value. Therefore we have to check for its existence:
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     // A part of the unit_trail(key_value)-interval may be found in the container, that
0084     // does not contain key_value. Therefore we have to check for its existence:
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 // NOTE: find(object, key) won't compile if key is of continuous type that does
0092 // not implement in(de)crementation (e.g. std::string).
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 //= Morphisms
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_;  // hold the first member
0123             
0124             // Go on while touching members are found
0125             it_++; next_++;
0126             while(     next_ != object.end()
0127                     && segmental::is_joinable<Type>(it_, next_) )
0128             { it_++; next_++; }
0129 
0130             // finally we arrive at the end of a sequence of joinable intervals
0131             // and it points to the last member of that sequence
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 }} // namespace boost icl
0146 
0147 #endif
0148 
0149