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