Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:49

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // regex_impl.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_REGEX_IMPL_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_REGEX_IMPL_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <vector>
0017 #include <boost/intrusive_ptr.hpp>
0018 #include <boost/xpressive/regex_traits.hpp>
0019 #include <boost/xpressive/detail/detail_fwd.hpp>
0020 #include <boost/xpressive/detail/dynamic/matchable.hpp>
0021 #include <boost/xpressive/detail/utility/tracking_ptr.hpp>
0022 #include <boost/xpressive/detail/utility/counted_base.hpp>
0023 
0024 namespace boost { namespace xpressive { namespace detail
0025 {
0026 
0027 ///////////////////////////////////////////////////////////////////////////////
0028 // finder
0029 template<typename BidiIter>
0030 struct finder
0031   : counted_base<finder<BidiIter> >
0032 {
0033     virtual ~finder() {}
0034     virtual bool ok_for_partial_matches() const { return true; }
0035     virtual bool operator ()(match_state<BidiIter> &state) const = 0;
0036 };
0037 
0038 ///////////////////////////////////////////////////////////////////////////////
0039 // traits
0040 template<typename Char>
0041 struct traits
0042   : counted_base<traits<Char> >
0043 {
0044     virtual ~traits() {}
0045     virtual Char tolower(Char ch) const = 0;
0046     virtual Char toupper(Char ch) const = 0;
0047     virtual bool in_range(Char from, Char to, Char ch) const = 0;
0048     virtual int value(Char ch, int radix) const = 0;
0049 };
0050 
0051 ///////////////////////////////////////////////////////////////////////////////
0052 // named_mark
0053 template<typename Char>
0054 struct named_mark
0055 {
0056     typedef typename detail::string_type<Char>::type string_type;
0057 
0058     named_mark(string_type name, std::size_t mark_nbr)
0059       : name_(name)
0060       , mark_nbr_(mark_nbr)
0061     {}
0062 
0063     string_type name_;
0064     std::size_t mark_nbr_;
0065 };
0066 
0067 ///////////////////////////////////////////////////////////////////////////////
0068 // traits_holder
0069 template<typename Traits>
0070 struct traits_holder
0071   : traits<typename Traits::char_type>
0072 {
0073     typedef typename Traits::char_type char_type;
0074 
0075     explicit traits_holder(Traits const &tr)
0076       : traits_(tr)
0077     {
0078     }
0079 
0080     Traits const &traits() const
0081     {
0082         return this->traits_;
0083     }
0084 
0085     char_type tolower(char_type ch) const
0086     {
0087         return this->tolower_(ch, typename Traits::version_tag());
0088     }
0089 
0090     char_type toupper(char_type ch) const
0091     {
0092         return this->toupper_(ch, typename Traits::version_tag());
0093     }
0094 
0095     int value(char_type ch, int radix) const
0096     {
0097         return this->traits_.value(ch, radix);
0098     }
0099 
0100     bool in_range(char_type from, char_type to, char_type ch) const
0101     {
0102         return this->traits_.in_range(from, to, ch);
0103     }
0104 
0105 private:
0106     char_type tolower_(char_type ch, regex_traits_version_1_tag) const
0107     {
0108         return ch;
0109     }
0110 
0111     char_type toupper_(char_type ch, regex_traits_version_1_tag) const
0112     {
0113         return ch;
0114     }
0115 
0116     char_type tolower_(char_type ch, regex_traits_version_2_tag) const
0117     {
0118         return this->traits_.tolower(ch);
0119     }
0120 
0121     char_type toupper_(char_type ch, regex_traits_version_2_tag) const
0122     {
0123         return this->traits_.toupper(ch);
0124     }
0125 
0126     Traits traits_;
0127 };
0128 
0129 ///////////////////////////////////////////////////////////////////////////////
0130 // regex_impl
0131 //
0132 template<typename BidiIter>
0133 struct regex_impl
0134   : enable_reference_tracking<regex_impl<BidiIter> >
0135 {
0136     typedef typename iterator_value<BidiIter>::type char_type;
0137 
0138     regex_impl()
0139       : enable_reference_tracking<regex_impl<BidiIter> >()
0140       , xpr_()
0141       , traits_()
0142       , finder_()
0143       , named_marks_()
0144       , mark_count_(0)
0145       , hidden_mark_count_(0)
0146     {
0147         #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
0148         ++instances;
0149         #endif
0150     }
0151 
0152     regex_impl(regex_impl<BidiIter> const &that)
0153       : enable_reference_tracking<regex_impl<BidiIter> >(that)
0154       , xpr_(that.xpr_)
0155       , traits_(that.traits_)
0156       , finder_(that.finder_)
0157       , named_marks_(that.named_marks_)
0158       , mark_count_(that.mark_count_)
0159       , hidden_mark_count_(that.hidden_mark_count_)
0160     {
0161         #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
0162         ++instances;
0163         #endif
0164     }
0165 
0166     ~regex_impl()
0167     {
0168         #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
0169         --instances;
0170         #endif
0171     }
0172 
0173     void swap(regex_impl<BidiIter> &that)
0174     {
0175         enable_reference_tracking<regex_impl<BidiIter> >::swap(that);
0176         this->xpr_.swap(that.xpr_);
0177         this->traits_.swap(that.traits_);
0178         this->finder_.swap(that.finder_);
0179         this->named_marks_.swap(that.named_marks_);
0180         std::swap(this->mark_count_, that.mark_count_);
0181         std::swap(this->hidden_mark_count_, that.hidden_mark_count_);
0182     }
0183 
0184     intrusive_ptr<matchable_ex<BidiIter> const> xpr_;
0185     intrusive_ptr<traits<char_type> const> traits_;
0186     intrusive_ptr<finder<BidiIter> > finder_;
0187     std::vector<named_mark<char_type> > named_marks_;
0188     std::size_t mark_count_;
0189     std::size_t hidden_mark_count_;
0190 
0191     #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
0192     static int instances;
0193     #endif
0194 
0195 private:
0196     regex_impl &operator =(regex_impl const &);
0197 };
0198 
0199 template<typename BidiIter>
0200 void swap(regex_impl<BidiIter> &left, regex_impl<BidiIter> &right)
0201 {
0202     left.swap(right);
0203 }
0204 
0205 #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
0206 template<typename BidiIter>
0207 int regex_impl<BidiIter>::instances = 0;
0208 #endif
0209 
0210 }}} // namespace boost::xpressive::detail
0211 
0212 #endif