1 ///////////////////////////////////////////////////////////////////////////////
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_ADAPTOR_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_ADAPTOR_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
16 #include <boost/ref.hpp>
17 #include <boost/implicit_cast.hpp>
18 #include <boost/intrusive_ptr.hpp>
19 #include <boost/xpressive/detail/detail_fwd.hpp>
20 #include <boost/xpressive/detail/dynamic/matchable.hpp>
22 namespace boost { namespace xpressive { namespace detail
25 ///////////////////////////////////////////////////////////////////////////////
28 // wrap a static xpression in a matchable interface so it can be stored
29 // in and invoked from a basic_regex object.
30 template<typename Xpr, typename Base>
31 struct xpression_adaptor
32 : Base // either matchable or matchable_ex
34 typedef typename Base::iterator_type iterator_type;
35 typedef typename iterator_value<iterator_type>::type char_type;
39 xpression_adaptor(Xpr const &xpr)
40 #if BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(4))
41 // Ugh, gcc has an optimizer bug which elides this c'tor call
42 // resulting in pure virtual function calls.
43 __attribute__((__noinline__))
49 virtual bool match(match_state<iterator_type> &state) const
51 typedef typename boost::unwrap_reference<Xpr const>::type xpr_type;
52 return implicit_cast<xpr_type &>(this->xpr_).match(state);
55 void link(xpression_linker<char_type> &linker) const
57 this->xpr_.link(linker);
60 void peek(xpression_peeker<char_type> &peeker) const
62 this->xpr_.peek(peeker);
66 xpression_adaptor &operator =(xpression_adaptor const &);
69 ///////////////////////////////////////////////////////////////////////////////
72 template<typename Base, typename Xpr>
73 inline intrusive_ptr<Base const> make_adaptor(Xpr const &xpr)
75 return intrusive_ptr<Base const>(new xpression_adaptor<Xpr, Base>(xpr));
78 }}} // namespace boost::xpressive::detail