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
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>
16 namespace boost{namespace icl
19 /** \brief Implements a set as a set of intervals - leaving adjoining intervals separate */
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
27 class separate_interval_set:
28 public interval_base_set<separate_interval_set<DomainT,Compare,Interval,Alloc>,
29 DomainT,Compare,Interval,Alloc>
32 typedef separate_interval_set<DomainT,Compare,Interval,Alloc> type;
34 typedef interval_base_set<type,DomainT,Compare,Interval,Alloc> base_type;
36 typedef type overloadable_type;
37 typedef type key_object_type;
39 typedef interval_set<DomainT,Compare,Interval,Alloc> joint_type;
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;
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;
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;
58 /// Comparison functor for keys
59 typedef exclusive_less_than<interval_type> key_compare;
61 /// The allocator type of the set
62 typedef Alloc<interval_type> allocator_type;
64 /// allocator type of the corresponding element set
65 typedef Alloc<DomainT> domain_allocator_type;
67 /// The corresponding atomized type representing this interval container of elements
68 typedef typename base_type::atomized_type atomized_type;
70 /// Container type for the implementation
71 typedef typename base_type::ImplSetT ImplSetT;
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;
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;
85 enum { fineness = 2 };
88 //==========================================================================
89 //= Construct, copy, destruct
90 //==========================================================================
91 /// Default constructor for the empty object
92 separate_interval_set(): base_type() {}
94 separate_interval_set(const separate_interval_set& src): base_type(src) {}
96 /// Copy constructor for base_type
97 template<class SubType>
99 (const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src)
104 /// Constructor for a single element
105 explicit separate_interval_set(const domain_type& elem): base_type() { this->add(elem); }
106 /// Constructor for a single interval
107 explicit separate_interval_set(const interval_type& itv): base_type() { this->add(itv); }
109 /// Assignment from a base interval_set.
110 template<class SubType>
111 void assign(const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src)
114 this->_set.insert(src.begin(), src.end());
117 /// Assignment operator for base type
118 template<class SubType>
119 separate_interval_set& operator =
120 (const interval_base_set<SubType,DomainT,Compare,Interval,Alloc>& src)
126 # ifndef BOOST_ICL_NO_CXX11_RVALUE_REFERENCES
127 //==========================================================================
129 //==========================================================================
132 separate_interval_set(separate_interval_set&& src)
133 : base_type(boost::move(src))
136 /// Move assignment operator
137 separate_interval_set& operator = (separate_interval_set src)
139 base_type::operator=(boost::move(src));
142 //==========================================================================
145 /// Assignment operator
146 separate_interval_set& operator = (const separate_interval_set& src)
148 base_type::operator=(src);
152 # endif // BOOST_ICL_NO_CXX11_RVALUE_REFERENCES
155 // Private functions that shall be accessible by the baseclass:
157 interval_base_set<separate_interval_set<DomainT,Compare,Interval,Alloc>,
158 DomainT,Compare,Interval,Alloc>;
160 iterator handle_inserted(iterator inserted_)
165 iterator add_over(const interval_type& addend, iterator last_)
167 return segmental::join_under(*this, addend, last_);
170 iterator add_over(const interval_type& addend)
172 return segmental::join_under(*this, addend);
179 //-----------------------------------------------------------------------------
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> >
185 typedef is_set<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > type;
186 BOOST_STATIC_CONSTANT(bool, value = true);
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> >
192 typedef is_interval_container<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > type;
193 BOOST_STATIC_CONSTANT(bool, value = true);
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> >
199 typedef is_interval_separator<icl::separate_interval_set<DomainT,Compare,Interval,Alloc> > type;
200 BOOST_STATIC_CONSTANT(bool, value = true);
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> >
209 static std::string apply()
210 { return "se_itv_set<"+ type_to_string<DomainT>::apply() +">"; }
213 }} // namespace icl boost