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_STATIC_VISITOR_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_STATIC_VISITOR_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
16 #include <boost/ref.hpp>
17 #include <boost/shared_ptr.hpp>
18 #include <boost/xpressive/detail/detail_fwd.hpp>
19 #include <boost/xpressive/detail/core/regex_impl.hpp>
20 #include <boost/xpressive/detail/static/transmogrify.hpp>
21 #include <boost/xpressive/detail/core/matcher/mark_begin_matcher.hpp>
23 namespace boost { namespace xpressive { namespace detail
25 ///////////////////////////////////////////////////////////////////////////////
27 template<typename BidiIter>
28 struct xpression_visitor_base
30 explicit xpression_visitor_base(shared_ptr<regex_impl<BidiIter> > const &self)
35 void swap(xpression_visitor_base<BidiIter> &that)
37 this->self_.swap(that.self_);
42 return -(int)(++this->self_->hidden_mark_count_);
45 void mark_number(int mark_nbr)
49 this->self_->mark_count_ =
50 (std::max)(this->self_->mark_count_, (std::size_t)mark_nbr);
54 shared_ptr<regex_impl<BidiIter> > &self()
61 template<typename Matcher>
62 void visit_(Matcher const &)
66 void visit_(reference_wrapper<basic_regex<BidiIter> > const &rex)
68 // when visiting an embedded regex, track the references
69 this->self_->track_reference(*detail::core_access<BidiIter>::get_regex_impl(rex.get()));
72 void visit_(reference_wrapper<basic_regex<BidiIter> const> const &rex)
74 // when visiting an embedded regex, track the references
75 this->self_->track_reference(*detail::core_access<BidiIter>::get_regex_impl(rex.get()));
78 void visit_(tracking_ptr<regex_impl<BidiIter> > const &rex)
80 // when visiting an embedded regex, track the references
81 this->self_->track_reference(*rex.get());
84 void visit_(mark_placeholder const &backref)
86 // keep track of the largest mark number found
87 this->mark_number(backref.mark_number_);
90 void visit_(mark_begin_matcher const &mark_begin)
92 // keep track of the largest mark number found
93 this->mark_number(mark_begin.mark_number_);
97 shared_ptr<regex_impl<BidiIter> > self_;
100 ///////////////////////////////////////////////////////////////////////////////
102 template<typename BidiIter, typename ICase, typename Traits>
103 struct xpression_visitor
104 : xpression_visitor_base<BidiIter>
106 typedef BidiIter iterator_type;
107 typedef ICase icase_type;
108 typedef Traits traits_type;
109 typedef typename boost::iterator_value<BidiIter>::type char_type;
111 explicit xpression_visitor(Traits const &tr, shared_ptr<regex_impl<BidiIter> > const &self)
112 : xpression_visitor_base<BidiIter>(self)
117 template<typename Matcher>
120 typedef typename transmogrify<BidiIter, ICase, Traits, Matcher>::type type;
123 template<typename Matcher>
124 typename apply<Matcher>::type
125 call(Matcher const &matcher)
127 this->visit_(matcher);
128 return transmogrify<BidiIter, ICase, Traits, Matcher>::call(matcher, *this);
131 Traits const &traits() const
133 return this->traits_;