Merged revisions 195034,195219,195245,195357,195374,195428,195599,195673,195809 via...
[official-gcc.git] / main / libstdc++-v3 / include / bits / regex_grep_matcher.h
blob8397fc3ce42ed6038761181257162e7b31ba74c0
1 // class template regex -*- C++ -*-
3 // Copyright (C) 2010-2013 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.
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.
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.
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/>.
25 /**
26 * @file bits/regex_grep_matcher.h
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{regex}
31 namespace std _GLIBCXX_VISIBILITY(default)
33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
35 template<typename _BiIter>
36 class sub_match;
38 template<typename _Bi_iter, typename _Allocator>
39 class match_results;
41 _GLIBCXX_END_NAMESPACE_VERSION
43 namespace __detail
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 /**
48 * @defgroup regex-detail Base and Implementation Classes
49 * @ingroup regex
50 * @{
53 /// A _Results facade specialized for wrapping a templated match_results.
54 template<typename _FwdIterT, typename _Alloc>
55 class _SpecializedResults
56 : public _Results
58 public:
59 _SpecializedResults(const _Automaton::_SizeT __size,
60 const _SpecializedCursor<_FwdIterT>& __cursor,
61 match_results<_FwdIterT, _Alloc>& __m);
63 void
64 _M_set_pos(int __i, int __j, const _PatternCursor& __pc);
66 void
67 _M_set_matched(int __i, bool __is_matched)
68 { _M_results.at(__i).matched = __is_matched; }
70 private:
71 match_results<_FwdIterT, _Alloc>& _M_results;
74 template<typename _FwdIterT, typename _Alloc>
75 _SpecializedResults<_FwdIterT, _Alloc>::
76 _SpecializedResults(const _Automaton::_SizeT __size,
77 const _SpecializedCursor<_FwdIterT>& __cursor,
78 match_results<_FwdIterT, _Alloc>& __m)
79 : _M_results(__m)
81 _M_results.clear();
82 _M_results.reserve(__size + 2);
83 _M_results.resize(__size);
84 typename match_results<_FwdIterT, _Alloc>::value_type __sm;
85 __sm.first = __sm.second = __cursor._M_begin();
86 _M_results.push_back(__sm);
87 __sm.first = __sm.second = __cursor._M_end();
88 _M_results.push_back(__sm);
91 template<typename _FwdIterT, typename _Alloc>
92 void
93 _SpecializedResults<_FwdIterT, _Alloc>::
94 _M_set_pos(int __i, int __j, const _PatternCursor& __pc)
96 typedef const _SpecializedCursor<_FwdIterT>& _CursorT;
97 _CursorT __c = static_cast<_CursorT>(__pc);
98 if (__j == 0)
99 _M_results.at(__i).first = __c._M_pos();
100 else
101 _M_results.at(__i).second = __c._M_pos()+1;
104 /// A stack of states used in evaluating the NFA.
105 typedef std::stack<_StateIdT, std::vector<_StateIdT> > _StateStack;
107 /// Executes a regular expression NFA/DFA over a range using a
108 /// variant of the parallel execution algorithm featured in the grep
109 /// utility, modified to use Laurikari tags.
110 class _Grep_matcher
112 public:
113 _Grep_matcher(_PatternCursor& __p,
114 _Results& __r,
115 const _AutomatonPtr& __automaton,
116 regex_constants::match_flag_type __flags);
118 private:
119 _StateSet
120 _M_e_closure(_StateIdT __i);
122 _StateSet
123 _M_e_closure(const _StateSet& __s);
125 _StateSet
126 _M_e_closure(_StateStack& __stack, const _StateSet& __s);
128 const std::shared_ptr<_Nfa> _M_nfa;
129 _PatternCursor& _M_pattern;
130 _Results& _M_results;
133 //@} regex-detail
134 _GLIBCXX_END_NAMESPACE_VERSION
135 } // namespace __detail
136 } // namespace std
138 #include <bits/regex_grep_matcher.tcc>