iox::cxx::SmartC🔗
C function call abstraction class which performs the error handling automatically. More...
#include <smart_c.hpp>
Public Functions🔗
Name | |
---|---|
ReturnType | getReturnValue() const 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. |
operator ReturnType() const conversion operator to the return type of the c call |
|
bool | hasErrors() const If one of the given error codes was returned during the c function call and the c function failed. |
const char * | getErrorString() const If no error occurred it returns a string like "no errors" (depending on the posix system) otherwise it returns the errnum error string. |
int32_t | getErrNum() const Returns the errnum. 0 if no error has occurred, otherwise != 0. |
Public Attributes🔗
Name | |
---|---|
const char * | file |
int | line |
const char * | func |
Friends🔗
Name | |
---|---|
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) |
Detailed Description🔗
template <typename Function ,
typename ReturnType ,
typename... FunctionArguments>
class iox::cxx::SmartC;
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 an error has occurred the optional has no value
if ( !semaphoreCall.hasErrors() ) {
DoStuffWithSemaphore(semaphore.getReturnValue());
}
Public Functions Documentation🔗
function getReturnValue🔗
inline ReturnType getReturnValue() const
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.
Return: returnValue of the c call
function operator ReturnType🔗
inline operator ReturnType() const
conversion operator to the return type of the c call
Return: returnValue of the c call
function hasErrors🔗
inline bool hasErrors() const
If one of the given error codes was returned during the c function call and the c function failed.
Return: true if the c call failed, otherwise false
function getErrorString🔗
inline const char * getErrorString() const
If no error occurred it returns a string like "no errors" (depending on the posix system) otherwise it returns the errnum error string.
Return: if the c call failed the result of strerror(errno)
function getErrNum🔗
inline int32_t getErrNum() const
Returns the errnum. 0 if no error has occurred, otherwise != 0.
Return: returns the errno value which was set by the c call
Public Attributes Documentation🔗
variable file🔗
const char * file;
variable line🔗
int line;
variable func🔗
const char * func;
Friends🔗
friend makeSmartCImpl🔗
friend 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
);
Updated on 31 May 2022 at 15:29:15 CEST