VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/components/nsComponentManagerUtils.h@ 65902

最後變更 在這個檔案從65902是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.3 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org Code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef nsComponentManagerUtils_h__
39#define nsComponentManagerUtils_h__
40
41/*
42 * Do not include this file directly. Instead,
43 * |#include "nsIComponentManager.h"|.
44 */
45
46#ifndef nsCOMPtr_h__
47#include "nsCOMPtr.h"
48#endif
49
50#ifndef nsComponentManagerObsolete_h___
51#include "nsComponentManagerObsolete.h"
52#endif
53
54#define NS_COMPONENTMANAGER_CID \
55{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
56 0x91775d60, \
57 0xd5dc, \
58 0x11d2, \
59 {0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
60}
61
62class NS_COM nsCreateInstanceByCID : public nsCOMPtr_helper
63{
64public:
65 nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
66 : mCID(aCID),
67 mOuter(aOuter),
68 mErrorPtr(aErrorPtr)
69 {
70 // nothing else to do here
71 }
72
73 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
74
75private:
76 const nsCID& mCID;
77 nsISupports* mOuter;
78 nsresult* mErrorPtr;
79};
80
81class NS_COM nsCreateInstanceByContractID : public nsCOMPtr_helper
82{
83public:
84 nsCreateInstanceByContractID( const char* aContractID, nsISupports* aOuter, nsresult* aErrorPtr )
85 : mContractID(aContractID),
86 mOuter(aOuter),
87 mErrorPtr(aErrorPtr)
88 {
89 // nothing else to do here
90 }
91
92 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
93
94private:
95 const char* mContractID;
96 nsISupports* mOuter;
97 nsresult* mErrorPtr;
98};
99
100inline
101const nsCreateInstanceByCID
102do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
103{
104 return nsCreateInstanceByCID(aCID, 0, error);
105}
106
107inline
108const nsCreateInstanceByCID
109do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
110{
111 return nsCreateInstanceByCID(aCID, aOuter, error);
112}
113
114inline
115const nsCreateInstanceByContractID
116do_CreateInstance( const char* aContractID, nsresult* error = 0 )
117{
118 return nsCreateInstanceByContractID(aContractID, 0, error);
119}
120
121inline
122const nsCreateInstanceByContractID
123do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error = 0 )
124{
125 return nsCreateInstanceByContractID(aContractID, aOuter, error);
126}
127
128// type-safe shortcuts for calling |CreateInstance|
129template <class DestinationType>
130inline
131nsresult
132CallCreateInstance( const nsCID &aClass,
133 nsISupports *aDelegate,
134 DestinationType** aDestination )
135{
136 NS_PRECONDITION(aDestination, "null parameter");
137
138 return nsComponentManager::CreateInstance(aClass, aDelegate,
139 NS_GET_IID(DestinationType),
140 NS_REINTERPRET_CAST(void**, aDestination));
141}
142
143template <class DestinationType>
144inline
145nsresult
146CallCreateInstance( const nsCID &aClass,
147 DestinationType** aDestination )
148{
149 NS_PRECONDITION(aDestination, "null parameter");
150
151 return nsComponentManager::CreateInstance(aClass, nsnull,
152 NS_GET_IID(DestinationType),
153 NS_REINTERPRET_CAST(void**, aDestination));
154}
155
156template <class DestinationType>
157inline
158nsresult
159CallCreateInstance( const char *aContractID,
160 nsISupports *aDelegate,
161 DestinationType** aDestination )
162{
163 NS_PRECONDITION(aContractID, "null parameter");
164 NS_PRECONDITION(aDestination, "null parameter");
165
166 return nsComponentManager::CreateInstance(aContractID,
167 aDelegate,
168 NS_GET_IID(DestinationType),
169 NS_REINTERPRET_CAST(void**, aDestination));
170}
171
172template <class DestinationType>
173inline
174nsresult
175CallCreateInstance( const char *aContractID,
176 DestinationType** aDestination )
177{
178 NS_PRECONDITION(aContractID, "null parameter");
179 NS_PRECONDITION(aDestination, "null parameter");
180
181 return nsComponentManager::CreateInstance(aContractID, nsnull,
182 NS_GET_IID(DestinationType),
183 NS_REINTERPRET_CAST(void**, aDestination));
184}
185
186/* keys for registry use */
187extern const char xpcomKeyName[];
188extern const char xpcomComponentsKeyName[];
189extern const char lastModValueName[];
190extern const char fileSizeValueName[];
191extern const char nativeComponentType[];
192extern const char staticComponentType[];
193
194#endif /* nsComponentManagerUtils_h__ */
195
196
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette