/src/mozilla-central/xpcom/base/nsQueryObject.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsQueryObject_h |
8 | | #define nsQueryObject_h |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | |
12 | | #include "nsCOMPtr.h" |
13 | | #include "mozilla/RefPtr.h" |
14 | | |
15 | | /*****************************************************************************/ |
16 | | |
17 | | template<class T> |
18 | | class MOZ_STACK_CLASS nsQueryObject final : public nsCOMPtr_helper |
19 | | { |
20 | | public: |
21 | | explicit nsQueryObject(T* aRawPtr) |
22 | | : mRawPtr(aRawPtr) |
23 | 0 | { |
24 | 0 | } Unexecuted instantiation: nsQueryObject<TestNsRefPtr::Foo>::nsQueryObject(TestNsRefPtr::Foo*) Unexecuted instantiation: nsQueryObject<TestNsRefPtr::Bar>::nsQueryObject(TestNsRefPtr::Bar*) |
25 | | |
26 | | virtual nsresult NS_FASTCALL operator()(const nsIID& aIID, |
27 | | void** aResult) const override |
28 | 0 | { |
29 | 0 | nsresult status = mRawPtr ? mRawPtr->QueryInterface(aIID, aResult) |
30 | 0 | : NS_ERROR_NULL_POINTER; |
31 | 0 | return status; |
32 | 0 | } Unexecuted instantiation: nsQueryObject<TestNsRefPtr::Foo>::operator()(nsID const&, void**) const Unexecuted instantiation: nsQueryObject<TestNsRefPtr::Bar>::operator()(nsID const&, void**) const |
33 | | private: |
34 | | T* MOZ_NON_OWNING_REF mRawPtr; |
35 | | }; |
36 | | |
37 | | template<class T> |
38 | | class MOZ_STACK_CLASS nsQueryObjectWithError final : public nsCOMPtr_helper |
39 | | { |
40 | | public: |
41 | | nsQueryObjectWithError(T* aRawPtr, nsresult* aErrorPtr) |
42 | | : mRawPtr(aRawPtr), mErrorPtr(aErrorPtr) |
43 | | { |
44 | | } |
45 | | |
46 | | virtual nsresult NS_FASTCALL operator()(const nsIID& aIID, |
47 | | void** aResult) const override |
48 | | { |
49 | | nsresult status = mRawPtr ? mRawPtr->QueryInterface(aIID, aResult) |
50 | | : NS_ERROR_NULL_POINTER; |
51 | | if (mErrorPtr) { |
52 | | *mErrorPtr = status; |
53 | | } |
54 | | return status; |
55 | | } |
56 | | private: |
57 | | T* MOZ_NON_OWNING_REF mRawPtr; |
58 | | nsresult* mErrorPtr; |
59 | | }; |
60 | | |
61 | | /*****************************************************************************/ |
62 | | |
63 | | /*****************************************************************************/ |
64 | | |
65 | | template<class T> |
66 | | inline nsQueryObject<T> |
67 | | do_QueryObject(T* aRawPtr) |
68 | 0 | { |
69 | 0 | return nsQueryObject<T>(aRawPtr); |
70 | 0 | } Unexecuted instantiation: nsQueryObject<TestNsRefPtr::Foo> do_QueryObject<TestNsRefPtr::Foo>(TestNsRefPtr::Foo*) Unexecuted instantiation: nsQueryObject<TestNsRefPtr::Bar> do_QueryObject<TestNsRefPtr::Bar>(TestNsRefPtr::Bar*) |
71 | | |
72 | | template<class T> |
73 | | inline nsQueryObject<T> |
74 | | do_QueryObject(nsCOMPtr<T>& aRawPtr) |
75 | | { |
76 | | return nsQueryObject<T>(aRawPtr); |
77 | | } |
78 | | |
79 | | template<class T> |
80 | | inline nsQueryObject<T> |
81 | | do_QueryObject(RefPtr<T>& aRawPtr) |
82 | 0 | { |
83 | 0 | return nsQueryObject<T>(aRawPtr); |
84 | 0 | } |
85 | | |
86 | | template<class T> |
87 | | inline nsQueryObjectWithError<T> |
88 | | do_QueryObject(T* aRawPtr, nsresult* aErrorPtr) |
89 | | { |
90 | | return nsQueryObjectWithError<T>(aRawPtr, aErrorPtr); |
91 | | } |
92 | | |
93 | | template<class T> |
94 | | inline nsQueryObjectWithError<T> |
95 | | do_QueryObject(nsCOMPtr<T>& aRawPtr, nsresult* aErrorPtr) |
96 | | { |
97 | | return nsQueryObjectWithError<T>(aRawPtr, aErrorPtr); |
98 | | } |
99 | | |
100 | | template<class T> |
101 | | inline nsQueryObjectWithError<T> |
102 | | do_QueryObject(RefPtr<T>& aRawPtr, nsresult* aErrorPtr) |
103 | | { |
104 | | return nsQueryObjectWithError<T>(aRawPtr, aErrorPtr); |
105 | | } |
106 | | |
107 | | /*****************************************************************************/ |
108 | | |
109 | | #endif // !defined(nsQueryObject_h) |