Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*-----------------------------------------------------------------------------+
0002 Copyright (c) 2007-2012: Joachim Faulhaber
0003 Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
0004 +------------------------------------------------------------------------------+
0005    Distributed under the Boost Software License, Version 1.0.
0006       (See accompanying file LICENCE.txt or copy at
0007            http://www.boost.org/LICENSE_1_0.txt)
0008 +-----------------------------------------------------------------------------*/
0009 #ifndef BOOST_ICL_SPLIT_INTERVAL_MAP_HPP_JOFA_000706
0010 #define BOOST_ICL_SPLIT_INTERVAL_MAP_HPP_JOFA_000706
0011 
0012 #include <boost/icl/interval_set.hpp>
0013 #include <boost/icl/interval_map.hpp>
0014 #include <boost/icl/interval_base_map.hpp>
0015 #include <boost/icl/split_interval_set.hpp>
0016 
0017 namespace boost{namespace icl
0018 {
0019 
0020 /** \brief implements a map as a map of intervals - on insertion 
0021     overlapping intervals are split and associated values are combined. */
0022 template
0023 <
0024     typename DomainT,
0025     typename CodomainT,
0026     class Traits = icl::partial_absorber,
0027     ICL_COMPARE Compare  = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT),
0028     ICL_COMBINE Combine  = ICL_COMBINE_INSTANCE(icl::inplace_plus, CodomainT),
0029     ICL_SECTION Section  = ICL_SECTION_INSTANCE(icl::inter_section, CodomainT), 
0030     ICL_INTERVAL(ICL_COMPARE) Interval = ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, DomainT, Compare),
0031     ICL_ALLOC   Alloc    = std::allocator
0032 >
0033 class split_interval_map:
0034     public interval_base_map<split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>, 
0035                              DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
0036 {
0037 public:
0038     typedef Traits traits;
0039     typedef split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> type;
0040     typedef       interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> joint_type;
0041     typedef type overloadable_type;
0042 
0043     typedef interval_base_map <type, 
0044                                DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> base_type;
0045 
0046     typedef DomainT domain_type;
0047     typedef CodomainT codomain_type;
0048     typedef ICL_INTERVAL_TYPE(Interval,DomainT,Compare) interval_type;
0049     typedef typename base_type::iterator iterator;
0050     typedef typename base_type::value_type value_type;
0051     typedef typename base_type::element_type element_type;
0052     typedef typename base_type::segment_type segment_type;
0053     typedef typename base_type::domain_mapping_type    domain_mapping_type;
0054     typedef typename base_type::interval_mapping_type  interval_mapping_type;
0055     typedef typename base_type::ImplMapT ImplMapT;
0056 
0057     typedef typename base_type::codomain_combine codomain_combine;
0058 
0059     typedef interval_set<DomainT,Compare,Interval,Alloc> interval_set_type;
0060     typedef interval_set_type set_type;
0061     typedef set_type          key_object_type;
0062 
0063     enum { fineness = 3 };
0064 
0065 public:
0066     //==========================================================================
0067     //= Construct, copy, destruct
0068     //==========================================================================
0069     /// Default constructor for the empty object
0070     split_interval_map(): base_type() {}
0071 
0072     /// Copy constructor
0073     split_interval_map(const split_interval_map& src): base_type(src) {}
0074 
0075     explicit split_interval_map(const domain_mapping_type& base_pair): base_type()
0076     { this->add(base_pair); }
0077 
0078     explicit split_interval_map(const value_type& value_pair): base_type()
0079     { this->add(value_pair); }
0080 
0081     /// Assignment from a base interval_map.
0082     template<class SubType>
0083     void assign(const interval_base_map<SubType,DomainT,CodomainT,
0084                                         Traits,Compare,Combine,Section,Interval,Alloc>& src)
0085     {
0086         this->clear();
0087         this->_map.insert(src.begin(), src.end());
0088     }
0089 
0090     /// Assignment operator for base type
0091     template<class SubType>
0092     split_interval_map& operator =
0093         (const interval_base_map<SubType,DomainT,CodomainT,
0094                                  Traits,Compare,Combine,Section,Interval,Alloc>& src)
0095     { 
0096         this->assign(src); 
0097         return *this; 
0098     }
0099 
0100 #   ifndef BOOST_ICL_NO_CXX11_RVALUE_REFERENCES
0101     //==========================================================================
0102     //= Move semantics
0103     //==========================================================================
0104 
0105     /// Move constructor
0106     split_interval_map(split_interval_map&& src)
0107         : base_type(boost::move(src))
0108     {}
0109 
0110     /// Move assignment operator
0111     split_interval_map& operator = (split_interval_map src)
0112     { 
0113         base_type::operator=(boost::move(src));
0114         return *this;
0115     }
0116 
0117     //==========================================================================
0118 #   else
0119 
0120     /// Assignment operator
0121     split_interval_map& operator = (const split_interval_map& src)
0122     { 
0123         base_type::operator=(src);
0124         return *this;
0125     }
0126 
0127 #   endif // BOOST_ICL_NO_CXX11_RVALUE_REFERENCES
0128 
0129 private:
0130     // Private functions that shall be accessible by the baseclass:
0131     friend class
0132         interval_base_map <split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>, 
0133                                               DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>;
0134 
0135     iterator handle_inserted(iterator it_)const { return it_; }
0136     void handle_inserted(iterator, iterator)const{ }
0137 
0138     template<class Combiner>
0139     void handle_left_combined(iterator it_)
0140     {
0141         if(on_absorbtion<type,Combiner,Traits::absorbs_identities>::is_absorbable((*it_).second))
0142             this->_map.erase(it_);
0143     }
0144 
0145     template<class Combiner>
0146     void handle_combined(iterator it_)
0147     {
0148         if(on_absorbtion<type,Combiner,Traits::absorbs_identities>::is_absorbable((*it_).second))
0149             this->_map.erase(it_);
0150     }
0151 
0152     template<class Combiner>
0153     void handle_preceeded_combined(iterator prior_, iterator& it_)
0154     {
0155         if(on_absorbtion<type,Combiner,Traits::absorbs_identities>::is_absorbable((*it_).second))
0156         {
0157             this->_map.erase(it_);
0158             it_ = prior_;
0159         }
0160     }
0161 
0162     template<class Combiner>
0163     void handle_succeeded_combined(iterator it_, iterator)
0164     {
0165         if(on_absorbtion<type,Combiner,Traits::absorbs_identities>::is_absorbable((*it_).second))
0166             this->_map.erase(it_);
0167     }
0168 
0169     void handle_reinserted(iterator){}
0170 
0171     template<class Combiner>
0172     void gap_insert_at(iterator& it_, iterator prior_, 
0173                        const interval_type& end_gap, const codomain_type& co_val)
0174     {
0175         if(on_absorbtion<type,Combiner,Traits::absorbs_identities>::is_absorbable((*it_).second))
0176         {
0177             this->_map.erase(it_);
0178             it_ = this->template gap_insert<Combiner>(prior_, end_gap, co_val);
0179         }
0180         else
0181             it_ = this->template gap_insert<Combiner>(it_, end_gap, co_val);
0182     }
0183 } ;
0184 
0185 //-----------------------------------------------------------------------------
0186 // type traits
0187 //-----------------------------------------------------------------------------
0188 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_INTERVAL(ICL_COMPARE)  Interval, ICL_ALLOC Alloc>
0189 struct is_map<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> >
0190 { 
0191     typedef is_map<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> > type;
0192     BOOST_STATIC_CONSTANT(bool, value = true); 
0193 };
0194 
0195 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_INTERVAL(ICL_COMPARE)  Interval, ICL_ALLOC Alloc>
0196 struct has_inverse<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> >
0197 { 
0198     typedef has_inverse<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> > type;
0199     BOOST_STATIC_CONSTANT(bool, value = (has_inverse<CodomainT>::value)); 
0200 };
0201 
0202 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_INTERVAL(ICL_COMPARE)  Interval, ICL_ALLOC Alloc>
0203 struct is_interval_container<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> >
0204 { 
0205     typedef is_interval_container<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> > type;
0206     BOOST_STATIC_CONSTANT(bool, value = true); 
0207 };
0208 
0209 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_INTERVAL(ICL_COMPARE)  Interval, ICL_ALLOC Alloc>
0210 struct is_interval_splitter<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> >
0211 { 
0212     typedef is_interval_splitter<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> > type;
0213     BOOST_STATIC_CONSTANT(bool, value = true); 
0214 };
0215 
0216 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_INTERVAL(ICL_COMPARE)  Interval, ICL_ALLOC Alloc>
0217 struct absorbs_identities<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> >
0218 { 
0219     typedef absorbs_identities<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> > type;
0220     BOOST_STATIC_CONSTANT(bool, value = (Traits::absorbs_identities)); 
0221 };
0222 
0223 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_INTERVAL(ICL_COMPARE)  Interval, ICL_ALLOC Alloc>
0224 struct is_total<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> >
0225 { 
0226     typedef is_total<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> > type;
0227     BOOST_STATIC_CONSTANT(bool, value = (Traits::is_total)); 
0228 };
0229 
0230 
0231 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_INTERVAL(ICL_COMPARE)  Interval, ICL_ALLOC Alloc>
0232 struct type_to_string<icl::split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc> >
0233 {
0234     static std::string apply()
0235     { 
0236         return "sp_itv_map<"+ type_to_string<DomainT>::apply()   + ","
0237                             + type_to_string<CodomainT>::apply() + ","
0238                             + type_to_string<Traits>::apply()    +">"; 
0239     }
0240 };
0241 
0242 }} // namespace icl boost
0243 
0244 #endif
0245 
0246