MLIB
Loading...
Searching...
No Matches
mlib::checked< T > Class Template Reference

Provides a mechanism similar to expected for creating objects associated with error codes. More...

#include <errorcode.h>

Inheritance diagram for mlib::checked< T >:
mlib::erc

Public Member Functions

 checked ()
 
 checked (const T &obj_, const erc &err)
 Constructor using a T and an error code. Both are copy-constructed.
 
 checked (const T &obj_, int value=0, erc::level pri_=erc::level::error)
 
 checked (T &&obj_, erc &&err)
 
 checked (T &&obj_, const erc &err)
 
 checked (const checked< T > &other)
 Copy constructor.
 
 checked (checked< T > &&other)
 Move constructor.
 
checked< T > & operator= (const checked< T > &rhs)
 Assignment operator.
 
checked< T > & operator= (checked< T > &&rhs)
 Move assignment operator.
 
checked< T > & operator= (const erc &rhs)
 Set error value.
 
T & operator* ()
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
- Public Member Functions inherited from mlib::erc
 erc ()
 Default ctor for erc objects creates an inactive error.
 
 erc (int value, level priority=level::error)
 Ctor for a real erc using default error facility.
 
 erc (int value, const mlib::errfac &facility, level priority=level::error)
 Ctor for a real erc.
 
 erc (const erc &other)
 Copy constructor removes the activity flag of the original object.
 
 erc (erc &&other)
 Move constructor removes the activity flag of the original object.
 
 ~erc () noexcept(false)
 Destructor. Call raise() function to see if the error should get logged or thrown.
 
ercoperator= (const erc &rhs)
 Principal assignment operator.
 
ercoperator= (erc &&rhs)
 Move assignment operator.
 
 operator int () const
 Integer conversion operator.
 
level priority () const
 Return priority value.
 
bool is_active () const
 Return activity flag.
 
const errfacfacility () const
 Return reference to facility.
 
bool operator== (const erc &other) const
 Equality comparison operator.
 
bool operator!= (const erc &other) const
 Inequality comparison operator.
 
void raise () const
 
void reactivate () const
 Similar to re-throwing an exception.
 
void deactivate () const
 Marks error code as inactive.
 
int code () const
 Return numerical value.
 
std::string message () const
 Get logging message.
 
void message (const std::string &m)
 Set the message for this error.
 

Protected Attributes

obj
 

Additional Inherited Members

- Public Types inherited from mlib::erc
enum  level {
  none = 0 , info , notice , warning ,
  error , critical , alert , emerg
}
 Error levels (borrowed from BSD Unix) More...
 
- Static Public Attributes inherited from mlib::erc
static erc success {0, erc::none}
 The SUCCESS indicator.
 

Detailed Description

template<checkable T>
class mlib::checked< T >

Provides a mechanism similar to expected for creating objects associated with error codes.

checked<T> objects are derived from mlib::erc, so they can be treated as regular erc objects, in particular they can be compared with an integer to check if they contain an error. To access the included T object, use the '->' or '*' operators.

Note
To avoid conflicts with the erc integer conversion operator, the template argument T should NOT be convertible to int.
Template Parameters
T- the type of the included object

Constructor & Destructor Documentation

◆ checked()

template<checkable T>
mlib::checked< T >::checked ( )
inline

Default constructor. Invoke T's default constructor and set the default error code value (0).

Member Function Documentation

◆ operator*() [1/2]

template<checkable T>
T & mlib::checked< T >::operator* ( )
inline

Access the included T object

◆ operator*() [2/2]

template<checkable T>
const T & mlib::checked< T >::operator* ( ) const
inline

Access the included T object

◆ operator->() [1/2]

template<checkable T>
T * mlib::checked< T >::operator-> ( )
inline

Access the included T object

◆ operator->() [2/2]

template<checkable T>
const T * mlib::checked< T >::operator-> ( ) const
inline

Access the included T object


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