os/ossrv/ossrv_pub/boost_apis/boost/xpressive/basic_regex.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/xpressive/basic_regex.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,239 @@
     1.4 +///////////////////////////////////////////////////////////////////////////////
     1.5 +/// \file basic_regex.hpp
     1.6 +/// Contains the definition of the basic_regex\<\> class template and its
     1.7 +/// associated helper functions.
     1.8 +//
     1.9 +//  Copyright 2004 Eric Niebler. Distributed under the Boost
    1.10 +//  Software License, Version 1.0. (See accompanying file
    1.11 +//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    1.12 +
    1.13 +#ifndef BOOST_XPRESSIVE_BASIC_REGEX_HPP_EAN_10_04_2005
    1.14 +#define BOOST_XPRESSIVE_BASIC_REGEX_HPP_EAN_10_04_2005
    1.15 +
    1.16 +// MS compatible compilers support #pragma once
    1.17 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
    1.18 +# pragma once
    1.19 +#endif
    1.20 +
    1.21 +#ifdef BOOST_XPRESSIVE_DEBUG_TRACKING_POINTER
    1.22 +# include <iostream>
    1.23 +#endif
    1.24 +#include <boost/mpl/bool.hpp>
    1.25 +#include <boost/xpressive/proto/proto_fwd.hpp>
    1.26 +#include <boost/xpressive/regex_constants.hpp>
    1.27 +#include <boost/xpressive/detail/detail_fwd.hpp>
    1.28 +#include <boost/xpressive/detail/core/regex_impl.hpp>
    1.29 +
    1.30 +namespace boost { namespace xpressive
    1.31 +{
    1.32 +
    1.33 +///////////////////////////////////////////////////////////////////////////////
    1.34 +// basic_regex
    1.35 +//
    1.36 +/// \brief Class template basic_regex\<\> is a class for holding a compiled regular expression.
    1.37 +template<typename BidiIter>
    1.38 +struct basic_regex
    1.39 +{
    1.40 +    typedef BidiIter iterator_type;
    1.41 +    typedef typename iterator_value<BidiIter>::type char_type;
    1.42 +    typedef std::basic_string<char_type> string_type;
    1.43 +    typedef regex_constants::syntax_option_type flag_type;
    1.44 +
    1.45 +    /// \post regex_id()    == 0
    1.46 +    /// \post mark_count()  == 0
    1.47 +    basic_regex()
    1.48 +      : impl_()
    1.49 +    {
    1.50 +    }
    1.51 +
    1.52 +    /// \param that The basic_regex object to copy.
    1.53 +    /// \post regex_id()    == that.regex_id()
    1.54 +    /// \post mark_count()  == that.mark_count()
    1.55 +    basic_regex(basic_regex<BidiIter> const &that)
    1.56 +      : impl_(that.impl_)
    1.57 +    {
    1.58 +    }
    1.59 +
    1.60 +    /// \param that The basic_regex object to copy.
    1.61 +    /// \post regex_id()    == that.regex_id()
    1.62 +    /// \post mark_count()  == that.mark_count()
    1.63 +    /// \return *this
    1.64 +    basic_regex<BidiIter> &operator =(basic_regex<BidiIter> const &that)
    1.65 +    {
    1.66 +        this->impl_ = that.impl_;
    1.67 +        return *this;
    1.68 +    }
    1.69 +
    1.70 +    /// Construct from a static regular expression.
    1.71 +    ///
    1.72 +    /// \param  xpr The static regular expression
    1.73 +    /// \pre    Xpr is the type of a static regular expression.
    1.74 +    /// \post   regex_id()   != 0
    1.75 +    /// \post   mark_count() \>= 0
    1.76 +    template<typename Xpr>
    1.77 +    basic_regex(Xpr const &xpr)
    1.78 +      : impl_()
    1.79 +    {
    1.80 +        this->operator =(xpr);
    1.81 +    }
    1.82 +
    1.83 +    /// Construct from a static regular expression.
    1.84 +    ///
    1.85 +    /// \param  xpr The static regular expression.
    1.86 +    /// \pre    Xpr is the type of a static regular expression.
    1.87 +    /// \post   regex_id()   != 0
    1.88 +    /// \post   mark_count() \>= 0
    1.89 +    /// \throw  std::bad_alloc on out of memory
    1.90 +    /// \return *this
    1.91 +    template<typename Xpr>
    1.92 +    basic_regex<BidiIter> &operator =(Xpr const &xpr)
    1.93 +    {
    1.94 +        detail::static_compile(xpr, *this->impl_.get());
    1.95 +        return *this;
    1.96 +    }
    1.97 +
    1.98 +    /// Returns the count of capturing sub-expressions in this regular expression
    1.99 +    ///
   1.100 +    std::size_t mark_count() const
   1.101 +    {
   1.102 +        return this->impl_ ? this->impl_->mark_count_ : 0;
   1.103 +    }
   1.104 +
   1.105 +    /// Returns a token which uniquely identifies this regular expression.
   1.106 +    ///
   1.107 +    regex_id_type regex_id() const
   1.108 +    {
   1.109 +        return this->impl_ ? this->impl_->xpr_.get() : 0;
   1.110 +    }
   1.111 +
   1.112 +    /// Swaps the contents of this basic_regex object with another.
   1.113 +    ///
   1.114 +    /// \param      that The other basic_regex object.
   1.115 +    /// \attention  This is a shallow swap that does not do reference tracking. If you embed
   1.116 +    /// a basic_regex object by reference in another regular expression and then swap its
   1.117 +    /// contents with another basic_regex object, the change will not be visible to the enclosing
   1.118 +    /// regular expression. It is done this way to ensure that swap() cannot throw.
   1.119 +    /// \throw nothrow
   1.120 +    void swap(basic_regex<BidiIter> &that) // throw()
   1.121 +    {
   1.122 +        this->impl_.swap(that.impl_);
   1.123 +    }
   1.124 +
   1.125 +    /// Factory method for building a regex object from a string.
   1.126 +    /// Equivalent to regex_compiler\< BidiIter \>().compile(str, flags);
   1.127 +    ///
   1.128 +    /// \param str The std::basic_string containing the regular expression.
   1.129 +    /// \param flags Optional bitmask of type syntax_option_type to control how str is interpreted.
   1.130 +    static basic_regex<BidiIter> compile(string_type const &str, flag_type flags = regex_constants::ECMAScript)
   1.131 +    {
   1.132 +        return regex_compiler<BidiIter>().compile(str, flags);
   1.133 +    }
   1.134 +
   1.135 +    // for binding actions to this regex when it is nested statically in another regex
   1.136 +    /// INTERNAL ONLY
   1.137 +    template<typename Action>
   1.138 +    proto::binary_op
   1.139 +    <
   1.140 +        proto::unary_op<basic_regex<BidiIter>, proto::noop_tag>
   1.141 +      , proto::unary_op<Action, proto::noop_tag>
   1.142 +      , proto::right_shift_tag
   1.143 +    > const
   1.144 +    operator [](detail::action_matcher<Action> const &action) const
   1.145 +    {
   1.146 +        return proto::noop(*this) >> proto::noop(*static_cast<Action const *>(&action));
   1.147 +    }
   1.148 +
   1.149 +    //{{AFX_DEBUG
   1.150 +    #ifdef BOOST_XPRESSIVE_DEBUG_TRACKING_POINTER
   1.151 +    // BUGBUG debug only
   1.152 +    /// INTERNAL ONLY
   1.153 +    friend std::ostream &operator <<(std::ostream &sout, basic_regex<BidiIter> const &rex)
   1.154 +    {
   1.155 +        rex.dump_(sout);
   1.156 +        return sout;
   1.157 +    }
   1.158 +    #endif
   1.159 +    //}}AFX_DEBUG
   1.160 +
   1.161 +private:
   1.162 +    friend struct detail::core_access<BidiIter>;
   1.163 +
   1.164 +    // Avoid a common programming mistake. Construction from a string is ambiguous. It could mean
   1.165 +    //   sregex rx = sregex::compile(str); // compile the string into a regex
   1.166 +    // or
   1.167 +    //   sregex rx = as_xpr(str);          // treat the string as a literal
   1.168 +    // Since there is no easy way to disambiguate, disallow it and force users to say what they mean
   1.169 +    /// INTERNAL ONLY
   1.170 +    basic_regex(char_type const *);
   1.171 +    /// INTERNAL ONLY
   1.172 +    basic_regex(string_type const &);
   1.173 +
   1.174 +    // used from parser, via core_access
   1.175 +    /// INTERNAL ONLY
   1.176 +    explicit basic_regex(detail::regex_impl<BidiIter> const &that)
   1.177 +      : impl_()
   1.178 +    {
   1.179 +        this->impl_.tracking_copy(that);
   1.180 +    }
   1.181 +
   1.182 +    /// INTERNAL ONLY
   1.183 +    bool match_(detail::state_type<BidiIter> &state) const
   1.184 +    {
   1.185 +        return this->impl_->xpr_->match(state);
   1.186 +    }
   1.187 +
   1.188 +    // Returns true if this basic_regex object does not contain a valid regular expression.
   1.189 +    /// INTERNAL ONLY
   1.190 +    bool invalid_() const
   1.191 +    {
   1.192 +        return !this->impl_ || !this->impl_->xpr_;
   1.193 +    }
   1.194 +
   1.195 +    /// INTERNAL ONLY
   1.196 +    void dump_(std::ostream &sout) const;
   1.197 +
   1.198 +    // the tracking_ptr manages lazy-init, COW, cycle-breaking, and
   1.199 +    // reference/dependency tracking.
   1.200 +    detail::tracking_ptr<detail::regex_impl<BidiIter> > impl_;
   1.201 +};
   1.202 +
   1.203 +//{{AFX_DEBUG
   1.204 +#ifdef BOOST_XPRESSIVE_DEBUG_TRACKING_POINTER
   1.205 +///////////////////////////////////////////////////////////////////////////////
   1.206 +// dump_
   1.207 +/// INTERNAL ONLY
   1.208 +template<typename BidiIter>
   1.209 +inline void basic_regex<BidiIter>::dump_(std::ostream &sout) const
   1.210 +{
   1.211 +    if(!this->impl_)
   1.212 +    {
   1.213 +        sout << "<null> refs={} deps={}";
   1.214 +    }
   1.215 +    else
   1.216 +    {
   1.217 +        sout << *this->impl_;
   1.218 +    }
   1.219 +}
   1.220 +#endif
   1.221 +//}}AFX_DEBUG
   1.222 +
   1.223 +///////////////////////////////////////////////////////////////////////////////
   1.224 +// swap
   1.225 +/// \brief      Swaps the contents of two basic_regex objects.
   1.226 +/// \param      left The first basic_regex object.
   1.227 +/// \param      right The second basic_regex object.
   1.228 +/// \attention  This is a shallow swap that does not do reference tracking.
   1.229 +/// If you embed a basic_regex object by reference in another regular expression
   1.230 +/// and then swap its contents with another basic_regex object, the change will
   1.231 +/// not be visible to the enclosing regular expression. It is done this way to
   1.232 +/// ensure that swap() cannot throw.
   1.233 +/// \throw nothrow
   1.234 +template<typename BidiIter>
   1.235 +inline void swap(basic_regex<BidiIter> &left, basic_regex<BidiIter> &right) // throw()
   1.236 +{
   1.237 +    left.swap(right);
   1.238 +}
   1.239 +
   1.240 +}} // namespace boost::xpressive
   1.241 +
   1.242 +#endif // BOOST_XPRESSIVE_REGEX_HPP_EAN_10_04_2005