Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:48

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // regex_byref_matcher.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_BYREF_MATCHER_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <boost/assert.hpp>
0017 #include <boost/mpl/assert.hpp>
0018 #include <boost/shared_ptr.hpp>
0019 #include <boost/xpressive/regex_error.hpp>
0020 #include <boost/xpressive/regex_constants.hpp>
0021 #include <boost/xpressive/detail/detail_fwd.hpp>
0022 #include <boost/xpressive/detail/core/quant_style.hpp>
0023 #include <boost/xpressive/detail/core/state.hpp>
0024 #include <boost/xpressive/detail/core/regex_impl.hpp>
0025 #include <boost/xpressive/detail/core/adaptor.hpp>
0026 
0027 namespace boost { namespace xpressive { namespace detail
0028 {
0029     ///////////////////////////////////////////////////////////////////////////////
0030     // regex_byref_matcher
0031     //
0032     template<typename BidiIter>
0033     struct regex_byref_matcher
0034       : quant_style<quant_variable_width, unknown_width::value, false>
0035     {
0036         // avoid cyclic references by holding a weak_ptr to the
0037         // regex_impl struct
0038         weak_ptr<regex_impl<BidiIter> > wimpl_;
0039 
0040         // the basic_regex object holds a ref-count to this regex_impl, so
0041         // we don't have to worry about it going away.
0042         regex_impl<BidiIter> const *pimpl_;
0043 
0044         regex_byref_matcher(shared_ptr<regex_impl<BidiIter> > const &impl)
0045           : wimpl_(impl)
0046           , pimpl_(impl.get())
0047         {
0048             BOOST_ASSERT(this->pimpl_);
0049         }
0050 
0051         template<typename Next>
0052         bool match(match_state<BidiIter> &state, Next const &next) const
0053         {
0054             BOOST_ASSERT(this->pimpl_ == this->wimpl_.lock().get());
0055             BOOST_XPR_ENSURE_(this->pimpl_->xpr_, regex_constants::error_badref, "bad regex reference");
0056 
0057             return push_context_match(*this->pimpl_, state, this->wrap_(next, is_static_xpression<Next>()));
0058         }
0059 
0060     private:
0061         template<typename Next>
0062         static xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> > wrap_(Next const &next, mpl::true_)
0063         {
0064             // wrap the static xpression in a matchable interface
0065             return xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> >(boost::cref(next));
0066         }
0067 
0068         template<typename Next>
0069         static Next const &wrap_(Next const &next, mpl::false_)
0070         {
0071             return next;
0072         }
0073     };
0074 
0075 }}}
0076 
0077 #endif