UWARG Computer Vision
ComPtr.h
1 /*
2  * ComPtr.h - Implementación de puntero inteligente para interfaces COM
3  *
4  * Copyright 2013 Jesús Torres <jmtorres@ull.es>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef COMPTR_H_
20 #define COMPTR_H_
21 
22 #include <LinuxCOM.h>
23 
24 #include <boost/intrusive_ptr.hpp>
25 #include <boost/static_assert.hpp>
26 #include <boost/type_traits.hpp>
27 
28 template <typename T>
29 class ComPtr : public boost::intrusive_ptr<T>
30 {
31  BOOST_STATIC_ASSERT((boost::is_base_of<IUnknown, T>::value));
32 
33  public:
34  ComPtr();
35  ComPtr(T* p, bool add_ref = false);
36  ComPtr(ComPtr const& r);
37  template<typename Y>
38  ComPtr(ComPtr<Y> const& r);
39 };
40 
41 template <typename T>
43  : boost::intrusive_ptr<T>()
44 {
45 }
46 
47 template <typename T>
48 ComPtr<T>::ComPtr(T* p, bool add_ref)
49  : boost::intrusive_ptr<T>(p, add_ref)
50 {
51 }
52 
53 template <typename T>
54 ComPtr<T>::ComPtr(ComPtr const& r)
55  : boost::intrusive_ptr<T>(r)
56 {
57 }
58 
59 template <typename T>
60 template <typename Y>
62  : boost::intrusive_ptr<T>(r)
63 {
64 }
65 
66 inline void intrusive_ptr_add_ref(IUnknown* p)
67 {
68  p->AddRef();
69 }
70 
71 inline void intrusive_ptr_release(IUnknown* p)
72 {
73  p->Release();
74 }
75 
76 #endif /* COMPTR_H_ */
Definition: ComPtr.h:29