Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
fml::StatusOr< T > Class Template Reference

#include <status_or.h>

Public Member Functions

 StatusOr (const T &value)
 
 StatusOr (T &&value)
 
 StatusOr (const Status &status)
 
 StatusOr (const StatusOr &)=default
 
 StatusOr (StatusOr &&)=default
 
StatusOroperator= (const StatusOr &)=default
 
StatusOroperator= (StatusOr &&)=default
 
StatusOroperator= (const T &value)
 
StatusOroperator= (const T &&value)
 
StatusOroperator= (const Status &value)
 
const Statusstatus () const
 
bool ok () const
 
const Tvalue () const
 
Tvalue ()
 

Detailed Description

template<typename T>
class fml::StatusOr< T >

Represents a union type of an object of type T and an fml::Status.

This is often used as a replacement for C++ exceptions where a function that could fail may return an error or a result. These are typically used for errors that are meant to be recovered from. If there is no recovery available FML_CHECK is more appropriate.

Example: StatusOr<int> div(int n, int d) { if (d == 0) { return Status(StatusCode::kFailedPrecondition, "div by zero"); } return n / d; }

Definition at line 32 of file status_or.h.

Constructor & Destructor Documentation

◆ StatusOr() [1/5]

template<typename T >
fml::StatusOr< T >::StatusOr ( const T value)
inline

Definition at line 36 of file status_or.h.

36: status_(), value_(value) {}
const T & value() const
Definition: status_or.h:77

◆ StatusOr() [2/5]

template<typename T >
fml::StatusOr< T >::StatusOr ( T &&  value)
inline

Definition at line 40 of file status_or.h.

40: status_(), value_(std::move(value)) {}

◆ StatusOr() [3/5]

template<typename T >
fml::StatusOr< T >::StatusOr ( const Status status)
inline

Definition at line 44 of file status_or.h.

44 : status_(status), value_() {
45 // It's not valid to construct a StatusOr with an OK status and no value.
46 FML_CHECK(!status_.ok());
47 }
const Status & status() const
Definition: status_or.h:73
bool ok() const
Definition: status.h:71
#define FML_CHECK(condition)
Definition: logging.h:85

◆ StatusOr() [4/5]

template<typename T >
fml::StatusOr< T >::StatusOr ( const StatusOr< T > &  )
default

◆ StatusOr() [5/5]

template<typename T >
fml::StatusOr< T >::StatusOr ( StatusOr< T > &&  )
default

Member Function Documentation

◆ ok()

template<typename T >
bool fml::StatusOr< T >::ok ( ) const
inline

Definition at line 75 of file status_or.h.

75{ return status_.ok(); }

◆ operator=() [1/5]

template<typename T >
StatusOr & fml::StatusOr< T >::operator= ( const Status value)
inline

Definition at line 67 of file status_or.h.

67 {
68 status_ = value;
69 value_ = std::nullopt;
70 return *this;
71 }

◆ operator=() [2/5]

template<typename T >
StatusOr & fml::StatusOr< T >::operator= ( const StatusOr< T > &  )
default

◆ operator=() [3/5]

template<typename T >
StatusOr & fml::StatusOr< T >::operator= ( const T &&  value)
inline

Definition at line 61 of file status_or.h.

61 {
62 status_ = Status();
63 value_ = std::move(value);
64 return *this;
65 }
Task::Status Status
Definition: TaskList.cpp:15

◆ operator=() [4/5]

template<typename T >
StatusOr & fml::StatusOr< T >::operator= ( const T value)
inline

Definition at line 55 of file status_or.h.

55 {
56 status_ = Status();
57 value_ = value;
58 return *this;
59 }

◆ operator=() [5/5]

template<typename T >
StatusOr & fml::StatusOr< T >::operator= ( StatusOr< T > &&  )
default

◆ status()

template<typename T >
const Status & fml::StatusOr< T >::status ( ) const
inline

Definition at line 73 of file status_or.h.

73{ return status_; }

◆ value() [1/2]

template<typename T >
T & fml::StatusOr< T >::value ( )
inline

Definition at line 86 of file status_or.h.

86 {
87 if (value_.has_value()) {
88 FML_DCHECK(status_.ok());
89 return value_.value();
90 }
91 FML_LOG(FATAL) << "StatusOr::value() called on error Status";
93 }
#define FATAL(error)
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_UNREACHABLE()
Definition: logging.h:109
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ value() [2/2]

template<typename T >
const T & fml::StatusOr< T >::value ( ) const
inline

Definition at line 77 of file status_or.h.

77 {
78 if (value_.has_value()) {
79 FML_DCHECK(status_.ok());
80 return value_.value();
81 }
82 FML_LOG(FATAL) << "StatusOr::value() called on error Status";
84 }

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