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>
This commit is contained in:
@@ -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__
|
||||
|
||||
Reference in New Issue
Block a user