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