summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-10-04 03:12:35 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-09-05 16:12:35 +0300
commit481fc69e7cfee17782a3086e51c9b86daa80a37d (patch)
tree22c443988dca2b0aeb10fc9e96dab023cc38e082 /include
parent8161018b9b2a161b83072d5ddec7658079850c21 (diff)
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/base/utils.h13
1 files changed, 13 insertions, 0 deletions
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 <algorithm>
#include <chrono>
+#include <functional>
#include <iterator>
#include <ostream>
#include <sstream>
@@ -398,6 +399,18 @@ constexpr std::underlying_type_t<Enum> to_underlying(Enum e) noexcept
return static_cast<std::underlying_type_t<Enum>>(e);
}
+class ScopeExitActions
+{
+public:
+ ~ScopeExitActions();
+
+ void operator+=(std::function<void()> &&action);
+ void release();
+
+private:
+ std::vector<std::function<void()>> actions_;
+};
+
} /* namespace utils */
#ifndef __DOXYGEN__