Tkrzw
Public Types | Public Member Functions | Static Public Member Functions | List of all members
tkrzw::Status Class Referencefinal

Status of operations. More...

#include <tkrzw_lib_common.h>

Public Types

enum  Code : int32_t {
  SUCCESS = 0, UNKNOWN_ERROR = 1, SYSTEM_ERROR = 2, NOT_IMPLEMENTED_ERROR = 3,
  PRECONDITION_ERROR = 4, INVALID_ARGUMENT_ERROR = 5, CANCELED_ERROR = 6, NOT_FOUND_ERROR = 7,
  PERMISSION_ERROR = 8, INFEASIBLE_ERROR = 9, DUPLICATION_ERROR = 10, BROKEN_DATA_ERROR = 11,
  NETWORK_ERROR = 12, APPLICATION_ERROR = 13
}
 Enumeration of status codes. More...
 

Public Member Functions

 Status ()
 Default constructor representing the success code. More...
 
 Status (Code code)
 Constructor representing a specific status. More...
 
 Status (Code code, std::string_view message)
 Constructor representing a specific status with a message. More...
 
 Status (const Status &rhs)
 Copy constructor. More...
 
 Status (Status &&rhs)
 Move constructor. More...
 
 ~Status ()
 Destructor. More...
 
Status & operator= (const Status &rhs)
 Assigns the internal state from another status object. More...
 
Status & operator= (Status &&rhs)
 Assigns the internal state from another moved status object. More...
 
Status & operator|= (const Status &rhs)
 Assigns the internal state from another status object only if the current state is success. More...
 
Status & operator|= (Status &&rhs)
 Assigns the internal state from another status object only if the current state is success. More...
 
Code GetCode () const
 Gets the status code. More...
 
std::string GetMessage () const
 Gets the status message. More...
 
bool HasMessage () const
 Checks whether the status has a non-empty message. More...
 
char * MakeMessageC () const
 Makes a C string of the message. More...
 
void Set (Code code)
 Sets the code and an empty message. More...
 
void Set (Code code, std::string_view message)
 Sets the code and the message. More...
 
bool operator== (const Status &rhs) const
 Checks whether the internal status code is equal to a given status. More...
 
bool operator!= (const Status &rhs) const
 Checks whether the internal status code is not equal to a given status. More...
 
bool operator== (const Code &code) const
 Checks whether the internal status code is equal to a given code. More...
 
bool operator!= (const Code &code) const
 Checks whether the internal status code is not equal to a given code. More...
 
bool operator< (const Status &rhs) const
 Compares this object with another status object. More...
 
 operator std::string () const
 Gets a string expression of the status. More...
 
bool IsOK () const
 Returns true if the status is success. More...
 
const Status & OrDie () const
 Throws an exception if the status is not success. More...
 

Static Public Member Functions

static const char * CodeName (Code code)
 Gets the string name of a status code. More...
 

Detailed Description

Status of operations.

Member Enumeration Documentation

◆ Code

enum tkrzw::Status::Code : int32_t

Enumeration of status codes.

Enumerator
SUCCESS 

Success.

UNKNOWN_ERROR 

Generic error whose cause is unknown.

SYSTEM_ERROR 

Generic error from underlying systems.

NOT_IMPLEMENTED_ERROR 

Error that the feature is not implemented.

PRECONDITION_ERROR 

Error that a precondition is not met.

INVALID_ARGUMENT_ERROR 

Error that a given argument is invalid.

CANCELED_ERROR 

Error that the operation is canceled.

NOT_FOUND_ERROR 

Error that a specific resource is not found.

PERMISSION_ERROR 

Error that the operation is not permitted.

INFEASIBLE_ERROR 

Error that the operation is infeasible.

DUPLICATION_ERROR 

Error that a specific resource is duplicated.

BROKEN_DATA_ERROR 

Error that internal data are broken.

NETWORK_ERROR 

Error caused by networking failure.

APPLICATION_ERROR 

Generic error caused by the application logic.

Constructor & Destructor Documentation

◆ Status() [1/5]

tkrzw::Status::Status ( )

Default constructor representing the success code.

◆ Status() [2/5]

tkrzw::Status::Status ( Code  code)
explicit

Constructor representing a specific status.

Parameters
codeThe status code.

◆ Status() [3/5]

tkrzw::Status::Status ( Code  code,
std::string_view  message 
)

Constructor representing a specific status with a message.

Parameters
codeThe status code.
messageAn arbitrary status message.

◆ Status() [4/5]

tkrzw::Status::Status ( const Status &  rhs)

Copy constructor.

Parameters
rhsThe right-hand-side object.

◆ Status() [5/5]

tkrzw::Status::Status ( Status &&  rhs)

Move constructor.

Parameters
rhsThe right-hand-side object.

◆ ~Status()

tkrzw::Status::~Status ( )

Destructor.

Member Function Documentation

◆ operator=() [1/2]

Status& tkrzw::Status::operator= ( const Status &  rhs)

Assigns the internal state from another status object.

Parameters
rhsThe status object.

◆ operator=() [2/2]

Status& tkrzw::Status::operator= ( Status &&  rhs)

Assigns the internal state from another moved status object.

Parameters
rhsThe status object.

◆ operator|=() [1/2]

Status& tkrzw::Status::operator|= ( const Status &  rhs)

Assigns the internal state from another status object only if the current state is success.

Parameters
rhsThe status object.

◆ operator|=() [2/2]

Status& tkrzw::Status::operator|= ( Status &&  rhs)

Assigns the internal state from another status object only if the current state is success.

Parameters
rhsThe status object.

◆ GetCode()

Code tkrzw::Status::GetCode ( ) const

Gets the status code.

Returns
The status code.

◆ GetMessage()

std::string tkrzw::Status::GetMessage ( ) const

Gets the status message.

Returns
The status message.

◆ HasMessage()

bool tkrzw::Status::HasMessage ( ) const

Checks whether the status has a non-empty message.

Returns
True if the status has a non-empty message.

◆ MakeMessageC()

char* tkrzw::Status::MakeMessageC ( ) const

Makes a C string of the message.

Returns
The C message string, which should be released by the free function.

◆ Set() [1/2]

void tkrzw::Status::Set ( Code  code)

Sets the code and an empty message.

Parameters
codeThe status code.

◆ Set() [2/2]

void tkrzw::Status::Set ( Code  code,
std::string_view  message 
)

Sets the code and the message.

Parameters
codeThe status code.
messageAn arbitrary status message.

◆ operator==() [1/2]

bool tkrzw::Status::operator== ( const Status &  rhs) const

Checks whether the internal status code is equal to a given status.

Parameters
rhsThe status to compare.
Returns
True if the internal status code is equal to the given status.

◆ operator!=() [1/2]

bool tkrzw::Status::operator!= ( const Status &  rhs) const

Checks whether the internal status code is not equal to a given status.

Parameters
rhsThe status to compare.
Returns
True if the internal status code is not equal to the given status.

◆ operator==() [2/2]

bool tkrzw::Status::operator== ( const Code &  code) const

Checks whether the internal status code is equal to a given code.

Parameters
codeThe code to compare.
Returns
True if the internal status code is equal to the given code.

◆ operator!=() [2/2]

bool tkrzw::Status::operator!= ( const Code &  code) const

Checks whether the internal status code is not equal to a given code.

Parameters
codeThe code to compare.
Returns
True if the internal status code is not equal to the given code.

◆ operator<()

bool tkrzw::Status::operator< ( const Status &  rhs) const

Compares this object with another status object.

Parameters
rhsThe status to compare.
Returns
True if this object is considered less than the given object.

◆ operator std::string()

tkrzw::Status::operator std::string ( ) const

Gets a string expression of the status.

Returns
The string expression

◆ IsOK()

bool tkrzw::Status::IsOK ( ) const

Returns true if the status is success.

Returns
True if the status is success, or false on failure.

◆ OrDie()

const Status& tkrzw::Status::OrDie ( ) const

Throws an exception if the status is not success.

Returns
The reference to this object.

◆ CodeName()

static const char* tkrzw::Status::CodeName ( Code  code)
static

Gets the string name of a status code.

Parameters
codeThe status code.
Returns
The name of the status code.