1 /////////////////////////////////////////////////////////////////////////////// 2 // regex_matcher.hpp 3 // 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) 7 8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_MATCHER_HPP_EAN_10_04_2005 9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_MATCHER_HPP_EAN_10_04_2005 10 11 // MS compatible compilers support #pragma once 12 #if defined(_MSC_VER) 13 # pragma once 14 #endif 15 16 #include <boost/mpl/assert.hpp> 17 #include <boost/xpressive/regex_error.hpp> 18 #include <boost/xpressive/regex_constants.hpp> 19 #include <boost/xpressive/detail/core/regex_impl.hpp> 20 #include <boost/xpressive/detail/detail_fwd.hpp> 21 #include <boost/xpressive/detail/core/quant_style.hpp> 22 #include <boost/xpressive/detail/core/state.hpp> 23 #include <boost/xpressive/detail/core/adaptor.hpp> 24 25 namespace boost { namespace xpressive { namespace detail 26 { 27 28 /////////////////////////////////////////////////////////////////////////////// 29 // regex_matcher 30 // 31 template<typename BidiIter> 32 struct regex_matcher 33 : quant_style<quant_variable_width, unknown_width::value, false> 34 { 35 regex_impl<BidiIter> impl_; 36 regex_matcherboost::xpressive::detail::regex_matcher37 regex_matcher(shared_ptr<regex_impl<BidiIter> > const &impl) 38 : impl_() 39 { 40 this->impl_.xpr_ = impl->xpr_; 41 this->impl_.traits_ = impl->traits_; 42 this->impl_.mark_count_ = impl->mark_count_; 43 this->impl_.hidden_mark_count_ = impl->hidden_mark_count_; 44 45 BOOST_XPR_ENSURE_(this->impl_.xpr_, regex_constants::error_badref, "bad regex reference"); 46 } 47 48 template<typename Next> matchboost::xpressive::detail::regex_matcher49 bool match(match_state<BidiIter> &state, Next const &next) const 50 { 51 // regex_matcher is used for embeding a dynamic regex in a static regex. As such, 52 // Next will always point to a static regex. 53 BOOST_MPL_ASSERT((is_static_xpression<Next>)); 54 55 // wrap the static xpression in a matchable interface 56 xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> > adaptor(boost::cref(next)); 57 return push_context_match(this->impl_, state, adaptor); 58 } 59 }; 60 61 }}} 62 63 #endif 64