STX  1.0.0
List of all members
stx::FixedReport Class Reference

#include <report.h>

Detailed Description

FixedReport is an error-type with a fixed-size stack-allocated buffer, containing an error string denoting the cause of the error from the error type of a Result<T, E>.

The error-string stored in the report is truncated (and contains a message to signify truncation) if its given string is longer than stx::kReportReserveSize.

When to use FixedReport against SpanReport

Constructing a FixedReport for your error type

FixedReports are automatically constructed for uint8_t, uint16_t, uint32_t,int8_t, int16_t, int32_t, string, string_view, and pointers, as the error strings are not known at compile-time and neither are the types containing a description of the error.

NOTE: If the error type already provides an error message or the needed error-message for the type is a static duration value and known at compile, you can use SpanReport instead which just forwards a reference to the error string.

Defining for your error type

// assuming the error type contains only an int, and no string description.
struct Error {
// error integer
int error;
// formats error message
void format_into(const char*, size_t size) const noexcept;
};
inline FixedReport operator>>(ReportQuery, Error const& err) noexcept {
char buffer[64];
err.format_into(buffer, 64);
return FixedReport(buffer, 64);
};

Exception-safety

Ensure to not throw exceptions.

Member Typedef Documentation

◆ storage_type

Constructor & Destructor Documentation

◆ FixedReport() [1/5]

constexpr stx::FixedReport::FixedReport ( )
inlinenoexcept

◆ FixedReport() [2/5]

constexpr stx::FixedReport::FixedReport ( const char *  str,
size_t  size 
)
inlinenoexcept

size: string size excluding null-terminator

◆ FixedReport() [3/5]

constexpr stx::FixedReport::FixedReport ( std::string_view const &  info)
inlineexplicitnoexcept

◆ FixedReport() [4/5]

constexpr stx::FixedReport::FixedReport ( FixedReport const &  )
defaultnoexcept

◆ FixedReport() [5/5]

constexpr stx::FixedReport::FixedReport ( FixedReport &&  )
defaultnoexcept

◆ ~FixedReport()

stx::FixedReport::~FixedReport ( )
defaultnoexcept

Member Function Documentation

◆ operator=() [1/2]

constexpr FixedReport& stx::FixedReport::operator= ( FixedReport const &  )
defaultnoexcept

◆ operator=() [2/2]

constexpr FixedReport& stx::FixedReport::operator= ( FixedReport &&  )
defaultnoexcept

◆ what()

constexpr std::string_view stx::FixedReport::what ( ) const
inlinenoexcept

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