Botan 3.14.1
Crypto and TLS for C&
Botan::AlgorithmMatch Class Referencefinal

#include <algorithm_spec.h>

Public Member Functions

bool has (std::string_view var) const
std::string_view head () const
size_t integer (std::string_view var) const
const AlgorithmSpec & name (std::string_view var) const
std::span< const AlgorithmSpec > rest (std::string_view var) const
std::string_view str (std::string_view var) const

Friends

class AlgorithmSpec

Detailed Description

The variables bound by a successful AlgorithmSpec::match

Requesting a variable which the pattern does not declare, or with an accessor that does not fit its type, is a programmer error and throws Internal_Error.

Definition at line 234 of file algorithm_spec.h.

Member Function Documentation

◆ has()

bool Botan::AlgorithmMatch::has ( std::string_view var) const
Returns
true if the variable was bound, either from the input or a default

Definition at line 281 of file algorithm_spec.cpp.

281 {
282 for(size_t i = 0; i != m_binding_count; ++i) {
283 if(m_bindings[i].var == var) {
284 return m_bindings[i].bound;
285 }
286 }
287 throw Internal_Error(fmt("AlgorithmMatch::has: no variable '{}' in pattern '{}'", var, m_pattern));
288}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt(), and has().

Referenced by has().

◆ head()

std::string_view Botan::AlgorithmMatch::head ( ) const
inline
Returns
the head of the matched specification, which is useful when the pattern lists several alternatives

Definition at line 240 of file algorithm_spec.h.

240{ return m_head; }

◆ integer()

size_t Botan::AlgorithmMatch::integer ( std::string_view var) const
Returns
the value bound to an int variable

Definition at line 298 of file algorithm_spec.cpp.

298 {
299 const auto& b = bound(var, "integer");
300 if(b.type != AlgorithmPattern::Type::Int) {
301 throw Internal_Error(fmt("AlgorithmMatch::integer: variable '{}' in pattern '{}' is not an int", var, m_pattern));
302 }
303 return b.integer;
304}

References Botan::fmt(), Botan::AlgorithmPattern::Int, and integer().

Referenced by AlgorithmSpec, and integer().

◆ name()

const AlgorithmSpec & Botan::AlgorithmMatch::name ( std::string_view var) const
Returns
the specification bound to a name variable

Definition at line 306 of file algorithm_spec.cpp.

306 {
307 const auto& b = bound(var, "name");
308 if(b.type != AlgorithmPattern::Type::Name || b.variadic || b.node == nullptr) {
309 throw Internal_Error(fmt("AlgorithmMatch::name: variable '{}' in pattern '{}' is not a name", var, m_pattern));
310 }
311 return *b.node;
312}

References AlgorithmSpec, Botan::fmt(), Botan::AlgorithmPattern::Name, and name().

Referenced by name().

◆ rest()

std::span< const AlgorithmSpec > Botan::AlgorithmMatch::rest ( std::string_view var) const
Returns
the specifications bound to a variadic variable

Definition at line 314 of file algorithm_spec.cpp.

314 {
315 const auto& b = bound(var, "rest");
316 if(!b.variadic) {
317 throw Internal_Error(fmt("AlgorithmMatch::rest: variable '{}' in pattern '{}' is not variadic", var, m_pattern));
318 }
319 return b.rest;
320}

References Botan::fmt(), and rest().

Referenced by AlgorithmSpec, and rest().

◆ str()

std::string_view Botan::AlgorithmMatch::str ( std::string_view var) const
Returns
the text bound to a variable of any type

Definition at line 290 of file algorithm_spec.cpp.

290 {
291 const auto& b = bound(var, "str");
292 if(b.variadic) {
293 throw Internal_Error(fmt("AlgorithmMatch::str: variable '{}' in pattern '{}' is variadic", var, m_pattern));
294 }
295 return b.text;
296}

References Botan::fmt(), and str().

Referenced by str().

◆ AlgorithmSpec

friend class AlgorithmSpec
friend

Definition at line 268 of file algorithm_spec.h.

References AlgorithmSpec, integer(), Botan::AlgorithmPattern::Name, rest(), and text.

Referenced by AlgorithmSpec, and name().


The documentation for this class was generated from the following files: