Chris@16: /*-----------------------------------------------------------------------------+ Chris@16: Copyright (c) 2007-2010: Joachim Faulhaber Chris@16: Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin Chris@16: +------------------------------------------------------------------------------+ Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENCE.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt) Chris@16: +-----------------------------------------------------------------------------*/ Chris@16: #ifndef BOOST_ICL_INTERVAL_SET_HPP_JOFA_990223 Chris@16: #define BOOST_ICL_INTERVAL_SET_HPP_JOFA_990223 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost{namespace icl Chris@16: { Chris@16: Chris@16: /** \brief Implements a set as a set of intervals - merging adjoining intervals */ Chris@16: template Chris@16: < Chris@16: typename DomainT, Chris@16: ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT), Chris@16: ICL_INTERVAL(ICL_COMPARE) Interval = ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, DomainT, Compare), Chris@16: ICL_ALLOC Alloc = std::allocator Chris@16: > Chris@16: class interval_set: Chris@16: public interval_base_set, Chris@16: DomainT,Compare,Interval,Alloc> Chris@16: { Chris@16: public: Chris@16: Chris@16: typedef interval_set type; Chris@16: Chris@16: /// The base_type of this class Chris@16: typedef interval_base_set base_type; Chris@16: Chris@16: typedef type overloadable_type; Chris@16: Chris@16: typedef type joint_type; Chris@16: Chris@16: typedef type key_object_type; Chris@16: Chris@16: /// The domain type of the set Chris@16: typedef DomainT domain_type; Chris@16: /// The codomaintype is the same as domain_type Chris@16: typedef DomainT codomain_type; Chris@16: Chris@16: /// The element type of the set Chris@16: typedef DomainT element_type; Chris@16: /// The interval type of the set Chris@16: typedef ICL_INTERVAL_TYPE(Interval,DomainT,Compare) interval_type; Chris@16: /// The segment type of the set Chris@16: typedef interval_type segment_type; Chris@16: Chris@16: /// Comparison functor for domain values Chris@16: typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; Chris@16: /// Comparison functor for intervals Chris@16: typedef exclusive_less_than interval_compare; Chris@16: Chris@16: /// Comparison functor for keys Chris@16: typedef exclusive_less_than key_compare; Chris@16: Chris@16: /// The allocator type of the set Chris@16: typedef Alloc allocator_type; Chris@16: Chris@16: /// allocator type of the corresponding element set Chris@16: typedef Alloc domain_allocator_type; Chris@16: Chris@16: /// The corresponding atomized type representing this interval container of elements Chris@16: typedef typename base_type::atomized_type atomized_type; Chris@16: Chris@16: /// Container type for the implementation Chris@16: typedef typename base_type::ImplSetT ImplSetT; Chris@16: Chris@16: /// key type of the implementing container Chris@16: typedef typename ImplSetT::key_type key_type; Chris@16: /// data type of the implementing container Chris@16: typedef typename ImplSetT::value_type data_type; Chris@16: /// value type of the implementing container Chris@16: typedef typename ImplSetT::value_type value_type; Chris@16: Chris@16: /// iterator for iteration over intervals Chris@16: typedef typename ImplSetT::iterator iterator; Chris@16: /// const_iterator for iteration over intervals Chris@16: typedef typename ImplSetT::const_iterator const_iterator; Chris@16: Chris@16: enum { fineness = 1 }; Chris@16: Chris@16: public: Chris@16: //========================================================================== Chris@16: //= Construct, copy, destruct Chris@16: //========================================================================== Chris@16: /// Default constructor for the empty object Chris@16: interval_set(): base_type() {} Chris@16: Chris@16: /// Copy constructor Chris@16: interval_set(const interval_set& src): base_type(src) {} Chris@16: Chris@16: /// Copy constructor for base_type Chris@16: template Chris@16: explicit interval_set Chris@16: (const interval_base_set& src) Chris@16: { Chris@16: this->assign(src); Chris@16: } Chris@16: Chris@16: /// Constructor for a single element Chris@16: explicit interval_set(const domain_type& value): base_type() Chris@16: { this->add(interval_type(value)); } Chris@16: Chris@16: /// Constructor for a single interval Chris@16: explicit interval_set(const interval_type& itv): base_type() Chris@16: { Chris@16: this->add(itv); Chris@16: } Chris@16: Chris@16: /// Assignment from a base interval_set. Chris@16: template Chris@16: void assign(const interval_base_set& src) Chris@16: { Chris@16: typedef interval_base_set base_set_type; Chris@16: this->clear(); Chris@16: // Has to be implemented via add. there might be touching borders to be joined Chris@16: iterator prior_ = this->_set.end(); Chris@16: ICL_const_FORALL(typename base_set_type, it_, src) Chris@16: prior_ = this->add(prior_, *it_); Chris@16: } Chris@16: Chris@101: /// Assignment operator for base type Chris@101: template Chris@101: interval_set& operator = Chris@101: (const interval_base_set& src) Chris@101: { Chris@101: this->assign(src); Chris@101: return *this; Chris@101: } Chris@101: Chris@16: # ifndef BOOST_ICL_NO_CXX11_RVALUE_REFERENCES Chris@16: //========================================================================== Chris@16: //= Move semantics Chris@16: //========================================================================== Chris@16: Chris@16: /// Move constructor Chris@16: interval_set(interval_set&& src) Chris@16: : base_type(boost::move(src)) Chris@16: {} Chris@16: Chris@16: /// Move assignment operator Chris@101: interval_set& operator = (interval_set src) Chris@16: { Chris@16: base_type::operator=(boost::move(src)); Chris@16: return *this; Chris@16: } Chris@101: Chris@16: //========================================================================== Chris@101: # else Chris@101: /// Assignment operator Chris@101: interval_set& operator = (const interval_set& src) Chris@101: { Chris@101: base_type::operator=(src); Chris@101: return *this; Chris@101: } Chris@101: Chris@16: # endif // BOOST_ICL_NO_CXX11_RVALUE_REFERENCES Chris@16: Chris@16: private: Chris@16: // Private functions that shall be accessible by the baseclass: Chris@16: friend class Chris@16: interval_base_set , Chris@16: DomainT,Compare,Interval,Alloc>; Chris@16: Chris@16: iterator handle_inserted(iterator it_) Chris@16: { Chris@16: return segmental::join_neighbours(*this, it_); Chris@16: } Chris@16: Chris@16: iterator add_over(const interval_type& addend, iterator last_) Chris@16: { Chris@16: iterator joined_ = segmental::join_under(*this, addend, last_); Chris@16: return segmental::join_neighbours(*this, joined_); Chris@16: } Chris@16: Chris@16: iterator add_over(const interval_type& addend) Chris@16: { Chris@16: iterator joined_ = segmental::join_under(*this, addend); Chris@16: return segmental::join_neighbours(*this, joined_); Chris@16: } Chris@16: Chris@16: } ; Chris@16: Chris@16: Chris@16: //----------------------------------------------------------------------------- Chris@16: // type traits Chris@16: //----------------------------------------------------------------------------- Chris@16: template Chris@16: struct is_set > Chris@16: { Chris@16: typedef is_set > type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_interval_container > Chris@16: { Chris@16: typedef is_interval_container > type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_interval_joiner > Chris@16: { Chris@16: typedef is_interval_joiner > type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: Chris@16: //----------------------------------------------------------------------------- Chris@16: // type representation Chris@16: //----------------------------------------------------------------------------- Chris@16: template Chris@16: struct type_to_string > Chris@16: { Chris@16: static std::string apply() Chris@16: { return "itv_set<"+ type_to_string::apply() +">"; } Chris@16: }; Chris@16: Chris@16: }} // namespace icl boost Chris@16: Chris@16: #endif Chris@16: Chris@16: