aboutsummaryrefslogtreecommitdiff
path: root/src/util/com_util.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-24 19:06:17 +0800
committercrupest <crupest@outlook.com>2019-03-24 19:06:17 +0800
commit79d1d76509dbf6cf9c79f8eb55968535982975aa (patch)
tree322ed87621506f2e56f4887c73370db769843a29 /src/util/com_util.hpp
parente8be3841457853daefc26d0ca00256ad8c44f593 (diff)
downloadcru-79d1d76509dbf6cf9c79f8eb55968535982975aa.tar.gz
cru-79d1d76509dbf6cf9c79f8eb55968535982975aa.tar.bz2
cru-79d1d76509dbf6cf9c79f8eb55968535982975aa.zip
...
Diffstat (limited to 'src/util/com_util.hpp')
-rw-r--r--src/util/com_util.hpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/com_util.hpp b/src/util/com_util.hpp
new file mode 100644
index 00000000..bbaf1c27
--- /dev/null
+++ b/src/util/com_util.hpp
@@ -0,0 +1,22 @@
+#pragma once
+#include "pre.hpp"
+
+#include <memory>
+
+namespace cru::util {
+
+template <typename TInterface>
+std::shared_ptr<TInterface> CreateComSharedPtr(TInterface* p) {
+ return std::shared_ptr<TInterface>(p, [](TInterface* ptr) {
+ if (ptr != nullptr) ptr->Release();
+ });
+}
+
+template <class TInterface>
+void SafeRelease(TInterface*& p) {
+ if (p != nullptr) {
+ p->Release();
+ p = nullptr;
+ }
+}
+} // namespace cru::util