🛰️航天仿真算法库 SpaceAST 0.3.1
载入中...
搜索中...
未找到
COMUtil.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24
25#if defined(_WIN32) && !defined(SWIG)
26#include <Windows.h>
27#endif
28
29AST_NAMESPACE_BEGIN
30
31#if defined(_WIN32) && !defined(SWIG)
32
35class CoInitializeGuard
36{
37public:
38 explicit CoInitializeGuard(COINIT initFlags) : hr_(CoInitializeEx(nullptr, initFlags)) {}
39 ~CoInitializeGuard() { if (SUCCEEDED(hr_)) CoUninitialize(); }
40 CoInitializeGuard(const CoInitializeGuard&) = delete;
41 CoInitializeGuard& operator=(const CoInitializeGuard&) = delete;
42 HRESULT hr_{};
43};
44
48AST_UTIL_API HRESULT aEnsureCoInitialized();
49
50
51
55template <typename T>
56class ComScopedPtr
57{
58public:
59 ComScopedPtr() = default;
60 ComScopedPtr(const ComScopedPtr&) = delete;
61 ComScopedPtr& operator=(const ComScopedPtr&) = delete;
62 ComScopedPtr(ComScopedPtr&& other) noexcept : p_(other.p_) { other.p_ = nullptr; }
63 ComScopedPtr& operator=(ComScopedPtr&& other) noexcept{std::swap(p_, other.p_); return *this;}
64 ~ComScopedPtr() { reset(); }
65
67 T* get() const { return p_; }
68 T* operator->() const { return p_; }
69 T& operator*() const { return *p_; }
70
73 T** operator&() { return &p_; }
74
76 void reset() { if (p_) p_->Release(); p_ = nullptr; }
77
78 operator bool() const { return p_ != nullptr; }
79private:
80 T* p_{nullptr};
81};
82
83#else
84
85// 非 Windows 平台:空实现
87{
88public:
89 explicit CoInitializeGuard(int) {}
90 int hr_ = 0;
91};
92
93A_ALWAYS_INLINE int aEnsureCoInitialized() { return 0; }
94
95#endif
96
97AST_NAMESPACE_END
定义 COMUtil.hpp:87
Unit T
特斯拉
定义 Unit.cpp:492