Aufgrund eines Versionsupdates wird GitLab am 01.04. zwischen 9:00 und 9:30 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to a version upgrade, GitLab won't be accessible at 01.04. between 9:00 and 9:30 a.m.

Commit 99882a22 authored by Martin Kröning's avatar Martin Kröning

Remove DeferralActionWrapper.hpp

parent 1db1f11a
#pragma once
#include <functional>
#include <vector>
/// Wraps an object and defers modifying actions
/// until explicitly applying them
///
/// \param T The type of the wrapped object
template <typename T> class DeferralActionWrapper {
public:
using ValueType = T;
using Function = std::function<void(ValueType &)>;
/// Constructs a wrapper around a default constructed object
DeferralActionWrapper() = default;
/// Constructs a wrapper around a given \p object
explicit DeferralActionWrapper(ValueType object)
: wrappedObject(std::move(object)) {}
/// Returns a the wrapped object
ValueType &get() { return wrappedObject; }
const ValueType &get() const { return wrappedObject; }
/// Enqueues an \p action
///
/// Caution: Be sure to work on a reference to modify the wrapped object!
void enqueue(Function action) {
deferredActions.push_back(std::move(action));
}
/// Applies pending modifying actions
void apply() {
for (auto &&action : deferredActions) {
action(wrappedObject);
}
deferredActions.clear();
}
private:
ValueType wrappedObject;
std::vector<Function> deferredActions;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment