Pigweed
C/C++ API Reference
|
Public Member Functions | |
constexpr | StatusWithSize () |
Creates a StatusWithSize with status OK and a size of 0. | |
template<typename T , typename = std::enable_if_t<std::is_integral<T>::value>> | |
constexpr | StatusWithSize (T size) |
constexpr | StatusWithSize (Status status, size_t size) |
Creates a StatusWithSize with the provided status and size. | |
constexpr | StatusWithSize (const StatusWithSize &)=default |
constexpr StatusWithSize & | operator= (const StatusWithSize &)=default |
constexpr void | UpdateAndAdd (StatusWithSize new_status_with_size) |
constexpr void | ZeroIfNotOk () |
Zeroes the size if the status is not OK . | |
constexpr size_t | size () const |
constexpr bool | ok () const |
True if status() == OkStatus(). | |
constexpr void | IgnoreError () const |
constexpr Status | status () const |
constexpr bool | IsCancelled () const |
constexpr bool | IsUnknown () const |
constexpr bool | IsInvalidArgument () const |
constexpr bool | IsDeadlineExceeded () const |
constexpr bool | IsNotFound () const |
constexpr bool | IsAlreadyExists () const |
constexpr bool | IsPermissionDenied () const |
constexpr bool | IsResourceExhausted () const |
constexpr bool | IsFailedPrecondition () const |
constexpr bool | IsAborted () const |
constexpr bool | IsOutOfRange () const |
constexpr bool | IsUnimplemented () const |
constexpr bool | IsInternal () const |
constexpr bool | IsUnavailable () const |
constexpr bool | IsDataLoss () const |
constexpr bool | IsUnauthenticated () const |
Static Public Member Functions | |
static constexpr StatusWithSize | Cancelled (size_t size=0) |
static constexpr StatusWithSize | Unknown (size_t size=0) |
static constexpr StatusWithSize | InvalidArgument (size_t size=0) |
static constexpr StatusWithSize | DeadlineExceeded (size_t size=0) |
static constexpr StatusWithSize | NotFound (size_t size=0) |
static constexpr StatusWithSize | AlreadyExists (size_t size=0) |
static constexpr StatusWithSize | PermissionDenied (size_t size=0) |
static constexpr StatusWithSize | Unauthenticated (size_t size=0) |
static constexpr StatusWithSize | ResourceExhausted (size_t size=0) |
static constexpr StatusWithSize | FailedPrecondition (size_t size=0) |
static constexpr StatusWithSize | Aborted (size_t size=0) |
static constexpr StatusWithSize | OutOfRange (size_t size=0) |
static constexpr StatusWithSize | Unimplemented (size_t size=0) |
static constexpr StatusWithSize | Internal (size_t size=0) |
static constexpr StatusWithSize | Unavailable (size_t size=0) |
static constexpr StatusWithSize | DataLoss (size_t size=0) |
static constexpr size_t | max_size () |
The maximum valid value for size. | |
StatusWithSize
stores a status and an unsigned integer. The integer must not exceed StatusWithSize::max_size()
, which is 134,217,727 (2**27 - 1) on 32-bit systems.
StatusWithSize
is useful for reporting the number of bytes read or written in an operation along with the status. For example, a function that writes a formatted string may want to report both the number of characters written and whether it ran out of space.
StatusWithSize
is more efficient than its alternatives. It packs a status and size into a single word, which can be returned from a function in a register. Because they are packed together, the size is limited to max_size().
StatusWithSize
's alternatives result in larger code size. For example:
Return status, pass size output as a pointer argument.
Requires an additional argument and forces the output argument to the stack in order to pass an address, increasing code size.
Return an object with Status and size members.
At least for ARMv7-M, the returned struct is created on the stack, which increases code size.
|
inlineexplicitconstexpr |
Creates a StatusWithSize
with status OK
and the provided size. std::enable_if
is used to prevent enum types (e.g. Status::Code
) from being used.
|
inlineconstexpr |
Ignores any errors. This method does nothing except potentially suppress complaints from any tools that are checking that errors are not dropped on the floor.
|
inlineconstexpr |
Returns the size. The size is always present, even if status()
is an error.
|
inlineconstexpr |
Update
s this status and adds to size
.
The resulting StatusWithSize
will have a size of this->size() + new_status_with_size.size()
The resulting status will be OK
if both statuses are OK
, otherwise it will take on the earliest non-OK
status.