File indexing completed on 2025-01-18 09:53:51
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_VISITOR_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_VISITOR_HPP_EAN_10_04_2005
0010
0011
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015
0016 #include <boost/ref.hpp>
0017 #include <boost/shared_ptr.hpp>
0018 #include <boost/xpressive/detail/detail_fwd.hpp>
0019 #include <boost/xpressive/detail/core/regex_impl.hpp>
0020 #include <boost/xpressive/detail/static/transmogrify.hpp>
0021 #include <boost/xpressive/detail/core/matcher/mark_begin_matcher.hpp>
0022
0023 namespace boost { namespace xpressive { namespace detail
0024 {
0025
0026
0027 template<typename BidiIter>
0028 struct xpression_visitor_base
0029 {
0030 explicit xpression_visitor_base(shared_ptr<regex_impl<BidiIter> > const &self)
0031 : self_(self)
0032 {
0033 }
0034
0035 void swap(xpression_visitor_base<BidiIter> &that)
0036 {
0037 this->self_.swap(that.self_);
0038 }
0039
0040 int get_hidden_mark()
0041 {
0042 return -(int)(++this->self_->hidden_mark_count_);
0043 }
0044
0045 void mark_number(int mark_nbr)
0046 {
0047 if(0 < mark_nbr)
0048 {
0049 this->self_->mark_count_ =
0050 (std::max)(this->self_->mark_count_, (std::size_t)mark_nbr);
0051 }
0052 }
0053
0054 shared_ptr<regex_impl<BidiIter> > &self()
0055 {
0056 return this->self_;
0057 }
0058
0059 protected:
0060
0061 template<typename Matcher>
0062 void visit_(Matcher const &)
0063 {
0064 }
0065
0066 void visit_(reference_wrapper<basic_regex<BidiIter> > const &rex)
0067 {
0068
0069 this->self_->track_reference(*detail::core_access<BidiIter>::get_regex_impl(rex.get()));
0070 }
0071
0072 void visit_(reference_wrapper<basic_regex<BidiIter> const> const &rex)
0073 {
0074
0075 this->self_->track_reference(*detail::core_access<BidiIter>::get_regex_impl(rex.get()));
0076 }
0077
0078 void visit_(tracking_ptr<regex_impl<BidiIter> > const &rex)
0079 {
0080
0081 this->self_->track_reference(*rex.get());
0082 }
0083
0084 void visit_(mark_placeholder const &backref)
0085 {
0086
0087 this->mark_number(backref.mark_number_);
0088 }
0089
0090 void visit_(mark_begin_matcher const &mark_begin)
0091 {
0092
0093 this->mark_number(mark_begin.mark_number_);
0094 }
0095
0096 private:
0097 shared_ptr<regex_impl<BidiIter> > self_;
0098 };
0099
0100
0101
0102 template<typename BidiIter, typename ICase, typename Traits>
0103 struct xpression_visitor
0104 : xpression_visitor_base<BidiIter>
0105 {
0106 typedef BidiIter iterator_type;
0107 typedef ICase icase_type;
0108 typedef Traits traits_type;
0109 typedef typename boost::iterator_value<BidiIter>::type char_type;
0110
0111 explicit xpression_visitor(Traits const &tr, shared_ptr<regex_impl<BidiIter> > const &self)
0112 : xpression_visitor_base<BidiIter>(self)
0113 , traits_(tr)
0114 {
0115 }
0116
0117 template<typename Matcher>
0118 struct apply
0119 {
0120 typedef typename transmogrify<BidiIter, ICase, Traits, Matcher>::type type;
0121 };
0122
0123 template<typename Matcher>
0124 typename apply<Matcher>::type
0125 call(Matcher const &matcher)
0126 {
0127 this->visit_(matcher);
0128 return transmogrify<BidiIter, ICase, Traits, Matcher>::call(matcher, *this);
0129 }
0130
0131 Traits const &traits() const
0132 {
0133 return this->traits_;
0134 }
0135
0136 private:
0137
0138 Traits traits_;
0139 };
0140
0141 }}}
0142
0143 #endif