summaryrefslogtreecommitdiffhomepage
path: root/tracker-kinect-face/tracker.h
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-kinect-face/tracker.h')
-rw-r--r--tracker-kinect-face/tracker.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/tracker-kinect-face/tracker.h b/tracker-kinect-face/tracker.h
index 5068f185..220a126f 100644
--- a/tracker-kinect-face/tracker.h
+++ b/tracker-kinect-face/tracker.h
@@ -14,7 +14,7 @@
#pragma once
-// Safe release for interfaces
+// @deprecated Use UniqueInterface instead. Remove it at some point.
template<class Interface>
inline void SafeRelease(Interface *& pInterfaceToRelease)
{
@@ -25,6 +25,32 @@ inline void SafeRelease(Interface *& pInterfaceToRelease)
}
}
+template<class Interface>
+inline void ReleaseInterface(Interface* pInterfaceToRelease)
+{
+ if (pInterfaceToRelease != nullptr)
+ {
+ pInterfaceToRelease->Release();
+ }
+}
+
+// Safely use Microsoft interfaces.
+template<typename T>
+class UniqueInterface : public std::unique_ptr<T, decltype(&ReleaseInterface<T>)> ///**/
+{
+public:
+ UniqueInterface() : std::unique_ptr<T, decltype(&ReleaseInterface<T>)>(nullptr, ReleaseInterface<T>){}
+ // Access pointer, typically for creation
+ T** PtrPtr() { return &iPtr; };
+ // Called this once the pointer was created
+ void Reset() { std::unique_ptr<T, decltype(&ReleaseInterface<T>)>::reset(iPtr); }
+ // If ever you want to release that interface before the object is deleted
+ void Free() { iPtr = nullptr; Reset(); }
+private:
+ T* iPtr = nullptr;
+};
+
+
class KinectFaceTracker : public ITracker
{