diff --git a/iceoryx_hoofs/README.md b/iceoryx_hoofs/README.md index 1ed33f39d86..9f28da7ff07 100644 --- a/iceoryx_hoofs/README.md +++ b/iceoryx_hoofs/README.md @@ -50,7 +50,7 @@ class should be used. |`function` | | A stack-based `std::function` replacement based on `storable_function` | |`function_ref` | | C++11 implementation of the next-gen C++ feature `std::function_ref` see [function_ref proposal](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0792r2.html). It behaves like `std::function` but does not own the callable.| |`functional_interface` | | Constructs to easily add functional interfaces like `and_then` to object container. | -|`GenericRAII` | | This is an abstraction of the C++ RAII idiom. Sometimes you have constructs where you would like to perform a certain task on creation and then again when they are getting out of scope, this is where `GenericRAII` comes in. It is like a `std::lock_guard` or a `std::shared_ptr` but more generic. | +|`ScopeGuard` | | This is an abstraction of the C++ RAII idiom. Sometimes you have constructs where you would like to perform a certain task on creation and then again when they are getting out of scope, this is where `ScopeGuard` comes in. It is like a `std::lock_guard` or a `std::shared_ptr` but more generic. | |`helplets` | | Implementations of [C++ Core Guideline](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) concepts like `not_null` are contained here. Additionally, we are providing some types to verify preconditions at compile time. Think of an int which has to be always greater 5, here we provide types like `greater_or_equal`.| |`list` | | Heap and exception free, relocatable implementation of `std::list` | |`NewType` | | C++11 implementation of [Haskells NewType-pattern](https://wiki.haskell.org/Newtype). | diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/scope_guard.hpp similarity index 68% rename from iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp rename to iceoryx_hoofs/include/iceoryx_hoofs/cxx/scope_guard.hpp index bde7205efa5..78130d6961c 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/scope_guard.hpp @@ -14,8 +14,8 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_HOOFS_CXX_GENERIC_RAII_HPP -#define IOX_HOOFS_CXX_GENERIC_RAII_HPP +#ifndef IOX_HOOFS_CXX_SCOPE_GUARD_HPP +#define IOX_HOOFS_CXX_SCOPE_GUARD_HPP #include "iceoryx_hoofs/cxx/function.hpp" #include "iceoryx_hoofs/cxx/function_ref.hpp" @@ -24,7 +24,7 @@ namespace iox { namespace cxx { -/// @brief The GenericRAII class is a simple helper class to apply the C++ RAII +/// @brief The ScopeGuard 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. @@ -42,31 +42,31 @@ namespace cxx /// } /// @endcode template -class GenericRAIIWithVariableCapacity +class ScopeGuardWithVariableCapacity { public: - /// @brief constructor which creates GenericRAII that calls only the cleanupFunction on destruction + /// @brief constructor which creates ScopeGuard that calls only the cleanupFunction on destruction /// @param[in] cleanupFunction callable which will be called in the destructor - explicit GenericRAIIWithVariableCapacity(const function& cleanupFunction) noexcept; + explicit ScopeGuardWithVariableCapacity(const function& cleanupFunction) noexcept; /// @brief constructor which calls initFunction and stores the cleanupFunction which will be /// called in the destructor /// @param[in] initFunction callable which will be called in the constructor /// @param[in] cleanupFunction callable which will be called in the destructor - GenericRAIIWithVariableCapacity(const function_ref& initFunction, - const function& cleanupFunction) noexcept; + ScopeGuardWithVariableCapacity(const function_ref& initFunction, + const function& cleanupFunction) noexcept; /// @brief calls m_cleanupFunction callable if it was set in the constructor - ~GenericRAIIWithVariableCapacity() noexcept; + ~ScopeGuardWithVariableCapacity() noexcept; - GenericRAIIWithVariableCapacity(const GenericRAIIWithVariableCapacity&) = delete; - GenericRAIIWithVariableCapacity& operator=(const GenericRAIIWithVariableCapacity&) = delete; + ScopeGuardWithVariableCapacity(const ScopeGuardWithVariableCapacity&) = delete; + ScopeGuardWithVariableCapacity& operator=(const ScopeGuardWithVariableCapacity&) = delete; /// @brief move constructor which moves a generic raii object without calling the cleanupFunction - GenericRAIIWithVariableCapacity(GenericRAIIWithVariableCapacity&& rhs) noexcept; + ScopeGuardWithVariableCapacity(ScopeGuardWithVariableCapacity&& rhs) noexcept; /// @brief move assignment which moves a generic raii object without calling the cleanupFunction - GenericRAIIWithVariableCapacity& operator=(GenericRAIIWithVariableCapacity&& rhs) noexcept; + ScopeGuardWithVariableCapacity& operator=(ScopeGuardWithVariableCapacity&& rhs) noexcept; private: void destroy() noexcept; @@ -76,11 +76,11 @@ class GenericRAIIWithVariableCapacity }; // This alias can be removed with C++17 and class template argument deduction -using GenericRAII = GenericRAIIWithVariableCapacity<>; +using ScopeGuard = ScopeGuardWithVariableCapacity<>; } // namespace cxx } // namespace iox -#include "iceoryx_hoofs/internal/cxx/generic_raii.inl" +#include "iceoryx_hoofs/internal/cxx/scope_guard.inl" -#endif // IOX_HOOFS_CXX_GENERIC_RAII_HPP +#endif // IOX_HOOFS_CXX_SCOPE_GUARD_HPP diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/scoped_static.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/scoped_static.hpp index 51ea609f043..fdc5eaafc3b 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/scoped_static.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/scoped_static.hpp @@ -17,21 +17,21 @@ #ifndef IOX_HOOFS_CXX_SCOPED_STATIC_HPP #define IOX_HOOFS_CXX_SCOPED_STATIC_HPP -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" namespace iox { namespace cxx { /// @todo better name -/// create a GenericRAII object to cleanup a static optional object at the end of the scope +/// create a ScopeGuard object to cleanup a static optional object at the end of the scope /// @tparam [in] T memory container which has emplace(...) and reset /// @tparam [in] CTorArgs ctor types for the object to construct /// @param [in] memory is a reference to a memory container, e.g. cxx::optional /// @param [in] ctorArgs ctor arguments for the object to construct -/// @return cxx::GenericRAII +/// @return cxx::ScopeGuard template -GenericRAII makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept; +ScopeGuard makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept; } // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp index 564458bc946..ecfdf847787 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp @@ -18,7 +18,7 @@ #define IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLER_HPP #include "iceoryx_hoofs/cxx/function.hpp" -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/log/logger.hpp" #include "iceoryx_hoofs/log/logging.hpp" #include "iceoryx_hoofs/log/logmanager.hpp" diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/generic_raii.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scope_guard.inl similarity index 68% rename from iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/generic_raii.inl rename to iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scope_guard.inl index 69d6b14907c..9823db499d7 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/generic_raii.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scope_guard.inl @@ -15,24 +15,24 @@ // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_HOOFS_CXX_GENERIC_RAII_INL -#define IOX_HOOFS_CXX_GENERIC_RAII_INL +#ifndef IOX_HOOFS_CXX_SCOPE_GUARD_INL +#define IOX_HOOFS_CXX_SCOPE_GUARD_INL -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" namespace iox { namespace cxx { template -inline GenericRAIIWithVariableCapacity::GenericRAIIWithVariableCapacity( +inline ScopeGuardWithVariableCapacity::ScopeGuardWithVariableCapacity( const cxx::function& cleanupFunction) noexcept : m_cleanupFunction(cleanupFunction) { } template -inline GenericRAIIWithVariableCapacity::GenericRAIIWithVariableCapacity( +inline ScopeGuardWithVariableCapacity::ScopeGuardWithVariableCapacity( const function_ref& initFunction, const function& cleanupFunction) noexcept : m_cleanupFunction(cleanupFunction) { @@ -40,21 +40,21 @@ inline GenericRAIIWithVariableCapacity::GenericRAIIWithVariableCapacit } template -inline GenericRAIIWithVariableCapacity::~GenericRAIIWithVariableCapacity() noexcept +inline ScopeGuardWithVariableCapacity::~ScopeGuardWithVariableCapacity() noexcept { destroy(); } template -inline GenericRAIIWithVariableCapacity::GenericRAIIWithVariableCapacity( - GenericRAIIWithVariableCapacity&& rhs) noexcept +inline ScopeGuardWithVariableCapacity::ScopeGuardWithVariableCapacity( + ScopeGuardWithVariableCapacity&& rhs) noexcept { *this = std::move(rhs); } template -inline GenericRAIIWithVariableCapacity& -GenericRAIIWithVariableCapacity::operator=(GenericRAIIWithVariableCapacity&& rhs) noexcept +inline ScopeGuardWithVariableCapacity& +ScopeGuardWithVariableCapacity::operator=(ScopeGuardWithVariableCapacity&& rhs) noexcept { if (this != &rhs) { @@ -66,7 +66,7 @@ GenericRAIIWithVariableCapacity::operator=(GenericRAIIWithVariableCapa } template -inline void GenericRAIIWithVariableCapacity::destroy() noexcept +inline void ScopeGuardWithVariableCapacity::destroy() noexcept { if (m_cleanupFunction) { diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scoped_static.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scoped_static.inl index da18e5a4ba5..11ff22f97c5 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scoped_static.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scoped_static.inl @@ -24,10 +24,10 @@ namespace iox namespace cxx { template -inline GenericRAII makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept +inline ScopeGuard makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept { memory.emplace(std::forward(ctorArgs)...); - return GenericRAII([&memory] { memory.reset(); }); + return ScopeGuard([&memory] { memory.reset(); }); } } // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp index b40843ce6a9..6f0dc8e6a10 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp @@ -17,7 +17,7 @@ #ifndef IOX_HOOFS_LOG_LOGGER_HPP #define IOX_HOOFS_LOG_LOGGER_HPP -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/log/logcommon.hpp" #include "iceoryx_hoofs/log/logstream.hpp" @@ -55,12 +55,12 @@ class Logger // NOLINTNEXTLINE(readability-identifier-naming) void SetLogLevel(const LogLevel logLevel) noexcept; - /// @brief Sets the LogLevel to the given level for the lifetime of the GenericRAII object and then sets it back to + /// @brief Sets the LogLevel to the given level for the lifetime of the ScopeGuard object and then sets it back to /// the previous one /// @param[in] logLevel to be set temporarily /// @return a scope guard which resets the LogLevel to the value at the time when this method was called // NOLINTNEXTLINE(readability-identifier-naming) - cxx::GenericRAII SetLogLevelForScope(const LogLevel logLevel) noexcept; + cxx::ScopeGuard SetLogLevelForScope(const LogLevel logLevel) noexcept; // NOLINTNEXTLINE(readability-identifier-naming) void SetLogMode(const LogMode logMode) noexcept; diff --git a/iceoryx_hoofs/source/log/logger.cpp b/iceoryx_hoofs/source/log/logger.cpp index 1ded21056bb..8f9cdcc88b5 100644 --- a/iceoryx_hoofs/source/log/logger.cpp +++ b/iceoryx_hoofs/source/log/logger.cpp @@ -67,11 +67,11 @@ void Logger::SetLogLevel(const LogLevel logLevel) noexcept } // NOLINTNEXTLINE(readability-identifier-naming) -cxx::GenericRAII Logger::SetLogLevelForScope(const LogLevel logLevel) noexcept +cxx::ScopeGuard Logger::SetLogLevelForScope(const LogLevel logLevel) noexcept { m_logLevelPredecessor.store(m_logLevel.load(std::memory_order_relaxed), std::memory_order_relaxed); SetLogLevel(logLevel); - return cxx::GenericRAII([&] { this->SetLogLevel(m_logLevelPredecessor.load(std::memory_order_relaxed)); }); + return cxx::ScopeGuard([&] { this->SetLogLevel(m_logLevelPredecessor.load(std::memory_order_relaxed)); }); } // NOLINTNEXTLINE(readability-identifier-naming) diff --git a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp index 0c15cac2940..760c6298294 100644 --- a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp @@ -16,8 +16,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp" -#include "iceoryx_hoofs/cxx/generic_raii.hpp" #include "iceoryx_hoofs/cxx/helplets.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/platform/fcntl.hpp" #include "iceoryx_hoofs/platform/mman.hpp" #include "iceoryx_hoofs/platform/stat.hpp" @@ -72,7 +72,7 @@ cxx::expected SharedMemoryBuilder::create() noe int sharedMemoryFileHandle = SharedMemory::INVALID_HANDLE; mode_t umaskSaved = umask(0U); { - cxx::GenericRAII umaskGuard([&] { umask(umaskSaved); }); + cxx::ScopeGuard umaskGuard([&] { umask(umaskSaved); }); if (m_openMode == OpenMode::PURGE_AND_CREATE) { diff --git a/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp b/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp index 545449750ef..89bedb0e983 100644 --- a/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp @@ -16,8 +16,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" -#include "iceoryx_hoofs/cxx/generic_raii.hpp" #include "iceoryx_hoofs/cxx/helplets.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/platform/socket.hpp" #include "iceoryx_hoofs/platform/unistd.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_call.hpp" @@ -323,7 +323,7 @@ cxx::expected UnixDomainSocket::initalizeSocket() noexcept // NOLINTNEXTLINE(hicpp-signed-bitwise) mode_t umaskSaved = umask(S_IXUSR | S_IXGRP | S_IRWXO); // Reset to old umask when going out of scope - cxx::GenericRAII umaskGuard([&] { umask(umaskSaved); }); + cxx::ScopeGuard umaskGuard([&] { umask(umaskSaved); }); auto socketCall = posixCall(iox_socket)(AF_LOCAL, SOCK_DGRAM, 0) .failureReturnValue(ERROR_CODE) diff --git a/iceoryx_hoofs/test/moduletests/test_cxx_generic_raii.cpp b/iceoryx_hoofs/test/moduletests/test_cxx_scope_guard.cpp similarity index 66% rename from iceoryx_hoofs/test/moduletests/test_cxx_generic_raii.cpp rename to iceoryx_hoofs/test/moduletests/test_cxx_scope_guard.cpp index ca54bb93431..599615dea5c 100644 --- a/iceoryx_hoofs/test/moduletests/test_cxx_generic_raii.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cxx_scope_guard.cpp @@ -14,8 +14,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" #include "iceoryx_hoofs/cxx/optional.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "test.hpp" namespace @@ -23,7 +23,7 @@ namespace using namespace ::testing; using namespace iox::cxx; -class GenericRAII_test : public Test +class ScopeGuard_test : public Test { public: void SetUp() override @@ -35,94 +35,94 @@ class GenericRAII_test : public Test } }; -TEST_F(GenericRAII_test, InitFunctionIsCalledInCtorWhenSet) +TEST_F(ScopeGuard_test, InitFunctionIsCalledInCtorWhenSet) { ::testing::Test::RecordProperty("TEST_ID", "9314e17c-5f02-4e5b-8d46-e324aa2cb88f"); int hasCalledInit = 0; - GenericRAII sut([&] { ++hasCalledInit; }, function()); + ScopeGuard sut([&] { ++hasCalledInit; }, function()); EXPECT_THAT(hasCalledInit, Eq(1)); } -TEST_F(GenericRAII_test, InitFunctionIsCalledInCtorWhenSetWithCleanupFunction) +TEST_F(ScopeGuard_test, InitFunctionIsCalledInCtorWhenSetWithCleanupFunction) { ::testing::Test::RecordProperty("TEST_ID", "22ff682e-e328-4696-8a38-3598365dcc31"); int hasCalledInit = 0; int hasCalledCleanup = 0; - GenericRAII sut([&] { ++hasCalledInit; }, [&] { ++hasCalledCleanup; }); + ScopeGuard sut([&] { ++hasCalledInit; }, [&] { ++hasCalledCleanup; }); EXPECT_THAT(hasCalledInit, Eq(1)); } -TEST_F(GenericRAII_test, CleanupFunctionIsCalledInDtor) +TEST_F(ScopeGuard_test, CleanupFunctionIsCalledInDtor) { ::testing::Test::RecordProperty("TEST_ID", "110bc888-0433-465f-8324-8b7149524bf7"); int hasCalledInit = 0; int hasCalledCleanup = 0; { - GenericRAII sut([&] { ++hasCalledInit; }, [&] { ++hasCalledCleanup; }); + ScopeGuard sut([&] { ++hasCalledInit; }, [&] { ++hasCalledCleanup; }); } EXPECT_THAT(hasCalledInit, Eq(1)); EXPECT_THAT(hasCalledCleanup, Eq(1)); } -TEST_F(GenericRAII_test, CleanupFunctionIsCalledInDtorWhenUsingCleanupOnlyCTor) +TEST_F(ScopeGuard_test, CleanupFunctionIsCalledInDtorWhenUsingCleanupOnlyCTor) { ::testing::Test::RecordProperty("TEST_ID", "74fbd0d6-c69f-4951-a193-e30c37d0d1bd"); bool hasCalledCleanup = false; { - GenericRAII sut([&] { hasCalledCleanup = true; }); + ScopeGuard sut([&] { hasCalledCleanup = true; }); } EXPECT_TRUE(hasCalledCleanup); } -TEST_F(GenericRAII_test, CleanupFunctionIsCalledInDtorWithEmptyInitFunction) +TEST_F(ScopeGuard_test, CleanupFunctionIsCalledInDtorWithEmptyInitFunction) { ::testing::Test::RecordProperty("TEST_ID", "e49f4d86-98e1-4562-81ef-0f672d271111"); int hasCalledCleanup = 0; { - GenericRAII sut([&] { ++hasCalledCleanup; }); + ScopeGuard sut([&] { ++hasCalledCleanup; }); } EXPECT_THAT(hasCalledCleanup, Eq(1)); } -TEST_F(GenericRAII_test, MoveCTorDoesNotCallCleanupFunctionOfOrigin) +TEST_F(ScopeGuard_test, MoveCTorDoesNotCallCleanupFunctionOfOrigin) { ::testing::Test::RecordProperty("TEST_ID", "cdaeb5da-fe45-4139-80bc-18caf32e2364"); int hasCalledCleanup = 0; - GenericRAII sut([&] { ++hasCalledCleanup; }); - GenericRAII sut2(std::move(sut)); + ScopeGuard sut([&] { ++hasCalledCleanup; }); + ScopeGuard sut2(std::move(sut)); EXPECT_THAT(hasCalledCleanup, Eq(0)); } -TEST_F(GenericRAII_test, MoveConstructedDoesCallCleanupFunctionWhenDestroyed) +TEST_F(ScopeGuard_test, MoveConstructedDoesCallCleanupFunctionWhenDestroyed) { ::testing::Test::RecordProperty("TEST_ID", "afbf48e1-5868-47a8-8157-d0000c23efc7"); int hasCalledCleanup = 0; { - iox::cxx::optional sut(GenericRAII([&] { ++hasCalledCleanup; })); - GenericRAII sut2(std::move(*sut)); + iox::cxx::optional sut(ScopeGuard([&] { ++hasCalledCleanup; })); + ScopeGuard sut2(std::move(*sut)); sut.reset(); EXPECT_THAT(hasCalledCleanup, Eq(0)); } EXPECT_THAT(hasCalledCleanup, Eq(1)); } -TEST_F(GenericRAII_test, MoveAssignmentCallsCleanup) +TEST_F(ScopeGuard_test, MoveAssignmentCallsCleanup) { ::testing::Test::RecordProperty("TEST_ID", "e0e596af-569b-41c6-b03f-6f8028272f85"); int hasCalledCleanup = 0; int hasCalledCleanup2 = 0; - GenericRAII sut([&] { ++hasCalledCleanup; }); - GenericRAII sut2([&] { ++hasCalledCleanup2; }); + ScopeGuard sut([&] { ++hasCalledCleanup; }); + ScopeGuard sut2([&] { ++hasCalledCleanup2; }); sut = std::move(sut2); @@ -130,15 +130,15 @@ TEST_F(GenericRAII_test, MoveAssignmentCallsCleanup) EXPECT_THAT(hasCalledCleanup2, Eq(0)); } -TEST_F(GenericRAII_test, MoveAssignedCallsCleanupWhenOutOfScope) +TEST_F(ScopeGuard_test, MoveAssignedCallsCleanupWhenOutOfScope) { ::testing::Test::RecordProperty("TEST_ID", "5f142656-ae86-47f2-a1e1-8ed471543d0e"); int hasCalledCleanup = 0; int hasCalledCleanup2 = 0; { - GenericRAII sut([&] { ++hasCalledCleanup; }); - GenericRAII sut2([&] { ++hasCalledCleanup2; }); + ScopeGuard sut([&] { ++hasCalledCleanup; }); + ScopeGuard sut2([&] { ++hasCalledCleanup2; }); sut = std::move(sut2); EXPECT_THAT(hasCalledCleanup, Eq(1)); diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp index fdc2bd4c367..8551e45f264 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp @@ -44,7 +44,7 @@ class ErrorHandlerMock : protected ErrorHandler { public: template - static cxx::GenericRAII setTemporaryErrorHandler(const TypedHandlerFunction& newHandler) noexcept; + static cxx::ScopeGuard setTemporaryErrorHandler(const TypedHandlerFunction& newHandler) noexcept; protected: static std::mutex m_handlerMutex; @@ -76,10 +76,10 @@ inline void errorHandlerForTest(const uint32_t error, const char* errorName, con } template -inline cxx::GenericRAII +inline cxx::ScopeGuard ErrorHandlerMock::setTemporaryErrorHandler(const TypedHandlerFunction& newHandler) noexcept { - return cxx::GenericRAII( + return cxx::ScopeGuard( [&newHandler] { std::lock_guard lock(m_handlerMutex); typedHandler.emplace(newHandler); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp index 8de9bcfbdee..c0ba0d7b02e 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp @@ -17,7 +17,7 @@ #ifndef IOX_POSH_ROUDI_ROUDI_MULTI_PROCESS_HPP #define IOX_POSH_ROUDI_ROUDI_MULTI_PROCESS_HPP -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/internal/concurrent/smart_lock.hpp" #include "iceoryx_hoofs/internal/relocatable_pointer/relative_pointer.hpp" #include "iceoryx_hoofs/platform/file.hpp" @@ -129,7 +129,7 @@ class RouDi void monitorAndDiscoveryUpdate() noexcept; - cxx::GenericRAII m_unregisterRelativePtr{[] { rp::BaseRelativePointer::unregisterAll(); }}; + cxx::ScopeGuard m_unregisterRelativePtr{[] { rp::BaseRelativePointer::unregisterAll(); }}; bool m_killProcessesInDestructor; std::atomic_bool m_runMonitoringAndDiscoveryThread; std::atomic_bool m_runHandleRuntimeMessageThread; @@ -141,7 +141,7 @@ class RouDi /// @note destroy the memory right at the end of the dTor, since the memory is not needed anymore and we know that /// the lifetime of the MemoryBlocks must be at least as long as RouDi; this saves us from issues if the /// RouDiMemoryManager outlives some MemoryBlocks - cxx::GenericRAII m_roudiMemoryManagerCleaner{[this]() { + cxx::ScopeGuard m_roudiMemoryManagerCleaner{[this]() { if (this->m_roudiMemoryInterface->destroyMemory().has_error()) { LogWarn() << "unable to cleanup roudi memory interface"; diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/iceoryx_roudi_components.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/iceoryx_roudi_components.hpp index adcc4b23b51..03e1024ed20 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/iceoryx_roudi_components.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/iceoryx_roudi_components.hpp @@ -18,7 +18,7 @@ #define IOX_POSH_ROUDI_ICEORYX_ROUDI_COMPONENTS_HPP #include "iceoryx_hoofs/cxx/expected.hpp" -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_posh/internal/roudi/port_manager.hpp" #include "iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp" diff --git a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp index cf54f145dfa..f486abb4ad2 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp" diff --git a/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp b/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp index 5f3924051f4..2f20ad11b5a 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/internal/concurrent/smart_lock.hpp" #include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" diff --git a/iceoryx_posh/test/moduletests/test_base_port.cpp b/iceoryx_posh/test/moduletests/test_base_port.cpp index 26e2df399d2..8e2e1104a04 100644 --- a/iceoryx_posh/test/moduletests/test_base_port.cpp +++ b/iceoryx_posh/test/moduletests/test_base_port.cpp @@ -15,8 +15,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" #include "iceoryx_hoofs/cxx/helplets.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/ports/base_port.hpp" diff --git a/iceoryx_posh/test/moduletests/test_capro_message.cpp b/iceoryx_posh/test/moduletests/test_capro_message.cpp index fde4c19ff45..8d245617638 100644 --- a/iceoryx_posh/test/moduletests/test_capro_message.cpp +++ b/iceoryx_posh/test/moduletests/test_capro_message.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_posh/internal/capro/capro_message.hpp" #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" #include "iceoryx_posh/internal/roudi/introspection/port_introspection.hpp" diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index dedbb87d064..05fe4596765 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/allocator.hpp" #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" #include "iceoryx_posh/error_handling/error_handling.hpp" diff --git a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp index 7b3e9321b4f..3521dcd7ec8 100644 --- a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/allocator.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" diff --git a/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp b/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp index 4b6a9f70d97..57dbf4765d3 100644 --- a/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp @@ -16,8 +16,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/cxx/attributes.hpp" -#include "iceoryx_hoofs/cxx/generic_raii.hpp" #include "iceoryx_hoofs/cxx/optional.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" #include "test.hpp" @@ -35,7 +35,7 @@ TEST(UniquePortId_test, SettingTheRouDiIdWorks) // we cannot ensure that setUniqueRouDiId wasn't called before, therefore we ignore the error auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler([](auto, auto) {}); auto uniqueRouDiIdResetScopeGuard = - GenericRAII{[] {}, [] { iox::popo::UniquePortId::setUniqueRouDiId(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID); }}; + ScopeGuard{[] {}, [] { iox::popo::UniquePortId::setUniqueRouDiId(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID); }}; iox::popo::UniquePortId::setUniqueRouDiId(someId); EXPECT_EQ(iox::popo::UniquePortId::getUniqueRouDiId(), someId); } @@ -52,7 +52,7 @@ TEST(UniquePortId_test, SettingTheRouDiIdTwiceFails) detectedErrorLevel.emplace(errorLevel); }); auto uniqueRouDiIdResetScopeGuard = - GenericRAII{[] {}, [] { iox::popo::UniquePortId::setUniqueRouDiId(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID); }}; + ScopeGuard{[] {}, [] { iox::popo::UniquePortId::setUniqueRouDiId(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID); }}; iox::popo::UniquePortId::setUniqueRouDiId(someId); // we don't know if setUniqueRouDiId was called before, therefore ignore any error diff --git a/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp b/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp index c13c2dd4513..48be34196b6 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_posh/internal/roudi/introspection/port_introspection.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp index d2726a75182..3ce73e80fac 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/cxx/convert.hpp" -#include "iceoryx_hoofs/cxx/generic_raii.hpp" +#include "iceoryx_hoofs/cxx/scope_guard.hpp" #include "iceoryx_hoofs/internal/relocatable_pointer/base_relative_pointer.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" @@ -75,7 +75,7 @@ class PortManager_test : public Test iox::RuntimeName_t m_runtimeName{"TestApp"}; - cxx::GenericRAII suppressLogging = iox::LoggerPosh().SetLogLevelForScope(iox::log::LogLevel::kOff); + cxx::ScopeGuard suppressLogging = iox::LoggerPosh().SetLogLevelForScope(iox::log::LogLevel::kOff); cxx::vector internalServices; const capro::ServiceDescription serviceRegistry{