Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // visitor.hpp Chris@16: // Chris@16: // Copyright 2008 Eric Niebler. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_VISITOR_HPP_EAN_10_04_2005 Chris@16: #define BOOST_XPRESSIVE_DETAIL_STATIC_VISITOR_HPP_EAN_10_04_2005 Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace xpressive { namespace detail Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: template Chris@16: struct xpression_visitor_base Chris@16: { Chris@16: explicit xpression_visitor_base(shared_ptr > const &self) Chris@16: : self_(self) Chris@16: { Chris@16: } Chris@16: Chris@16: void swap(xpression_visitor_base &that) Chris@16: { Chris@16: this->self_.swap(that.self_); Chris@16: } Chris@16: Chris@16: int get_hidden_mark() Chris@16: { Chris@16: return -(int)(++this->self_->hidden_mark_count_); Chris@16: } Chris@16: Chris@16: void mark_number(int mark_nbr) Chris@16: { Chris@16: if(0 < mark_nbr) Chris@16: { Chris@16: this->self_->mark_count_ = Chris@16: (std::max)(this->self_->mark_count_, (std::size_t)mark_nbr); Chris@16: } Chris@16: } Chris@16: Chris@16: shared_ptr > &self() Chris@16: { Chris@16: return this->self_; Chris@16: } Chris@16: Chris@16: protected: Chris@16: Chris@16: template Chris@16: void visit_(Matcher const &) Chris@16: { Chris@16: } Chris@16: Chris@16: void visit_(reference_wrapper > const &rex) Chris@16: { Chris@16: // when visiting an embedded regex, track the references Chris@16: this->self_->track_reference(*detail::core_access::get_regex_impl(rex.get())); Chris@16: } Chris@16: Chris@16: void visit_(reference_wrapper const> const &rex) Chris@16: { Chris@16: // when visiting an embedded regex, track the references Chris@16: this->self_->track_reference(*detail::core_access::get_regex_impl(rex.get())); Chris@16: } Chris@16: Chris@16: void visit_(tracking_ptr > const &rex) Chris@16: { Chris@16: // when visiting an embedded regex, track the references Chris@16: this->self_->track_reference(*rex.get()); Chris@16: } Chris@16: Chris@16: void visit_(mark_placeholder const &backref) Chris@16: { Chris@16: // keep track of the largest mark number found Chris@16: this->mark_number(backref.mark_number_); Chris@16: } Chris@16: Chris@16: void visit_(mark_begin_matcher const &mark_begin) Chris@16: { Chris@16: // keep track of the largest mark number found Chris@16: this->mark_number(mark_begin.mark_number_); Chris@16: } Chris@16: Chris@16: private: Chris@16: shared_ptr > self_; Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: template Chris@16: struct xpression_visitor Chris@16: : xpression_visitor_base Chris@16: { Chris@16: typedef BidiIter iterator_type; Chris@16: typedef ICase icase_type; Chris@16: typedef Traits traits_type; Chris@16: typedef typename boost::iterator_value::type char_type; Chris@16: Chris@16: explicit xpression_visitor(Traits const &tr, shared_ptr > const &self) Chris@16: : xpression_visitor_base(self) Chris@16: , traits_(tr) Chris@16: { Chris@16: } Chris@16: Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: typedef typename transmogrify::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename apply::type Chris@16: call(Matcher const &matcher) Chris@16: { Chris@16: this->visit_(matcher); Chris@16: return transmogrify::call(matcher, *this); Chris@16: } Chris@16: Chris@16: Traits const &traits() const Chris@16: { Chris@16: return this->traits_; Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: Traits traits_; Chris@16: }; Chris@16: Chris@16: }}} Chris@16: Chris@16: #endif