File indexing completed on 2025-01-18 09:53:48
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ALTERNATE_MATCHER_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ALTERNATE_MATCHER_HPP_EAN_10_04_2005
0010
0011
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015
0016 #include <boost/version.hpp>
0017 #if BOOST_VERSION <= 103200
0018
0019 namespace boost { namespace fusion
0020 {
0021 namespace detail { struct iterator_root; }
0022 using detail::iterator_root;
0023 }}
0024 #endif
0025
0026 #include <boost/xpressive/detail/detail_fwd.hpp>
0027 #include <boost/xpressive/detail/core/quant_style.hpp>
0028 #include <boost/xpressive/detail/core/state.hpp>
0029 #include <boost/xpressive/detail/dynamic/matchable.hpp>
0030 #include <boost/xpressive/detail/utility/hash_peek_bitset.hpp>
0031 #include <boost/xpressive/detail/utility/algorithm.hpp>
0032 #include <boost/xpressive/detail/utility/any.hpp>
0033
0034 namespace boost { namespace xpressive { namespace detail
0035 {
0036
0037
0038
0039
0040 template<typename BidiIter, typename Next>
0041 struct alt_match_pred
0042 {
0043 alt_match_pred(match_state<BidiIter> &state)
0044 : state_(&state)
0045 {
0046 }
0047
0048 template<typename Xpr>
0049 bool operator ()(Xpr const &xpr) const
0050 {
0051 return xpr.BOOST_NESTED_TEMPLATE push_match<Next>(*this->state_);
0052 }
0053
0054 private:
0055 match_state<BidiIter> *state_;
0056 };
0057
0058
0059
0060
0061 template<typename BidiIter, typename Next>
0062 inline bool alt_match
0063 (
0064 alternates_vector<BidiIter> const &alts, match_state<BidiIter> &state, Next const &
0065 )
0066 {
0067 return detail::any(alts.begin(), alts.end(), alt_match_pred<BidiIter, Next>(state));
0068 }
0069
0070 template<typename Head, typename Tail, typename BidiIter, typename Next>
0071 inline bool alt_match
0072 (
0073 alternates_list<Head, Tail> const &alts, match_state<BidiIter> &state, Next const &
0074 )
0075 {
0076 return fusion::any(alts, alt_match_pred<BidiIter, Next>(state));
0077 }
0078
0079
0080
0081 template<typename Alternates, typename Traits>
0082 struct alternate_matcher
0083 : quant_style<
0084 Alternates::width != unknown_width::value && Alternates::pure ? quant_fixed_width : quant_variable_width
0085 , Alternates::width
0086 , Alternates::pure
0087 >
0088 {
0089 typedef Alternates alternates_type;
0090 typedef typename Traits::char_type char_type;
0091
0092 Alternates alternates_;
0093 mutable hash_peek_bitset<char_type> bset_;
0094
0095 explicit alternate_matcher(Alternates const &alternates = Alternates())
0096 : alternates_(alternates)
0097 , bset_()
0098 {
0099 }
0100
0101 template<typename BidiIter, typename Next>
0102 bool match(match_state<BidiIter> &state, Next const &next) const
0103 {
0104 if(!state.eos() && !this->can_match_(*state.cur_, traits_cast<Traits>(state)))
0105 {
0106 return false;
0107 }
0108
0109 return detail::alt_match(this->alternates_, state, next);
0110 }
0111
0112 detail::width get_width() const
0113 {
0114
0115
0116
0117 BOOST_MPL_ASSERT_RELATION(unknown_width::value, !=, Alternates::width);
0118 return Alternates::width;
0119 }
0120
0121 private:
0122 alternate_matcher &operator =(alternate_matcher const &);
0123
0124 bool can_match_(char_type ch, Traits const &tr) const
0125 {
0126 return this->bset_.test(ch, tr);
0127 }
0128 };
0129
0130 }}}
0131
0132 #endif