1 /*=============================================================================
2 Copyright (c) 2001-2003 Joel de Guzman
3 http://spirit.sourceforge.net/
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #ifndef BOOST_SPIRIT_RANGE_RUN_HPP
9 #define BOOST_SPIRIT_RANGE_RUN_HPP
11 ///////////////////////////////////////////////////////////////////////////////
14 #include <boost/spirit/home/classic/namespace.hpp>
16 ///////////////////////////////////////////////////////////////////////////////
17 namespace boost { namespace spirit {
19 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
21 namespace utility { namespace impl {
23 ///////////////////////////////////////////////////////////////////////////
27 // Implements a closed range of values. This class is used in
28 // the implementation of the range_run class.
30 // { Low level implementation detail }
31 // { Not to be confused with BOOST_SPIRIT_CLASSIC_NS::range }
33 ///////////////////////////////////////////////////////////////////////////
34 template <typename CharT>
37 range(CharT first, CharT last);
39 bool is_valid() const;
40 bool includes(CharT v) const;
41 bool includes(range const& r) const;
42 bool overlaps(range const& r) const;
43 void merge(range const& r);
49 //////////////////////////////////
50 template <typename CharT>
51 struct range_char_compare {
53 bool operator()(range<CharT> const& x, const CharT y) const
54 { return x.first < y; }
56 bool operator()(const CharT x, range<CharT> const& y) const
57 { return x < y.first; }
59 // This additional operator is required for the checked STL shipped
60 // with VC8 testing the ordering of the iterators passed to the
61 // std::lower_bound algo this range_char_compare<> predicate is passed
63 bool operator()(range<CharT> const& x, range<CharT> const& y) const
64 { return x.first < y.first; }
67 //////////////////////////////////
68 template <typename CharT>
69 struct range_compare {
71 bool operator()(range<CharT> const& x, range<CharT> const& y) const
72 { return x.first < y.first; }
75 ///////////////////////////////////////////////////////////////////////////
79 // An implementation of a sparse bit (boolean) set. The set uses
80 // a sorted vector of disjoint ranges. This class implements the
81 // bare minimum essentials from which the full range of set
82 // operators can be implemented. The set is constructed from
83 // ranges. Internally, adjacent or overlapping ranges are
86 // range_runs are very space-economical in situations where there
87 // are lots of ranges and a few individual disjoint values.
88 // Searching is O(log n) where n is the number of ranges.
90 // { Low level implementation detail }
92 ///////////////////////////////////////////////////////////////////////////
93 template <typename CharT>
98 typedef range<CharT> range_t;
99 typedef std::vector<range_t> run_t;
100 typedef typename run_t::iterator iterator;
101 typedef typename run_t::const_iterator const_iterator;
103 void swap(range_run& rr);
104 bool test(CharT v) const;
105 void set(range_t const& r);
106 void clear(range_t const& r);
109 const_iterator begin() const;
110 const_iterator end() const;
114 void merge(iterator iter, range_t const& r);
121 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
123 }} // namespace BOOST_SPIRIT_CLASSIC_NS::utility::impl
127 #include <boost/spirit/home/classic/utility/impl/chset/range_run.ipp>