1 | /*=============================================================================
|
---|
2 | Copyright (c) 2001-2003 Joel de Guzman
|
---|
3 | http://spirit.sourceforge.net/
|
---|
4 |
|
---|
5 | Use, modification and distribution is subject to the Boost Software
|
---|
6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
7 | http://www.boost.org/LICENSE_1_0.txt)
|
---|
8 | =============================================================================*/
|
---|
9 | #ifndef BOOST_SPIRIT_RANGE_RUN_HPP
|
---|
10 | #define BOOST_SPIRIT_RANGE_RUN_HPP
|
---|
11 |
|
---|
12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
13 | #include <vector>
|
---|
14 |
|
---|
15 | ///////////////////////////////////////////////////////////////////////////////
|
---|
16 | namespace boost { namespace spirit { namespace utility { namespace impl {
|
---|
17 |
|
---|
18 | ///////////////////////////////////////////////////////////////////////////
|
---|
19 | //
|
---|
20 | // range class
|
---|
21 | //
|
---|
22 | // Implements a closed range of values. This class is used in
|
---|
23 | // the implementation of the range_run class.
|
---|
24 | //
|
---|
25 | // { Low level implementation detail }
|
---|
26 | // { Not to be confused with boost::spirit::range }
|
---|
27 | //
|
---|
28 | ///////////////////////////////////////////////////////////////////////////
|
---|
29 | template <typename CharT>
|
---|
30 | struct range {
|
---|
31 |
|
---|
32 | range(CharT first, CharT last);
|
---|
33 |
|
---|
34 | bool is_valid() const;
|
---|
35 | bool includes(CharT v) const;
|
---|
36 | bool includes(range const& r) const;
|
---|
37 | bool overlaps(range const& r) const;
|
---|
38 | void merge(range const& r);
|
---|
39 |
|
---|
40 | CharT first;
|
---|
41 | CharT last;
|
---|
42 | };
|
---|
43 |
|
---|
44 | //////////////////////////////////
|
---|
45 | template <typename CharT>
|
---|
46 | struct range_char_compare {
|
---|
47 |
|
---|
48 | bool operator()(range<CharT> const& x, const CharT y) const
|
---|
49 | { return x.first < y; }
|
---|
50 |
|
---|
51 | bool operator()(const CharT x, range<CharT> const& y) const
|
---|
52 | { return x < y.first; }
|
---|
53 |
|
---|
54 | // This additional operator is required for the checked STL shipped
|
---|
55 | // with VC8 testing the ordering of the iterators passed to the
|
---|
56 | // std::lower_bound algo this range_char_compare<> predicate is passed
|
---|
57 | // to.
|
---|
58 | bool operator()(range<CharT> const& x, range<CharT> const& y) const
|
---|
59 | { return x.first < y.first; }
|
---|
60 | };
|
---|
61 |
|
---|
62 | //////////////////////////////////
|
---|
63 | template <typename CharT>
|
---|
64 | struct range_compare {
|
---|
65 |
|
---|
66 | bool operator()(range<CharT> const& x, range<CharT> const& y) const
|
---|
67 | { return x.first < y.first; }
|
---|
68 | };
|
---|
69 |
|
---|
70 | ///////////////////////////////////////////////////////////////////////////
|
---|
71 | //
|
---|
72 | // range_run
|
---|
73 | //
|
---|
74 | // An implementation of a sparse bit (boolean) set. The set uses
|
---|
75 | // a sorted vector of disjoint ranges. This class implements the
|
---|
76 | // bare minimum essentials from which the full range of set
|
---|
77 | // operators can be implemented. The set is constructed from
|
---|
78 | // ranges. Internally, adjacent or overlapping ranges are
|
---|
79 | // coalesced.
|
---|
80 | //
|
---|
81 | // range_runs are very space-economical in situations where there
|
---|
82 | // are lots of ranges and a few individual disjoint values.
|
---|
83 | // Searching is O(log n) where n is the number of ranges.
|
---|
84 | //
|
---|
85 | // { Low level implementation detail }
|
---|
86 | //
|
---|
87 | ///////////////////////////////////////////////////////////////////////////
|
---|
88 | template <typename CharT>
|
---|
89 | class range_run {
|
---|
90 |
|
---|
91 | public:
|
---|
92 |
|
---|
93 | typedef range<CharT> range_t;
|
---|
94 | typedef std::vector<range_t> run_t;
|
---|
95 | typedef typename run_t::iterator iterator;
|
---|
96 | typedef typename run_t::const_iterator const_iterator;
|
---|
97 |
|
---|
98 | void swap(range_run& rr);
|
---|
99 | bool test(CharT v) const;
|
---|
100 | void set(range_t const& r);
|
---|
101 | void clear(range_t const& r);
|
---|
102 | void clear();
|
---|
103 |
|
---|
104 | const_iterator begin() const;
|
---|
105 | const_iterator end() const;
|
---|
106 |
|
---|
107 | private:
|
---|
108 |
|
---|
109 | void merge(iterator iter, range_t const& r);
|
---|
110 |
|
---|
111 | run_t run;
|
---|
112 | };
|
---|
113 |
|
---|
114 | }}}} // namespace boost::spirit::utility::impl
|
---|
115 |
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | #include <boost/spirit/utility/impl/chset/range_run.ipp>
|
---|