API return value class wrapping a 32-bit type. The MSB (bit 31) indicates success or failure. Bits 0 to 30 are used to store the return value.
class MWX_APIRET {
uint32_t _code;
public:
MWX_APIRET() : _code(0) {}
MWX_APIRET(bool b) {
_code = b ? 0x80000000 : 0;
}
MWX_APIRET(bool b, uint32_t val) {
_code = (b ? 0x80000000 : 0) + (val & 0x7fffffff);
}
inline bool is_success() const { return ((_code & 0x80000000) != 0); }
inline bool is_fail() const { return ((_code & 0x80000000) == 0); }
inline uint32_t get_value() const { return _code & 0x7fffffff; }
inline operator uint32_t() const { return get_value(); }
inline operator bool() const { return is_success(); }
};
Constructors
MWX_APIRET()
MWX_APIRET(bool b)
MWX_APIRET(bool b, uint32_t val)
The default constructor initializes with the combination false
, 0
.
You can also explicitly construct with bool
and uint32_t
parameters.
Since a constructor with a bool
parameter is implemented, you can use true
/false
as return values, like the following example:
MWX_APIRET myfunc() {
if (...) return true;
else false;
}
Methods
is_success()
, operator bool()
inline bool is_success()
inline operator bool()
Returns true
if the MSB is set to 1
.
inline bool is_fail()
Returns true
if the MSB is 0
.
inline uint32_t get_value()
inline operator uint32_t()
Retrieves the value part from bits 0 to 30.