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