From 481fc69e7cfee17782a3086e51c9b86daa80a37d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 4 Oct 2022 03:12:35 +0300 Subject: libcamera: utils: Add ScopeExitActions class The ScopeExitActions class is a simple object that performs user-provided actions upon destruction. It is meant to simplify cleanup tasks in error handling paths. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Paul Elder Reviewed-by: Umang Jain --- include/libcamera/base/utils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include') diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index a9b27d0f..957150cb 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -398,6 +399,18 @@ constexpr std::underlying_type_t to_underlying(Enum e) noexcept return static_cast>(e); } +class ScopeExitActions +{ +public: + ~ScopeExitActions(); + + void operator+=(std::function &&action); + void release(); + +private: + std::vector> actions_; +}; + } /* namespace utils */ #ifndef __DOXYGEN__ -- cgit v1.2.1