1 ///////////////////////////////////////////////////////////////////////////////
2 // regex_byref_matcher.hpp
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
16 #include <boost/assert.hpp>
17 #include <boost/mpl/assert.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include <boost/xpressive/regex_error.hpp>
20 #include <boost/xpressive/regex_constants.hpp>
21 #include <boost/xpressive/detail/detail_fwd.hpp>
22 #include <boost/xpressive/detail/core/quant_style.hpp>
23 #include <boost/xpressive/detail/core/state.hpp>
24 #include <boost/xpressive/detail/core/regex_impl.hpp>
25 #include <boost/xpressive/detail/core/adaptor.hpp>
27 namespace boost { namespace xpressive { namespace detail
29 ///////////////////////////////////////////////////////////////////////////////
30 // regex_byref_matcher
32 template<typename BidiIter>
33 struct regex_byref_matcher
34 : quant_style<quant_variable_width, unknown_width::value, false>
36 // avoid cyclic references by holding a weak_ptr to the
38 weak_ptr<regex_impl<BidiIter> > wimpl_;
40 // the basic_regex object holds a ref-count to this regex_impl, so
41 // we don't have to worry about it going away.
42 regex_impl<BidiIter> const *pimpl_;
44 regex_byref_matcher(shared_ptr<regex_impl<BidiIter> > const &impl)
48 BOOST_ASSERT(this->pimpl_);
51 template<typename Next>
52 bool match(match_state<BidiIter> &state, Next const &next) const
54 BOOST_ASSERT(this->pimpl_ == this->wimpl_.lock().get());
55 BOOST_XPR_ENSURE_(this->pimpl_->xpr_, regex_constants::error_badref, "bad regex reference");
57 return push_context_match(*this->pimpl_, state, this->wrap_(next, is_static_xpression<Next>()));
61 template<typename Next>
62 static xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> > wrap_(Next const &next, mpl::true_)
64 // wrap the static xpression in a matchable interface
65 return xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> >(boost::cref(next));
68 template<typename Next>
69 static Next const &wrap_(Next const &next, mpl::false_)