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_DYNAMIC_SEQUENCE_HPP_EAN_04_10_2006
9
#define BOOST_XPRESSIVE_DETAIL_DYNAMIC_SEQUENCE_HPP_EAN_04_10_2006
11
// MS compatible compilers support #pragma once
12
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
16
#include <boost/assert.hpp>
17
#include <boost/intrusive_ptr.hpp>
18
#include <boost/xpressive/detail/utility/width.hpp>
19
#include <boost/xpressive/detail/detail_fwd.hpp>
21
namespace boost { namespace xpressive { namespace detail
24
///////////////////////////////////////////////////////////////////////////////
26
template<typename BidiIter>
40
template<typename Matcher>
41
sequence(intrusive_ptr<dynamic_xpression<Matcher, BidiIter> > const &xpr)
42
: pure_(Matcher::pure)
43
, width_(xpr->Matcher::get_width())
44
, quant_(static_cast<quant_enum>(Matcher::quant))
52
template<typename Traits>
53
sequence(intrusive_ptr<dynamic_xpression<alternate_matcher<alternates_vector<BidiIter>, Traits>, BidiIter> > const &xpr)
60
, alternates_(&xpr->alternates_)
69
sequence<BidiIter> &operator +=(sequence<BidiIter> const &that)
75
else if(!that.empty())
77
*this->tail_ = that.head_;
78
this->tail_ = that.tail_;
79
// keep track of sequence width and purity
80
this->width_ += that.width_;
81
this->pure_ = this->pure_ && that.pure_;
87
sequence<BidiIter> &operator |=(sequence<BidiIter> that)
89
BOOST_ASSERT(!this->empty());
90
BOOST_ASSERT(0 != this->alternates_);
92
// Keep track of width and purity
93
if(this->alternates_->empty())
95
this->width_ = that.width_;
96
this->pure_ = that.pure_;
100
this->width_ |= that.width_;
101
this->pure_ = this->pure_ && that.pure_;
104
// through the wonders of reference counting, all alternates_ can share an end_alternate
105
if(!this->alt_end_xpr_)
107
this->alt_end_xpr_ = new alt_end_xpr_type;
110
// terminate each alternate with an alternate_end_matcher
111
that += sequence(this->alt_end_xpr_);
112
this->alternates_->push_back(that.head_);
117
void repeat(quant_spec const &spec)
119
this->xpr().matchable()->repeat(spec, *this);
122
shared_matchable<BidiIter> const &xpr() const
127
detail::width width() const
137
quant_enum quant() const
143
typedef dynamic_xpression<alternate_end_matcher, BidiIter> alt_end_xpr_type;
147
this->quant_ = (!is_unknown(this->width_) && this->pure_)
148
? (!this->width_ ? quant_none : quant_fixed_width)
149
: quant_variable_width;
153
detail::width width_;
155
shared_matchable<BidiIter> head_;
156
shared_matchable<BidiIter> *tail_;
157
intrusive_ptr<alt_end_xpr_type> alt_end_xpr_;
158
alternates_vector<BidiIter> *alternates_;
161
template<typename BidiIter>
162
inline sequence<BidiIter> operator +(sequence<BidiIter> left, sequence<BidiIter> const &right)
164
return left += right;
167
template<typename BidiIter>
168
inline sequence<BidiIter> operator |(sequence<BidiIter> left, sequence<BidiIter> const &right)
170
return left |= right;
173
}}} // namespace boost::xpressive::detail