LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc::Rv< R > Class Template Reference

#include <Errata.h>

Collaboration diagram for swoc::Rv< R >:
Collaboration graph

Public Types

using result_type = R
 Type of result value.
 
using code_type = Errata::code_type
 
using Severity = Errata::Severity
 

Public Member Functions

 Rv ()
 
 Rv (result_type const &result)
 
 Rv (result_type const &result, Errata &&errata)
 
 Rv (result_type &&result)
 
 Rv (result_type &&result, Errata &&errata)
 
 Rv (Errata &&errata)
 
self_typenote (std::string_view text)
 
self_typenote (Severity severity, std::string_view text)
 
self_typenote (code_type const &code)
 
self_typenote (code_type const &code, Severity severity)
 
template<typename... Args>
self_typenote (std::string_view fmt, Args &&...args)
 
template<typename... Args>
self_typenote (Severity severity, std::string_view fmt, Args &&...args)
 
self_typenote (Errata const &that)
 
self_typenote (Errata &&that)
 
 operator result_type const & () const
 
result_typeoperator= (result_type const &r)
 
result_typeoperator= (result_type &&r)
 
self_typeassign (result_type const &result)
 
self_typeassign (result_type &&result)
 
result_typeresult ()
 
result_type const & result () const
 
Errataerrata ()
 
Errata const & errata () const
 
 operator Errata & ()
 
self_typeoperator= (Errata &&status)
 
bool is_ok () const
 
self_typeclear ()
 Clear the errata.
 
template<typename... Args>
auto note (std::string_view fmt, Args &&...args) -> self_type &
 
template<typename... Args>
auto note (Severity severity, std::string_view fmt, Args &&...args) -> self_type &
 

Protected Types

using self_type = Rv
 Standard self reference type.
 

Protected Attributes

result_type _r
 The result.
 
Errata _errata
 The errata.
 

Detailed Description

template<typename R>
class swoc::Rv< R >

Return type for returning a value and status (errata). In general, a method wants to return both a result and a status so that errors are logged properly. This structure is used to do that in way that is more usable than just std::pair. - Simpler and shorter typography - Force use of errata rather than having to remember it (and the order) each time - Enable assignment directly to R for ease of use and compatibility so clients can upgrade asynchronously.

Definition at line 711 of file Errata.h.

Member Typedef Documentation

◆ code_type

template<typename R>
using swoc::Rv< R >::code_type = Errata::code_type

Definition at line 714 of file Errata.h.

◆ result_type

template<typename R>
using swoc::Rv< R >::result_type = R

Type of result value.

Definition at line 713 of file Errata.h.

◆ self_type

template<typename R>
using swoc::Rv< R >::self_type = Rv
protected

Standard self reference type.

Definition at line 718 of file Errata.h.

◆ Severity

template<typename R>
using swoc::Rv< R >::Severity = Errata::Severity

Definition at line 715 of file Errata.h.

Constructor & Destructor Documentation

◆ Rv() [1/6]

template<typename T>
swoc::Rv< T >::Rv ( )

Default constructor. The default constructor for R is used. The status is initialized to SUCCESS.

Definition at line 1371 of file Errata.h.

◆ Rv() [2/6]

template<typename T>
swoc::Rv< T >::Rv ( result_type const & result)

Construct with copy of result and empty (successful) Errata.

Parameters
resultResult of the operation.

Definition at line 1373 of file Errata.h.

◆ Rv() [3/6]

template<typename T>
swoc::Rv< T >::Rv ( result_type const & result,
Errata && errata )

Construct with copy of result and move errata.

Parameters
resultReturn value / result.
errataSource errata to move.

Definition at line 1375 of file Errata.h.

◆ Rv() [4/6]

template<typename R>
swoc::Rv< R >::Rv ( result_type && result)

Construct with move of result and empty (successful) Errata.

Parameters
resultThe return / result value.

Definition at line 1377 of file Errata.h.

◆ Rv() [5/6]

template<typename R>
swoc::Rv< R >::Rv ( result_type && result,
Errata && errata )

Construct with a move of result and errata.

Parameters
resultThe return / result value to move.
errataStatus to move.

Definition at line 1379 of file Errata.h.

◆ Rv() [6/6]

template<typename R>
swoc::Rv< R >::Rv ( Errata && errata)

Construct only from errata

Parameters
errataErrata instance.

This is useful for error conditions. The result is default constructed and the errata consumed by the return value. If result_type is a smart pointer or other cheaply default constructed class this can make the code much cleaner;

// Assume Thing can be default constructed cheaply.
Rv<Thing> func(...) {
if (something_bad) {
return Errata("Bad thing happen!");
}
return Thing{arg1, arg2};
}

Definition at line 1381 of file Errata.h.

Member Function Documentation

◆ assign() [1/2]

template<typename R>
Rv< R > & swoc::Rv< R >::assign ( result_type && result)

Move the result to this.

Parameters
resultValue to move.
Returns
this,

Definition at line 1424 of file Errata.h.

◆ assign() [2/2]

template<typename R>
Rv< R > & swoc::Rv< R >::assign ( result_type const & result)

Set the result.

This differs from assignment of the function result in that the return value is a reference to the Rv, not the internal result. This makes it useful for assigning a result local variable and then returning.

Parameters
resultValue to move.
Returns
this
Rv<int> func(...) {
Rv<int> zret;
int value;
// ... complex computation, result in value
return zret.assign(value);
}
self_type & assign(result_type const &result)
Definition Errata.h:1417

Definition at line 1417 of file Errata.h.

◆ clear()

template<typename R>
auto swoc::Rv< R >::clear ( )

Clear the errata.

Definition at line 1366 of file Errata.h.

◆ errata() [1/2]

template<typename R>
Errata & swoc::Rv< R >::errata ( )

Return the status.

Returns
A reference to the errata in this object.

Definition at line 1407 of file Errata.h.

◆ errata() [2/2]

template<typename R>
Errata const & swoc::Rv< R >::errata ( ) const

Return the status.

Returns
A reference to the errata in this object.

Definition at line 1401 of file Errata.h.

◆ is_ok()

template<typename R>
bool swoc::Rv< R >::is_ok ( ) const

Check the status of the return value.

Returns
true if the value is valid / OK, false otherwise.

Definition at line 1360 of file Errata.h.

◆ note() [1/10]

template<typename R>
auto swoc::Rv< R >::note ( code_type const & code)

Append a message in to the result.

Parameters
codethe error code.
Returns
*this

The annotation text is constructed as the short, long, and numeric value of code, which is then discarded.

Definition at line 1330 of file Errata.h.

◆ note() [2/10]

template<typename R>
auto swoc::Rv< R >::note ( code_type const & code,
Severity severity )

Append a message in to the result.

Parameters
codethe error code.
severityLocal severity.
Returns
*this

The annotation text is constructed as the short, long, and numeric value of code, which is then discarded.

Definition at line 1337 of file Errata.h.

◆ note() [3/10]

template<typename R>
Rv< R > & swoc::Rv< R >::note ( Errata && that)
inline

Copy messages from that to this, then clear that.

Parameters
thatSource object from which to copy.
Returns
*this

The code and severity of that are discarded.

Definition at line 1445 of file Errata.h.

◆ note() [4/10]

template<typename R>
Rv< R > & swoc::Rv< R >::note ( Errata const & that)
inline

Copy messages from that to this.

Parameters
thatSource object from which to copy.
Returns
*this

The code and severity of that are discarded.

Definition at line 1438 of file Errata.h.

◆ note() [5/10]

template<typename R>
template<typename... Args>
self_type & swoc::Rv< R >::note ( Severity severity,
std::string_view fmt,
Args &&... args )

Append a message in to the result.

Template Parameters
ArgsFormat string argument types.
Parameters
severityLocal severity.
fmtFormat string.
argsArguments for fmt.
Returns
*this

◆ note() [6/10]

template<typename R>
template<typename... Args>
auto swoc::Rv< R >::note ( Severity severity,
std::string_view fmt,
Args &&... args ) -> self_type &

Definition at line 1353 of file Errata.h.

◆ note() [7/10]

template<typename R>
auto swoc::Rv< R >::note ( Severity severity,
std::string_view text )
inline

Append a message in to the result.

Parameters
severityLocal severity.
textText for the error.
Returns
*this

Definition at line 1323 of file Errata.h.

◆ note() [8/10]

template<typename R>
template<typename... Args>
self_type & swoc::Rv< R >::note ( std::string_view fmt,
Args &&... args )

Append a message in to the result.

Template Parameters
ArgsFormat string argument types.
Parameters
fmtFormat string.
argsArguments for fmt.
Returns
*this

◆ note() [9/10]

template<typename R>
template<typename... Args>
auto swoc::Rv< R >::note ( std::string_view fmt,
Args &&... args ) -> self_type &

Definition at line 1345 of file Errata.h.

◆ note() [10/10]

template<typename R>
auto swoc::Rv< R >::note ( std::string_view text)
inline

Append a message in to the result.

Parameters
textText for the error.
Returns
*this

Definition at line 1316 of file Errata.h.

◆ operator Errata &()

template<typename R>
swoc::Rv< R >::operator Errata & ( )

Get the internal Errata.

Returns
Reference to internal Errata.

Definition at line 1411 of file Errata.h.

◆ operator result_type const &()

template<typename T>
swoc::Rv< T >::operator result_type const & ( ) const

User conversion to the result type.

This makes it easy to use the function normally or to pass the result only to other functions without having to extract it by hand.

Definition at line 1383 of file Errata.h.

◆ operator=() [1/3]

template<typename R>
auto swoc::Rv< R >::operator= ( Errata && status)

Replace current status with status.

Parameters
statusErrata to move in to this instance.
Returns
*this

The current Errata for this is discarded and replaced with status.

Definition at line 1431 of file Errata.h.

◆ operator=() [2/3]

template<typename R>
auto swoc::Rv< R >::operator= ( result_type && r)

Move assign a result r to this.

Parameters
rResult.
Returns
r

Definition at line 1460 of file Errata.h.

◆ operator=() [3/3]

template<typename R>
auto swoc::Rv< R >::operator= ( result_type const & r)

Assignment from result type.

Parameters
rResult.

This allows the result to be assigned to a pre-declared return value structure. The return value is a reference to the internal result so that this operator can be chained in other assignments to instances of result type. This is most commonly used when the result is computed in to a local variable to be both returned and stored in a member.

Rv<int> zret;
int value;
// ... complex computations, result in value
this->m_value = zret = value;
// ...
return zret;
Returns
A reference to the copy of r stored in this object.

Definition at line 1453 of file Errata.h.

◆ result() [1/2]

template<typename R>
R & swoc::Rv< R >::result ( )

Return the result.

Returns
A reference to the result value in this object.

Definition at line 1395 of file Errata.h.

◆ result() [2/2]

template<typename R>
R const & swoc::Rv< R >::result ( ) const

Return the result.

Returns
A reference to the result value in this object.

Definition at line 1389 of file Errata.h.

Member Data Documentation

◆ _errata

template<typename R>
Errata swoc::Rv< R >::_errata
protected

The errata.

Definition at line 721 of file Errata.h.

◆ _r

template<typename R>
result_type swoc::Rv< R >::_r
protected

The result.

Definition at line 720 of file Errata.h.


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