File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 2020#ifndef IME_COM_PTR_H
2121#define IME_COM_PTR_H
2222
23+ #include < utility>
24+
2325// ATL-indepdent smart pointers for COM objects
2426// very similar to the ones provided by ATL (CComPtr & CComQIPtr).
2527
@@ -30,14 +32,18 @@ namespace Ime {
3032template <class T >
3133class ComPtr {
3234public:
33- ComPtr (void ): p_(NULL ) {
35+ ComPtr (void ): p_(nullptr ) {
3436 }
3537
3638 ComPtr (T* p, bool ref = true ): p_(p) {
3739 if (p_ && ref)
3840 p_->AddRef ();
3941 }
4042
43+ ComPtr (ComPtr&& other) : p_(other.p_) {
44+ other.p_ = nullptr ;
45+ }
46+
4147 ComPtr (const ComPtr& other): p_(other.p_) {
4248 if (p_)
4349 p_->AddRef ();
@@ -81,6 +87,12 @@ class ComPtr {
8187 return p_ < p;
8288 }
8389
90+ ComPtr& operator = (ComPtr&& other) {
91+ p_ = other.p_ ;
92+ other.p_ = nullptr ;
93+ return *this ;
94+ }
95+
8496 ComPtr& operator = (const ComPtr& other) {
8597 return operator = (other.p_ );
8698 }
@@ -118,6 +130,9 @@ class ComQIPtr: public ComPtr<T> {
118130 ComQIPtr (const ComQIPtr& other): ComPtr<T>(other) {
119131 }
120132
133+ ComQIPtr (ComQIPtr&& other) : ComPtr<T>(std::move(other)) {
134+ }
135+
121136 ComQIPtr (IUnknown* p) {
122137 if (p) {
123138 p->QueryInterface (__uuidof (T), (void **)&p_);
You can’t perform that action at this time.
0 commit comments