basic_parser is abstract, not CRTP (API Change):

* `basic_parser` now uses pure virtual member functions instead
  of the curiously recurring template pattern.

Actions Required:

* Change uses of the `basic_parser` type to omit the `Derived`
  template parameter

* Classes derived from `basic_parser` no longer need to friend
  the base.

* Virtual functions in the derived class may be marked `override`.
This commit is contained in:
Vinnie Falco
2019-02-23 06:55:12 -08:00
parent bbd62dd181
commit 59bda5d9c6
33 changed files with 1365 additions and 1236 deletions

View File

@@ -151,11 +151,7 @@ receive_expect_100_continue(
// Read the rest of the message.
//
// We use parser.base() to return a basic_parser&, to avoid an
// ambiguous function error (from boost::asio::read). Another
// solution is to qualify the call, e.g. `beast::http::read`
//
read(stream, buffer, parser.base(), ec);
read(stream, buffer, parser, ec);
}
//]
@@ -875,14 +871,9 @@ do_form_request(
//[example_http_custom_parser
template<bool isRequest>
class custom_parser
: public basic_parser<isRequest, custom_parser<isRequest>>
class custom_parser : public basic_parser<isRequest>
{
private:
// The friend declaration is needed,
// otherwise the callbacks must be made public.
friend class basic_parser<isRequest, custom_parser>;
/// Called after receiving the request-line (isRequest == true).
void
on_request_impl(
@@ -890,7 +881,7 @@ private:
string_view method_str, // The method as a string
string_view target, // The request-target
int version, // The HTTP-version
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called after receiving the start-line (isRequest == false).
void
@@ -898,7 +889,7 @@ private:
int code, // The status-code
string_view reason, // The obsolete reason-phrase
int version, // The HTTP-version
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called after receiving a header field.
void
@@ -906,12 +897,12 @@ private:
field f, // The known-field enumeration constant
string_view name, // The field name string.
string_view value, // The field value
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called after the complete header is received.
void
on_header_impl(
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called just before processing the body, if a body exists.
void
@@ -919,7 +910,7 @@ private:
boost::optional<
std::uint64_t> const&
content_length, // Content length if known, else `boost::none`
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called for each piece of the body, if a body exists.
//!
@@ -932,7 +923,7 @@ private:
std::size_t
on_body_impl(
string_view s, // A portion of the body
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called for each chunk header.
void
@@ -940,7 +931,7 @@ private:
std::uint64_t size, // The size of the upcoming chunk,
// or zero for the last chunk
string_view extension, // The chunk extensions (may be empty)
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called to deliver the chunk body.
//!
@@ -958,11 +949,12 @@ private:
// including what is being passed here.
// or zero for the last chunk
string_view body, // The next piece of the chunk body
error_code& ec); // The error returned to the caller, if any
error_code& ec) override; // The error returned to the caller, if any
/// Called when the complete message is parsed.
void
on_finish_impl(error_code& ec);
on_finish_impl(
error_code& ec) override; // The error returned to the caller, if any
public:
custom_parser() = default;