1 /*-----------------------------------------------------------------------------+ 2 Copyright (c) 2007-2009: Joachim Faulhaber 3 +------------------------------------------------------------------------------+ 4 Distributed under the Boost Software License, Version 1.0. 5 (See accompanying file LICENCE.txt or copy at 6 http://www.boost.org/LICENSE_1_0.txt) 7 +-----------------------------------------------------------------------------*/ 8 #ifndef BOOST_ICL_SEPARATE_INTERVAL_SET_HPP_JOFA_080608 9 #define BOOST_ICL_SEPARATE_INTERVAL_SET_HPP_JOFA_080608 10 11 #include <boost/assert.hpp> 12 #include <boost/icl/type_traits/is_interval_separator.hpp> 13 #include <boost/icl/interval_base_set.hpp> 14 #include <boost/icl/interval_set.hpp> 15 16 namespace boost{namespace icl 17 { 18 19 /** \brief Implements a set as a set of intervals - leaving adjoining intervals separate */ 20 template 21 < 22 typename DomainT, 23 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT), 24 ICL_INTERVAL(ICL_COMPARE) Interval = ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, DomainT, Compare), 25 ICL_ALLOC Alloc = std::allocator 26 > 27 class separate_interval_set: 28 public interval_base_set<separate_interval_set<DomainT,Compare,Interval,Alloc>, 29 DomainT,Compare,Interval,Alloc> 30 { 31 public: 32 typedef separate_interval_set<DomainT,Compare,Interval,Alloc> type; 33 34 typedef interval_base_set<type,DomainT,Compare,Interval,Alloc> base_type; 35 36 typedef type overloadable_type; 37 typedef type key_object_type; 38 39 typedef interval_set<DomainT,Compare,Interval,Alloc> joint_type; 40 41 /// The domain type of the set 42 typedef DomainT domain_type; 43 /// The codomaintype is the same as domain_type 44 typedef DomainT codomain_type; 45 46 /// The element type of the set 47 typedef DomainT element_type; 48 /// The interval type of the set 49 typedef ICL_INTERVAL_TYPE(Interval,DomainT,Compare) interval_type; 50 /// The segment type of the set 51 typedef interval_type segment_type; 52 53 /// Comparison functor for domain values 54 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; 55 /// Comparison functor for intervals 56 typedef exclusive_less_than<interval_type> interval_compare; 57 58 /// Comparison functor for keys 59 typedef exclusive_less_than<interval_type> key_compare; 60 61 /// The allocator type of the set 62 typedef Alloc<interval_type> allocator_type; 63 64 /// allocator type of the corresponding element set 65 typedef Alloc<DomainT> domain_allocator_type; 66 67 /// The corresponding atomized type representing this interval container of elements 68 typedef typename base_type::atomized_type atomized_type; 69 70 /// Container type for the implementation 71 typedef typename base_type::ImplSetT ImplSetT; 72 73 /// key type of the implementing container 74 typedef typename ImplSetT::key_type key_type; 75 /// data type of the implementing container 76 typedef typename ImplSetT::value_type data_type; 77 /// value type of the implementing container 78 typedef typename ImplSetT::value_type value_type; 79 80 /// iterator for iteration over intervals 81 typedef typename ImplSetT::iterator iterator; 82 /// const_iterator for iteration over intervals 83 typedef typename ImplSetT::const_iterator const_iterator; 84 85 enum { fineness = 2 }; 86 87 public: 88 //========================================================================== 89 //= Construct, copy, destruct 90 //========================================================================== 91 /// Default constructor for the empty object separate_interval_set()92 separate_interval_set(): base_type() {} 93 /// Copy constructor separate_interval_set(const separate_interval_set & src)94 separate_interval_set(const separate_interval_set& src): base_type(src) {} 95 96 /// Copy constructor for base_type 97 template<class SubType> separate_interval_set(const interval_base_set<SubType,DomainT,Compare,Interval,Alloc> & src)98 separate_interval_set 99 (const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src) 100 { 101 this->assign(src); 102 } 103 104 /// Constructor for a single element separate_interval_set(const domain_type & elem)105 explicit separate_interval_set(const domain_type& elem): base_type() { this->add(elem); } 106 /// Constructor for a single interval separate_interval_set(const interval_type & itv)107 explicit separate_interval_set(const interval_type& itv): base_type() { this->add(itv); } 108 109 /// Assignment from a base interval_set. 110 template<class SubType> assign(const interval_base_set<SubType,DomainT,Compare,Interval,Alloc> & src)111 void assign(const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src) 112 { 113 this->clear(); 114 this->_set.insert(src.begin(), src.end()); 115 } 116 117 /// Assignment operator for base type 118 template<class SubType> operator =(const interval_base_set<SubType,DomainT,Compare,Interval,Alloc> & src)119 separate_interval_set& operator = 120 (const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src) 121 { 122 this->assign(src); 123 return *this; 124 } 125 126 # ifndef BOOST_ICL_NO_CXX11_RVALUE_REFERENCES 127 //========================================================================== 128 //= Move semantics 129 //========================================================================== 130 131 /// Move constructor separate_interval_set(separate_interval_set && src)132 separate_interval_set(separate_interval_set&& src) 133 : base_type(boost::move(src)) 134 {} 135 136 /// Move assignment operator operator =(separate_interval_set src)137 separate_interval_set& operator = (separate_interval_set src) 138 { 139 base_type::operator=(boost::move(src)); 140 return *this; 141 } 142 //========================================================================== 143 # else 144 145 /// Assignment operator operator =(const separate_interval_set & src)146 separate_interval_set& operator = (const separate_interval_set& src) 147 { 148 base_type::operator=(src); 149 return *this; 150 } 151 152 # endif // BOOST_ICL_NO_CXX11_RVALUE_REFERENCES 153 154 private: 155 // Private functions that shall be accessible by the baseclass: 156 friend class 157 interval_base_set<separate_interval_set<DomainT,Compare,Interval,Alloc>, 158 DomainT,Compare,Interval,Alloc>; 159 handle_inserted(iterator inserted_)160 iterator handle_inserted(iterator inserted_) 161 { 162 return inserted_; 163 } 164 add_over(const interval_type & addend,iterator last_)165 iterator add_over(const interval_type& addend, iterator last_) 166 { 167 return segmental::join_under(*this, addend, last_); 168 } 169 add_over(const interval_type & addend)170 iterator add_over(const interval_type& addend) 171 { 172 return segmental::join_under(*this, addend); 173 } 174 175 } ; 176 177 178 179 //----------------------------------------------------------------------------- 180 // type traits 181 //----------------------------------------------------------------------------- 182 template <class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc> 183 struct is_set<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > 184 { 185 typedef is_set<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > type; 186 BOOST_STATIC_CONSTANT(bool, value = true); 187 }; 188 189 template <class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc> 190 struct is_interval_container<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > 191 { 192 typedef is_interval_container<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > type; 193 BOOST_STATIC_CONSTANT(bool, value = true); 194 }; 195 196 template <class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc> 197 struct is_interval_separator<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > 198 { 199 typedef is_interval_separator<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > type; 200 BOOST_STATIC_CONSTANT(bool, value = true); 201 }; 202 203 //----------------------------------------------------------------------------- 204 // type representation 205 //----------------------------------------------------------------------------- 206 template <class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc> 207 struct type_to_string<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > 208 { applyboost::icl::type_to_string209 static std::string apply() 210 { return "se_itv_set<"+ type_to_string<DomainT>::apply() +">"; } 211 }; 212 213 }} // namespace icl boost 214 215 #endif 216 217 218