VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/base/nsAgg.h@ 45791

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

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 9.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 nsAgg_h___
39#define nsAgg_h___
40
41#include "nsISupports.h"
42
43
44////////////////////////////////////////////////////////////////////////////////
45
46// Put this in your class's declaration:
47#define NS_DECL_AGGREGATED \
48 NS_DECL_ISUPPORTS \
49 \
50public: \
51 \
52 /* You must implement this operation instead of the nsISupports */ \
53 /* methods if you inherit from nsAggregated. */ \
54 NS_IMETHOD \
55 AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr); \
56 \
57protected: \
58 \
59 class Internal : public nsISupports { \
60 public: \
61 \
62 Internal() {} \
63 \
64 NS_IMETHOD QueryInterface(const nsIID& aIID, \
65 void** aInstancePtr); \
66 NS_IMETHOD_(nsrefcnt) AddRef(void); \
67 NS_IMETHOD_(nsrefcnt) Release(void); \
68 \
69 }; \
70 \
71 friend class Internal; \
72 \
73 nsISupports* fOuter; \
74 Internal fAggregated; \
75 \
76 nsISupports* GetInner(void) { return &fAggregated; } \
77 \
78public: \
79
80
81// Put this in your class's constructor:
82#define NS_INIT_AGGREGATED(outer) \
83 PR_BEGIN_MACRO \
84 fOuter = outer ? outer : &fAggregated; \
85 PR_END_MACRO
86
87
88// Put this in your class's implementation file:
89#define NS_IMPL_AGGREGATED(_class) \
90NS_IMETHODIMP \
91_class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
92{ \
93 return fOuter->QueryInterface(aIID, aInstancePtr); \
94} \
95 \
96NS_IMETHODIMP_(nsrefcnt) \
97_class::AddRef(void) \
98{ \
99 return fOuter->AddRef(); \
100} \
101 \
102NS_IMETHODIMP_(nsrefcnt) \
103_class::Release(void) \
104{ \
105 return fOuter->Release(); \
106} \
107 \
108NS_IMETHODIMP \
109_class::Internal::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
110{ \
111 _class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
112 return agg->AggregatedQueryInterface(aIID, aInstancePtr); \
113} \
114 \
115NS_IMETHODIMP_(nsrefcnt) \
116_class::Internal::AddRef(void) \
117{ \
118 _class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
119 NS_PRECONDITION(PRInt32(agg->mRefCnt) >= 0, "illegal refcnt"); \
120 ++agg->mRefCnt; \
121 NS_LOG_ADDREF(this, agg->mRefCnt, #_class, sizeof(*this)); \
122 return agg->mRefCnt; \
123} \
124 \
125NS_IMETHODIMP_(nsrefcnt) \
126_class::Internal::Release(void) \
127{ \
128 _class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
129 NS_PRECONDITION(0 != agg->mRefCnt, "dup release"); \
130 --agg->mRefCnt; \
131 NS_LOG_RELEASE(this, agg->mRefCnt, #_class); \
132 if (agg->mRefCnt == 0) { \
133 agg->mRefCnt = 1; /* stabilize */ \
134 NS_DELETEXPCOM(agg); \
135 return 0; \
136 } \
137 return agg->mRefCnt; \
138} \
139
140// for use with QI macros in nsISupportsUtils.h:
141
142#define NS_INTERFACE_MAP_BEGIN_AGGREGATED(_class) \
143 NS_IMPL_AGGREGATED_QUERY_HEAD(_class)
144
145#define NS_IMPL_AGGREGATED_QUERY_HEAD(_class) \
146NS_IMETHODIMP \
147_class::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr) \
148{ \
149 NS_ASSERTION(aInstancePtr, \
150 "AggregatedQueryInterface requires a non-NULL result ptr!"); \
151 if ( !aInstancePtr ) \
152 return NS_ERROR_NULL_POINTER; \
153 nsISupports* foundInterface;
154
155#endif /* nsAgg_h___ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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