Skip to content

iox::cxx::GenericRAII🔗

The GenericRAII class is a simple helper class to apply the C++ RAII idiom quickly. You set 2 functions, one which is called in the constructor and another function is called in the destructor which can be useful when handling resources. More...

#include <iceoryx_hoofs/cxx/generic_raii.hpp>

Public Functions🔗

Name
GenericRAII(const std::function< void()> & cleanupFunction)
constructor which creates GenericRAII that calls only the cleanupFunction on destruction
GenericRAII(const function_ref< void()> & initFunction, const std::function< void()> & cleanupFunction)
constructor which calls initFunction and stores the cleanupFunction which will be called in the destructor
~GenericRAII()
calls m_cleanupFunction callable if it was set in the constructor
GenericRAII(const GenericRAII & )
GenericRAII & operator=(const GenericRAII & )
GenericRAII(GenericRAII && rhs)
move constructor which moves a generic raii object without calling the cleanupFunction
GenericRAII & operator=(GenericRAII && rhs)
move assignment which moves a generic raii object without calling the cleanupFunction

Detailed Description🔗

class iox::cxx::GenericRAII;

The GenericRAII class is a simple helper class to apply the C++ RAII idiom quickly. You set 2 functions, one which is called in the constructor and another function is called in the destructor which can be useful when handling resources.

// This example leads to a console output of:
// hello world
// I am doing stuff
// goodbye
void someFunc() {
    auto raii{[](){ std::cout << "hello world\n"; },
                [](){ std::cout << "goodbye\n"; }};
    std::cout << "I am doing stuff\n";
    // raii goes out of scope here and the cleanupFunction is called in the
    // destructor
}

Public Functions Documentation🔗

function GenericRAII🔗

explicit GenericRAII(
    const std::function< void()> & cleanupFunction
)

constructor which creates GenericRAII that calls only the cleanupFunction on destruction

Parameters:

  • cleanupFunction callable which will be called in the destructor

function GenericRAII🔗

GenericRAII(
    const function_ref< void()> & initFunction,
    const std::function< void()> & cleanupFunction
)

constructor which calls initFunction and stores the cleanupFunction which will be called in the destructor

Parameters:

  • initFunction callable which will be called in the constructor
  • cleanupFunction callable which will be called in the destructor

function ~GenericRAII🔗

~GenericRAII()

calls m_cleanupFunction callable if it was set in the constructor

function GenericRAII🔗

GenericRAII(
    const GenericRAII & 
)

function operator=🔗

GenericRAII & operator=(
    const GenericRAII & 
)

function GenericRAII🔗

GenericRAII(
    GenericRAII && rhs
)

move constructor which moves a generic raii object without calling the cleanupFunction

function operator=🔗

GenericRAII & operator=(
    GenericRAII && rhs
)

move assignment which moves a generic raii object without calling the cleanupFunction


Updated on 17 March 2022 at 12:15:57 CET