C function call abstraction class which performs the error handling automatically.
More...
|
ReturnType | getReturnValue () const noexcept |
| Returns the returnValue of the c function call. If an error has occurred the error code is returned. If you use it in your code you should probably check with hasErrors() if an actual error has occurred during the call. More...
|
|
| operator ReturnType () const noexcept |
| conversion operator to the return type of the c call More...
|
|
bool | hasErrors () const noexcept |
| If one of the given error codes was returned during the c function call and the c function failed. More...
|
|
const char * | getErrorString () const noexcept |
| If no error occurred it returns a string like "no errors" (depending on the posix system) otherwise it returns the errnum error string. More...
|
|
int32_t | getErrNum () const noexcept |
| Returns the errnum. 0 if no error has occurred, otherwise != 0. More...
|
|
|
template<typename Function_F , typename ReturnType_F , typename... FunctionArguments_F> |
SmartC< Function_F, ReturnType_F, FunctionArguments_F... > | makeSmartCImpl (const char *file, const int line, const char *func, const Function_F &f_function, const ReturnMode &f_mode, const std::initializer_list< ReturnType_F > &f_returnValues, const std::initializer_list< int > &f_ignoredValues, FunctionArguments_F... f_args) noexcept |
|
template<typename Function, typename ReturnType, typename... FunctionArguments>
class iox::cxx::SmartC< Function, ReturnType, FunctionArguments >
C function call abstraction class which performs the error handling automatically.
#include <cstdlib>
#include "smart_c.hpp"
auto memoryCall =
cxx::makeSmartC(malloc, cxx::returnMode::PRE_DEFINED_ERROR_CODE, {static_cast<void*>(nullptr)}, 10);
void * pointer;
if ( !memoryCall.hasErrors() ) {
pointer = memoryCall.getReturnValue();
}
...
auto semaphoreCall =
cxx::makeSmartC(sem_open, cxx::returnMode::PRE_DEFINED_ERROR_CODE, {SEM_FAILED}, {}, "param1",
12);
if ( !semaphoreCall.hasErrors() ) {
DoStuffWithSemaphore(semaphore.getReturnValue());
}