Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/url
0008 //
0009 
0010 #ifndef BOOST_URL_GRAMMAR_VARIANT_RULE_HPP
0011 #define BOOST_URL_GRAMMAR_VARIANT_RULE_HPP
0012 
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/url/error_types.hpp>
0015 #include <boost/url/variant.hpp>
0016 #include <boost/url/grammar/detail/tuple.hpp>
0017 
0018 namespace boost {
0019 namespace urls {
0020 namespace grammar {
0021 
0022 /** Match one of a set of rules
0023 
0024     Each specified rule is tried in sequence.
0025     When the first match occurs, the result
0026     is stored and returned in the variant. If
0027     no match occurs, an error is returned.
0028 
0029     @par Value Type
0030     @code
0031     using value_type = variant< typename Rules::value_type... >;
0032     @endcode
0033 
0034     @par Example
0035     Rules are used with the function @ref parse.
0036     @code
0037     // request-target = origin-form
0038     //                / absolute-form
0039     //                / authority-form
0040     //                / asterisk-form
0041 
0042     system::result< variant< url_view, url_view, authority_view, core::string_view > > rv = grammar::parse(
0043         "/index.html?width=full",
0044         variant_rule(
0045             origin_form_rule,
0046             absolute_uri_rule,
0047             authority_rule,
0048             delim_rule('*') ) );
0049     @endcode
0050 
0051     @par BNF
0052     @code
0053     variant     = rule1 / rule2 / rule3...
0054     @endcode
0055 
0056     @par Specification
0057     @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#section-3.2"
0058         >3.2.  Alternatives (rfc5234)</a>
0059     @li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-5.3"
0060         >5.3.  Request Target (rfc7230)</a>
0061 
0062     @see
0063         @ref absolute_uri_rule,
0064         @ref authority_rule,
0065         @ref delim_rule,
0066         @ref parse,
0067         @ref origin_form_rule,
0068         @ref url_view.
0069 */
0070 #ifdef BOOST_URL_DOCS
0071 template<class... Rules>
0072 constexpr
0073 __implementation_defined__
0074 variant_rule( Rules... rn ) noexcept;
0075 #else
0076 template<
0077     class R0, class... Rn>
0078 class variant_rule_t
0079 {
0080 public:
0081     using value_type = variant<
0082         typename R0::value_type,
0083         typename Rn::value_type...>;
0084 
0085     auto
0086     parse(
0087         char const*& it,
0088         char const* end) const ->
0089             system::result<value_type>;
0090 
0091     template<
0092         class R0_,
0093         class... Rn_>
0094     friend
0095     constexpr
0096     auto
0097     variant_rule(
0098         R0_ const& r0,
0099         Rn_ const&... rn) noexcept ->
0100             variant_rule_t<R0_, Rn_...>;
0101 
0102 private:
0103     constexpr
0104     variant_rule_t(
0105         R0 const& r0,
0106         Rn const&... rn) noexcept
0107         : rn_(r0, rn...)
0108     {
0109     }
0110 
0111     detail::tuple<R0, Rn...> rn_;
0112 };
0113 
0114 template<
0115     class R0,
0116     class... Rn>
0117 constexpr
0118 auto
0119 variant_rule(
0120     R0 const& r0,
0121     Rn const&... rn) noexcept ->
0122         variant_rule_t<R0, Rn...>;
0123 #endif
0124 
0125 } // grammar
0126 } // urls
0127 } // boost
0128 
0129 #include <boost/url/grammar/impl/variant_rule.hpp>
0130 
0131 #endif