Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 // regex_byref_matcher.hpp
|
Chris@16
|
3 //
|
Chris@16
|
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
5 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005
|
Chris@16
|
9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005
|
Chris@16
|
10
|
Chris@16
|
11 // MS compatible compilers support #pragma once
|
Chris@101
|
12 #if defined(_MSC_VER)
|
Chris@16
|
13 # pragma once
|
Chris@16
|
14 #endif
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/assert.hpp>
|
Chris@16
|
17 #include <boost/mpl/assert.hpp>
|
Chris@16
|
18 #include <boost/shared_ptr.hpp>
|
Chris@16
|
19 #include <boost/xpressive/regex_error.hpp>
|
Chris@16
|
20 #include <boost/xpressive/regex_constants.hpp>
|
Chris@16
|
21 #include <boost/xpressive/detail/detail_fwd.hpp>
|
Chris@16
|
22 #include <boost/xpressive/detail/core/quant_style.hpp>
|
Chris@16
|
23 #include <boost/xpressive/detail/core/state.hpp>
|
Chris@16
|
24 #include <boost/xpressive/detail/core/regex_impl.hpp>
|
Chris@16
|
25 #include <boost/xpressive/detail/core/adaptor.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 namespace boost { namespace xpressive { namespace detail
|
Chris@16
|
28 {
|
Chris@16
|
29 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
30 // regex_byref_matcher
|
Chris@16
|
31 //
|
Chris@16
|
32 template<typename BidiIter>
|
Chris@16
|
33 struct regex_byref_matcher
|
Chris@16
|
34 : quant_style<quant_variable_width, unknown_width::value, false>
|
Chris@16
|
35 {
|
Chris@16
|
36 // avoid cyclic references by holding a weak_ptr to the
|
Chris@16
|
37 // regex_impl struct
|
Chris@16
|
38 weak_ptr<regex_impl<BidiIter> > wimpl_;
|
Chris@16
|
39
|
Chris@16
|
40 // the basic_regex object holds a ref-count to this regex_impl, so
|
Chris@16
|
41 // we don't have to worry about it going away.
|
Chris@16
|
42 regex_impl<BidiIter> const *pimpl_;
|
Chris@16
|
43
|
Chris@16
|
44 regex_byref_matcher(shared_ptr<regex_impl<BidiIter> > const &impl)
|
Chris@16
|
45 : wimpl_(impl)
|
Chris@16
|
46 , pimpl_(impl.get())
|
Chris@16
|
47 {
|
Chris@16
|
48 BOOST_ASSERT(this->pimpl_);
|
Chris@16
|
49 }
|
Chris@16
|
50
|
Chris@16
|
51 template<typename Next>
|
Chris@16
|
52 bool match(match_state<BidiIter> &state, Next const &next) const
|
Chris@16
|
53 {
|
Chris@16
|
54 BOOST_ASSERT(this->pimpl_ == this->wimpl_.lock().get());
|
Chris@16
|
55 BOOST_XPR_ENSURE_(this->pimpl_->xpr_, regex_constants::error_badref, "bad regex reference");
|
Chris@16
|
56
|
Chris@16
|
57 return push_context_match(*this->pimpl_, state, this->wrap_(next, is_static_xpression<Next>()));
|
Chris@16
|
58 }
|
Chris@16
|
59
|
Chris@16
|
60 private:
|
Chris@16
|
61 template<typename Next>
|
Chris@16
|
62 static xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> > wrap_(Next const &next, mpl::true_)
|
Chris@16
|
63 {
|
Chris@16
|
64 // wrap the static xpression in a matchable interface
|
Chris@16
|
65 return xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> >(boost::cref(next));
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 template<typename Next>
|
Chris@16
|
69 static Next const &wrap_(Next const &next, mpl::false_)
|
Chris@16
|
70 {
|
Chris@16
|
71 return next;
|
Chris@16
|
72 }
|
Chris@16
|
73 };
|
Chris@16
|
74
|
Chris@16
|
75 }}}
|
Chris@16
|
76
|
Chris@16
|
77 #endif
|