Boost C++ Libraries

PrevUpHomeNext

Class template operand

boost::taar::matcher::operand — The canonical wrapper around a request matcher.

Synopsis

// In header: <boost/taar/matcher/operand.hpp>

template<typename RequestType, typename CallableType, 
         typename Metadata = any_metadata> 
class operand {
public:
  // types
  typedef RequestType              request_type;   // The Beast request-header type accepted by this matcher. 
  typedef CallableType             callable_type;  // The wrapped callable type. 
  typedef Metadata                 metadata_type;  // The metadata AST that describes this operand's constraint. 
  typedef data_tuple_t< Metadata > captures_type;  // The runtime captures tuple keyed by the metadata's flattened leaf order. 

  // public member functions
  operand(callable_type);
  operand(callable_type, Metadata, captures_type);
  constexpr captures_type const & captures() const noexcept;
  auto operator()(request_type const &, context &, 
                  boost::urls::url_view const &, cookies const &) const;

  // friend functions
  auto operator!(operand);
  template<typename RHSType> auto operator&&(operand, RHSType &&);
  template<typename LHSType> auto operator&&(LHSType &&, operand);
  template<typename RHSType> auto operator||(operand, RHSType &&);
  template<typename LHSType> auto operator||(LHSType &&, operand);

  // public data members
  static constexpr int callabe_kind;
  static constexpr auto with_parsed_target;  // True if the wrapped callable needs the URL-parsed target. 
  static constexpr auto with_parsed_cookies;  // True if the wrapped callable needs the parsed cookie map. 
};

Description

operand adapts an arbitrary callable into the unified matcher interface that session::http uses. The callable may take any of the following parameter packs (after request_type const& and context&):

  • no extra parameters,

  • boost::urls::url_view const& parsed_target,

  • taar::cookies const& parsed_cookies,

  • both, in either order.

operand advertises whether the wrapped callable needs the parsed target and/or parsed cookies through the with_parsed_target and with_parsed_cookies constants, so the session can avoid the parsing cost when no registered matcher needs it.

Instances compose with &&, ||, and unary !. Composition lifts the request type to the super type of the operands and forwards the parsed inputs to whichever side needs them.

In addition to its runtime behaviour, every operand carries a metadata description* of its constraint: the type-level AST (the Metadata template parameter) and a runtime captures tuple (captures_type, accessible via captures). Leaf matchers such as method_t and target_t attach a tag and the captured value at construction time; composition operators combine the tags with and_, or_, not_ and concatenate the captures tuples. See <boost/taar/matcher/metadata.hpp> for the type vocabulary and the rationale.

Users normally do not construct operand directly; matcher placeholders such as method, target, and others produce operands through their relational operators.

Template Parameters

  1. typename RequestType

    The Beast request header type the matcher accepts.

  2. typename CallableType

    The wrapped callable type.

  3. typename Metadata = any_metadata

    The metadata AST node for this operand. Defaults to any_metadata, which means "opaque to introspecting generators".

operand public member functions

  1. operand(callable_type callable);
    Construct from a callable that satisfies the matcher concept.

    This constructor is available only when Metadata is any_metadata, because the operand has no leaf-specific value to capture. Leaf matchers use the metadata-aware constructor instead.

  2. operand(callable_type callable, Metadata, captures_type captures);
    Construct with an explicit metadata description and captures.

    Used by leaf matcher placeholders (e.g. method_t, target_t) and by the composition operators to assemble a new operand whose metadata describes the combined constraint.

    The unnamed second parameter is a value of Metadata. It carries no information at run time; it is passed by value to drive CTAD on the deduction guide.

    Parameters:

    callable

    The wrapped predicate.

    captures

    The captured values for the leaves of Metadata.

  3. constexpr captures_type const & captures() const noexcept;
    The captured values for this operand's metadata leaves.
  4. auto operator()(request_type const & request, context & context, 
                    boost::urls::url_view const & parsed_target, 
                    cookies const & parsed_cookies) const;
    Invoke the wrapped matcher.

    The session always passes the parsed target and the parsed cookies; operands that do not need them ignore the corresponding arguments.

    Parameters:

    request

    The incoming request header.

    context

    Per-request scratch space (see context).

    parsed_target

    The request target after URL parsing.

    parsed_cookies

    The Cookie header parsed into a key/value map.

    Returns:

    true if the request matches.

operand friend functions

  1. auto operator!(operand opr);
    Negate the wrapped matcher.
  2. template<typename RHSType> 
      auto operator&&(operand lhs_operand, RHSType && rhs);
    Short-circuit AND; the right operand is a raw callable.
  3. template<typename LHSType> 
      auto operator&&(LHSType && lhs, operand rhs_operand);
    Short-circuit AND; the left operand is a raw callable.
  4. template<typename RHSType> 
      auto operator||(operand lhs_operand, RHSType && rhs);
    Short-circuit OR; the right operand is a raw callable.
  5. template<typename LHSType> 
      auto operator||(LHSType && lhs, operand rhs_operand);
    Short-circuit OR; the left operand is a raw callable.

PrevUpHomeNext