SofaBuffers C/C++ 0.12.0
API Documentation
Loading...
Searching...
No Matches
sofab::DynCap Class Reference

A CORELIB_PLAN §6.2.1 receiver cap, exactly as the caller states it. More...

#include <sofab.hpp>

Public Member Functions

constexpr DynCap () noexcept=default
 The unstated cap: missing, not unlimited.
 
constexpr DynCap (std::size_t v) noexcept
 State the cap. v is a maximum: n > v is refused.
 
template<typename T >
requires std::is_signed_v<T>
constexpr DynCap (T)=delete
 Deleted: a signed cap would let -1 re-enter as an unlimited mode.
 
constexpr bool stated () const noexcept
 Whether the caller stated a number at all.
 
constexpr std::size_t value () const noexcept
 The stated maximum. Meaningless unless stated.
 

Detailed Description

A CORELIB_PLAN §6.2.1 receiver cap, exactly as the caller states it.

§6.2.1 draws a line this type exists to make unforgeable: the provenance of a receiver limit is generated code's, and "there is no unset state and no unlimited mode". A codec "**MUST NOT** hold a limit of its own, <strong>MUST NOT</strong> supply a default for one it was not given, <strong>MUST NOT</strong> read an omitted argument as <em>unlimited</em>".

A long dynCap = -1 parameter breaks the last of those by construction: the sentinel is an omitted argument, and reading it as "no ceiling" is the unlimited mode the clause forbids. This type has no such spelling.

  • a value is stated by constructing from an unsigned count — DynCap{64};
  • a default-constructed DynCap is unstated, which is not "unlimited" but missing. Reaching it on a schema-unbounded field is an error in the call — the caller stated neither a schema bound nor a cap — and is reported as Error::InvalidArgument (§6.3), never decoded uncapped;
  • a signed argument does not compile, so the old -1 cannot be smuggled in as SIZE_MAX, which would be the unlimited mode wearing a new type.

The number is still never held past the comparison it was passed for: a DynCap lives in the caller's collector or on the caller's stack, and this header only reads it.

Definition at line 2022 of file sofab.hpp.

Constructor & Destructor Documentation

◆ DynCap() [1/3]

constexpr sofab::DynCap::DynCap ( )
constexprdefaultnoexcept

The unstated cap: missing, not unlimited.

◆ DynCap() [2/3]

constexpr sofab::DynCap::DynCap ( std::size_t  v)
inlineexplicitconstexprnoexcept

State the cap. v is a maximum: n > v is refused.

Definition at line 2032 of file sofab.hpp.

◆ DynCap() [3/3]

template<typename T >
requires std::is_signed_v<T>
constexpr sofab::DynCap::DynCap ( T  )
explicitconstexprdelete

Deleted: a signed cap would let -1 re-enter as an unlimited mode.

Member Function Documentation

◆ stated()

constexpr bool sofab::DynCap::stated ( ) const
inlineconstexprnoexcept

Whether the caller stated a number at all.

Definition at line 2040 of file sofab.hpp.

Here is the caller graph for this function:

◆ value()

constexpr std::size_t sofab::DynCap::value ( ) const
inlineconstexprnoexcept

The stated maximum. Meaningless unless stated.

Definition at line 2043 of file sofab.hpp.

Here is the caller graph for this function:

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