Resolve "Make `admire::error_code` a fully fledged class"
This MR redefines the admire::error_code typedef transforming it into
a fully-fledged C++ object.
This has the following advantages:
-
The default
error_codeconstructor initializes toADM_SUCCESS. Thus, we can now doerror_code ec;instead oferror_code ec = ADM_SUCCESS;. -
error_codes can be constructed explicitly fromADM_return_tvalues. -
error_codes can be constructed explicitly fromint32_t(for RPC types). -
error_codes can be converted implicitly toADM_return_t, which makes code less verbose when returning from C++ code to the C code. -
error_codes are convertible tobool. This means that we can now doerror_code ec = fun(); if(ec) { /* there was an error, do something */ }whereas previously we were forced to explicitly check against
ADM_SUCCESS.error_code ec = fun(); if(ec != ADM_SUCCESS) { /* there was an error, do something */ } -
error_codes providevalue(),name(), andmessage()functions that make them much more flexible. -
Several
error_codeconstants are defined to avoid usingADM_return_tdirectly in C++ code, hopefully making the code more readable:constexpr error_code error_code::success = error_code{ADM_SUCCESS}; constexpr error_code error_code::snafu = error_code{ADM_ESNAFU}; constexpr error_code error_code::bad_args = error_code{ADM_EBADARGS}; constexpr error_code error_code::out_of_memory = error_code{ADM_ENOMEM}; constexpr error_code error_code::entity_exists = error_code{ADM_EEXISTS}; constexpr error_code error_code::no_such_entity = error_code{ADM_ENOENT}; constexpr error_code error_code::adhoc_in_use = error_code{ADM_EADHOC_BUSY}; constexpr error_code error_code::other = error_code{ADM_EOTHER};
Also, most of the implementation is constexpr, which is always nice.
Closes #81 (closed)