iceoryx_doc  1.0.1
Public Member Functions | Friends | List of all members
iox::cxx::SmartC< Function, ReturnType, FunctionArguments > Class Template Reference

C function call abstraction class which performs the error handling automatically. More...

#include <smart_c.hpp>

Public Member Functions

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...
 

Friends

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
 

Detailed Description

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 an error has occurred the optional has no value
if ( !semaphoreCall.hasErrors() ) {
DoStuffWithSemaphore(semaphore.getReturnValue());
}

Member Function Documentation

◆ getErrNum()

template<typename Function , typename ReturnType , typename... FunctionArguments>
int32_t iox::cxx::SmartC< Function, ReturnType, FunctionArguments >::getErrNum
inlinenoexcept

Returns the errnum. 0 if no error has occurred, otherwise != 0.

Returns
returns the errno value which was set by the c call

◆ getErrorString()

template<typename Function , typename ReturnType , typename... FunctionArguments>
const char * iox::cxx::SmartC< Function, ReturnType, FunctionArguments >::getErrorString
inlinenoexcept

If no error occurred it returns a string like "no errors" (depending on the posix system) otherwise it returns the errnum error string.

Returns
if the c call failed the result of strerror(errno)

◆ getReturnValue()

template<typename Function , typename ReturnType , typename... FunctionArguments>
ReturnType iox::cxx::SmartC< Function, ReturnType, FunctionArguments >::getReturnValue
inlinenoexcept

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.

Returns
returnValue of the c call

◆ hasErrors()

template<typename Function , typename ReturnType , typename... FunctionArguments>
bool iox::cxx::SmartC< Function, ReturnType, FunctionArguments >::hasErrors
inlinenoexcept

If one of the given error codes was returned during the c function call and the c function failed.

Returns
true if the c call failed, otherwise false

◆ operator ReturnType()

template<typename Function , typename ReturnType , typename... FunctionArguments>
iox::cxx::SmartC< Function, ReturnType, FunctionArguments >::operator ReturnType
inlinenoexcept

conversion operator to the return type of the c call

Returns
returnValue of the c call

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