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_CORE_REGEX_IMPL_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_REGEX_IMPL_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
17 #include <boost/intrusive_ptr.hpp>
18 #include <boost/xpressive/regex_traits.hpp>
19 #include <boost/xpressive/detail/detail_fwd.hpp>
20 #include <boost/xpressive/detail/dynamic/matchable.hpp>
21 #include <boost/xpressive/detail/utility/tracking_ptr.hpp>
22 #include <boost/xpressive/detail/utility/counted_base.hpp>
24 namespace boost { namespace xpressive { namespace detail
27 ///////////////////////////////////////////////////////////////////////////////
29 template<typename BidiIter>
31 : counted_base<finder<BidiIter> >
34 virtual bool ok_for_partial_matches() const { return true; }
35 virtual bool operator ()(match_state<BidiIter> &state) const = 0;
38 ///////////////////////////////////////////////////////////////////////////////
40 template<typename Char>
42 : counted_base<traits<Char> >
45 virtual Char tolower(Char ch) const = 0;
46 virtual Char toupper(Char ch) const = 0;
47 virtual bool in_range(Char from, Char to, Char ch) const = 0;
48 virtual int value(Char ch, int radix) const = 0;
51 ///////////////////////////////////////////////////////////////////////////////
53 template<typename Char>
56 typedef typename detail::string_type<Char>::type string_type;
58 named_mark(string_type name, std::size_t mark_nbr)
64 std::size_t mark_nbr_;
67 ///////////////////////////////////////////////////////////////////////////////
69 template<typename Traits>
71 : traits<typename Traits::char_type>
73 typedef typename Traits::char_type char_type;
75 explicit traits_holder(Traits const &tr)
80 Traits const &traits() const
85 char_type tolower(char_type ch) const
87 return this->tolower_(ch, typename Traits::version_tag());
90 char_type toupper(char_type ch) const
92 return this->toupper_(ch, typename Traits::version_tag());
95 int value(char_type ch, int radix) const
97 return this->traits_.value(ch, radix);
100 bool in_range(char_type from, char_type to, char_type ch) const
102 return this->traits_.in_range(from, to, ch);
106 char_type tolower_(char_type ch, regex_traits_version_1_tag) const
111 char_type toupper_(char_type ch, regex_traits_version_1_tag) const
116 char_type tolower_(char_type ch, regex_traits_version_2_tag) const
118 return this->traits_.tolower(ch);
121 char_type toupper_(char_type ch, regex_traits_version_2_tag) const
123 return this->traits_.toupper(ch);
129 ///////////////////////////////////////////////////////////////////////////////
132 template<typename BidiIter>
134 : enable_reference_tracking<regex_impl<BidiIter> >
136 typedef typename iterator_value<BidiIter>::type char_type;
139 : enable_reference_tracking<regex_impl<BidiIter> >()
145 , hidden_mark_count_(0)
147 #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
152 regex_impl(regex_impl<BidiIter> const &that)
153 : enable_reference_tracking<regex_impl<BidiIter> >(that)
155 , traits_(that.traits_)
156 , finder_(that.finder_)
157 , named_marks_(that.named_marks_)
158 , mark_count_(that.mark_count_)
159 , hidden_mark_count_(that.hidden_mark_count_)
161 #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
168 #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
173 void swap(regex_impl<BidiIter> &that)
175 enable_reference_tracking<regex_impl<BidiIter> >::swap(that);
176 this->xpr_.swap(that.xpr_);
177 this->traits_.swap(that.traits_);
178 this->finder_.swap(that.finder_);
179 this->named_marks_.swap(that.named_marks_);
180 std::swap(this->mark_count_, that.mark_count_);
181 std::swap(this->hidden_mark_count_, that.hidden_mark_count_);
184 intrusive_ptr<matchable_ex<BidiIter> const> xpr_;
185 intrusive_ptr<traits<char_type> const> traits_;
186 intrusive_ptr<finder<BidiIter> > finder_;
187 std::vector<named_mark<char_type> > named_marks_;
188 std::size_t mark_count_;
189 std::size_t hidden_mark_count_;
191 #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
192 static int instances;
196 regex_impl &operator =(regex_impl const &);
199 template<typename BidiIter>
200 void swap(regex_impl<BidiIter> &left, regex_impl<BidiIter> &right)
205 #ifdef BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
206 template<typename BidiIter>
207 int regex_impl<BidiIter>::instances = 0;
210 }}} // namespace boost::xpressive::detail