Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1450 Rename GenericRAII to ScopeGuard
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Hoinkis <[email protected]>
  • Loading branch information
mossmaurice committed Aug 22, 2022
1 parent f6d4a3f commit 872b401
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, 6>`.|
|`list` | | Heap and exception free, relocatable implementation of `std::list` |
|`NewType<T, Policies>` | | C++11 implementation of [Haskells NewType-pattern](https://wiki.haskell.org/Newtype). |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -42,31 +42,31 @@ namespace cxx
/// }
/// @endcode
template <uint64_t CleanupCapacity = DEFAULT_FUNCTION_CAPACITY>
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<void(), CleanupCapacity>& cleanupFunction) noexcept;
explicit ScopeGuardWithVariableCapacity(const function<void(), CleanupCapacity>& 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<void()>& initFunction,
const function<void()>& cleanupFunction) noexcept;
ScopeGuardWithVariableCapacity(const function_ref<void()>& initFunction,
const function<void()>& 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;
Expand All @@ -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
8 changes: 4 additions & 4 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/scoped_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, typename... CTorArgs>
GenericRAII makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept;
ScopeGuard makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept;
} // namespace cxx
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,46 @@
//
// 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 <uint64_t Capacity>
inline GenericRAIIWithVariableCapacity<Capacity>::GenericRAIIWithVariableCapacity(
inline ScopeGuardWithVariableCapacity<Capacity>::ScopeGuardWithVariableCapacity(
const cxx::function<void(), Capacity>& cleanupFunction) noexcept
: m_cleanupFunction(cleanupFunction)
{
}

template <uint64_t Capacity>
inline GenericRAIIWithVariableCapacity<Capacity>::GenericRAIIWithVariableCapacity(
inline ScopeGuardWithVariableCapacity<Capacity>::ScopeGuardWithVariableCapacity(
const function_ref<void()>& initFunction, const function<void()>& cleanupFunction) noexcept
: m_cleanupFunction(cleanupFunction)
{
initFunction();
}

template <uint64_t Capacity>
inline GenericRAIIWithVariableCapacity<Capacity>::~GenericRAIIWithVariableCapacity() noexcept
inline ScopeGuardWithVariableCapacity<Capacity>::~ScopeGuardWithVariableCapacity() noexcept
{
destroy();
}

template <uint64_t Capacity>
inline GenericRAIIWithVariableCapacity<Capacity>::GenericRAIIWithVariableCapacity(
GenericRAIIWithVariableCapacity&& rhs) noexcept
inline ScopeGuardWithVariableCapacity<Capacity>::ScopeGuardWithVariableCapacity(
ScopeGuardWithVariableCapacity&& rhs) noexcept
{
*this = std::move(rhs);
}

template <uint64_t Capacity>
inline GenericRAIIWithVariableCapacity<Capacity>&
GenericRAIIWithVariableCapacity<Capacity>::operator=(GenericRAIIWithVariableCapacity<Capacity>&& rhs) noexcept
inline ScopeGuardWithVariableCapacity<Capacity>&
ScopeGuardWithVariableCapacity<Capacity>::operator=(ScopeGuardWithVariableCapacity<Capacity>&& rhs) noexcept
{
if (this != &rhs)
{
Expand All @@ -66,7 +66,7 @@ GenericRAIIWithVariableCapacity<Capacity>::operator=(GenericRAIIWithVariableCapa
}

template <uint64_t Capacity>
inline void GenericRAIIWithVariableCapacity<Capacity>::destroy() noexcept
inline void ScopeGuardWithVariableCapacity<Capacity>::destroy() noexcept
{
if (m_cleanupFunction)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace iox
namespace cxx
{
template <typename T, typename... CTorArgs>
inline GenericRAII makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept
inline ScopeGuard makeScopedStatic(T& memory, CTorArgs&&... ctorArgs) noexcept
{
memory.emplace(std::forward<CTorArgs>(ctorArgs)...);
return GenericRAII([&memory] { memory.reset(); });
return ScopeGuard([&memory] { memory.reset(); });
}
} // namespace cxx
} // namespace iox
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/source/log/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -72,7 +72,7 @@ cxx::expected<SharedMemory, SharedMemoryError> 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)
{
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -323,7 +323,7 @@ cxx::expected<IpcChannelError> 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)
Expand Down
Loading

0 comments on commit 872b401

Please sign in to comment.