mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 16:30:32 +00:00
35f2d342a0
- Added ImGui Module Manager that that implements module logic and manages other module resources. - Added Texture Manager to manage texture resources and maps them to index that can be passed to ImGui context. - Added Context Proxy that represents and manages a single ImGui context. - Added Slate ImGui Widget to render ImGui output.
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
#pragma once
|
|
|
|
namespace ScopeGuards
|
|
{
|
|
// Saves snapshot of the object state and restores it during destruction.
|
|
template<typename T>
|
|
class TStateSaver
|
|
{
|
|
public:
|
|
|
|
// Constructor taking target object in state that we want to save.
|
|
TStateSaver(T& Target)
|
|
: Ptr(&Target)
|
|
, Value(Target)
|
|
{
|
|
}
|
|
|
|
// Move constructor allowing to transfer state out of scope.
|
|
TStateSaver(TStateSaver&& Other)
|
|
: Ptr(Other.Ptr)
|
|
, Value(MoveTemp(Other.Value))
|
|
{
|
|
// Release responsibility from the other object (std::exchange currently not supported by all platforms).
|
|
Other.Ptr = nullptr;
|
|
}
|
|
|
|
// Non-assignable to enforce acquisition on construction.
|
|
TStateSaver& operator=(TStateSaver&&) = delete;
|
|
|
|
// Non-copyable.
|
|
TStateSaver(const TStateSaver&) = delete;
|
|
TStateSaver& operator=(const TStateSaver&) = delete;
|
|
|
|
~TStateSaver()
|
|
{
|
|
if (Ptr)
|
|
{
|
|
*Ptr = Value;
|
|
}
|
|
}
|
|
|
|
private:
|
|
|
|
T* Ptr;
|
|
T Value;
|
|
};
|
|
|
|
// Create a state saver for target object. Unless saver is moved, state will be restored at the end of scope.
|
|
// @param Target - Target object in state that we want to save
|
|
// @returns State saver that unless moved, will restore target's state during scope exit
|
|
template<typename T>
|
|
TStateSaver<T> MakeStateSaver(T& Target)
|
|
{
|
|
return TStateSaver<T>{ Target };
|
|
}
|
|
}
|