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