Skip to content

Instantly share code, notes, and snippets.

@ffAudio
Created April 18, 2021 14:02
Show Gist options
  • Save ffAudio/cfe4da1670f606728b8ceef2b8ccf321 to your computer and use it in GitHub Desktop.
Save ffAudio/cfe4da1670f606728b8ceef2b8ccf321 to your computer and use it in GitHub Desktop.
A scoped pointer for MediaFoundation classes
template<typename T>
class MFSafePointer
{
public:
MFSafePointer() = default;
~MFSafePointer()
{
reset();
}
T* get()
{
return pointer;
}
T** getPointer()
{
jassert (pointer == nullptr);
return &pointer;
}
T* operator->()
{
return pointer;
}
void reset (T* p = nullptr)
{
if (pointer) pointer->Release();
pointer = p;
}
private:
T* pointer = nullptr;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MFSafePointer)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment