regex_compiler.h: Fix filename in doxygen comment.
[gcc.git] / libstdc++-v3 / include / bits / regex_grep_matcher.h
1 // class template regex -*- C++ -*-
2
3 // Copyright (C) 2010 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /**
26 * @file bits/regex_grep_matcher.h
27 * This is an internal header file, included by other library headers.
28 * You should not attempt to use it directly.
29 */
30
31
32 namespace std
33 {
34 template<typename _BiIter>
35 class sub_match;
36
37 template<typename _Bi_iter, typename _Allocator>
38 class match_results;
39
40 namespace __regex
41 {
42 // A _Results facade specialized for wrapping a templated sub_match.
43 template<typename _FwdIterT, typename _Alloc>
44 class _SpecializedResults
45 : public _Results
46 {
47 public:
48 _SpecializedResults(const _Automaton::_SizeT __size,
49 const _SpecializedCursor<_FwdIterT>& __cursor,
50 match_results<_FwdIterT, _Alloc>& __m);
51
52 void
53 _M_set_pos(int __i, int __j, const _PatternCursor& __pc);
54
55 void
56 _M_set_matched(int __i, bool __is_matched)
57 { _M_results.at(__i).matched = __is_matched; }
58
59 private:
60 match_results<_FwdIterT, _Alloc>& _M_results;
61 };
62
63 template<typename _FwdIterT, typename _Alloc>
64 _SpecializedResults<_FwdIterT, _Alloc>::
65 _SpecializedResults(const _Automaton::_SizeT __size,
66 const _SpecializedCursor<_FwdIterT>& __cursor,
67 match_results<_FwdIterT, _Alloc>& __m)
68 : _M_results(__m)
69 {
70 typedef typename match_results<_FwdIterT, _Alloc>::size_type size_type;
71 _M_results.clear();
72 std::sub_match<_FwdIterT> __sm;
73 __sm.matched = false;
74 size_type __result_count = __size + 2;
75 for (size_type __i = 0; __i < __result_count; ++__i)
76 _M_results.push_back(__sm);
77 _M_results.at(__size+0).first = __cursor._M_begin();
78 _M_results.at(__size+0).second = __cursor._M_begin();
79 _M_results.at(__size+1).first = __cursor._M_end();
80 _M_results.at(__size+1).second = __cursor._M_end();
81 }
82
83 template<typename _FwdIterT, typename _Alloc>
84 void
85 _SpecializedResults<_FwdIterT, _Alloc>::
86 _M_set_pos(int __i, int __j, const _PatternCursor& __pc)
87 {
88 typedef const _SpecializedCursor<_FwdIterT>& _CursorT;
89 _CursorT __c = static_cast<_CursorT>(__pc);
90 if (__j == 0)
91 _M_results.at(__i).first = __c._M_pos();
92 else
93 _M_results.at(__i).second = __c._M_pos()+1;
94 }
95
96 // A stack of states used in evaluating the NFA.
97 typedef std::stack<_StateIdT, std::vector<_StateIdT> > _StateStack;
98
99 // Executes a regular expression NFA/DFA over a range using a variant of
100 // the parallel execution algorithm featured in the grep utility, modified
101 // to use Laurikari tags.
102 class _Grep_matcher
103 {
104 public:
105 _Grep_matcher(_PatternCursor& __p,
106 _Results& __r,
107 const _AutomatonPtr& __automaton,
108 regex_constants::match_flag_type __flags);
109
110 private:
111 _StateSet
112 _M_e_closure(_StateIdT __i);
113
114 _StateSet
115 _M_e_closure(const _StateSet& __s);
116
117 _StateSet
118 _M_e_closure(_StateStack& __stack, const _StateSet& __s);
119
120 private:
121 const std::shared_ptr<_Nfa> _M_nfa;
122 _PatternCursor& _M_pattern;
123 _Results& _M_results;
124 };
125
126 } // namespace __regex
127 } // namespace std
128
129 #include <bits/regex_grep_matcher.tcc>
130
131 /* vim: set ts=8 sw=2 sts=2: */