xrpld
Loading...
Searching...
No Matches
xrpl::rpc::Handler::Method Class Reference

The function a handler dispatches to. More...

#include <Handler.h>

Collaboration diagram for xrpl::rpc::Handler::Method:

Public Types

using Function = Status (*)(JsonContext&, json::Value&)

Public Member Functions

Status operator() (JsonContext &context, json::Value &result) const
 Call the function.

Static Public Member Functions

template<Function Fn>
static constexpr Method of () noexcept
 Build a Method that calls a given function.

Private Member Functions

constexpr Method (Function fn) noexcept

Private Attributes

Function fn_

Detailed Description

The function a handler dispatches to.

A plain function pointer, not a std::function: every method is a free function known at compile time, so nothing needs to be captured. That keeps Handler a literal type, letting the dispatch table be built and checked at compile time.

of() takes the function as a template argument, and there is no default constructor, so a table entry that omits its method does not compile.

The pointer is not also checked against null, because gcc under -fsanitize=undefined does not fold the address of a function template instantiation in a constant expression. A null check in the table assertion, or a requires clause on Fn, both fail to compile there.

Definition at line 47 of file Handler.h.

Member Typedef Documentation

◆ Function

Definition at line 50 of file Handler.h.

Constructor & Destructor Documentation

◆ Method()

xrpl::rpc::Handler::Method::Method ( Function fn)
explicitconstexprprivatenoexcept

Definition at line 79 of file Handler.h.

Member Function Documentation

◆ of()

template<Function Fn>
constexpr Method xrpl::rpc::Handler::Method::of ( )
staticconstexprnoexcept

Build a Method that calls a given function.

Template Parameters
FnThe function to call.
Returns
The Method.

Definition at line 60 of file Handler.h.

◆ operator()()

Status xrpl::rpc::Handler::Method::operator() ( JsonContext & context,
json::Value & result ) const

Call the function.

Parameters
contextThe request being served.
resultThe object the function writes its reply into.
Returns
The status the function returns.

Definition at line 73 of file Handler.h.

Member Data Documentation

◆ fn_

Function xrpl::rpc::Handler::Method::fn_
private

Definition at line 83 of file Handler.h.