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
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/
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
15
* The Original Code is mozilla.org code.
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.
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.
36
* ***** END LICENSE BLOCK ***** */
41
#include "nsISupports.h"
44
////////////////////////////////////////////////////////////////////////////////
46
// Put this in your class's declaration:
47
#define NS_DECL_AGGREGATED \
52
/* You must implement this operation instead of the nsISupports */ \
53
/* methods if you inherit from nsAggregated. */ \
55
AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr); \
59
class Internal : public nsISupports { \
64
NS_IMETHOD QueryInterface(const nsIID& aIID, \
65
void** aInstancePtr); \
66
NS_IMETHOD_(nsrefcnt) AddRef(void); \
67
NS_IMETHOD_(nsrefcnt) Release(void); \
71
friend class Internal; \
73
nsISupports* fOuter; \
74
Internal fAggregated; \
76
nsISupports* GetInner(void) { return &fAggregated; } \
81
// Put this in your class's constructor:
82
#define NS_INIT_AGGREGATED(outer) \
84
fOuter = outer ? outer : &fAggregated; \
88
// Put this in your class's implementation file:
89
#define NS_IMPL_AGGREGATED(_class) \
91
_class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
93
return fOuter->QueryInterface(aIID, aInstancePtr); \
96
NS_IMETHODIMP_(nsrefcnt) \
97
_class::AddRef(void) \
99
return fOuter->AddRef(); \
102
NS_IMETHODIMP_(nsrefcnt) \
103
_class::Release(void) \
105
return fOuter->Release(); \
109
_class::Internal::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
111
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
112
return agg->AggregatedQueryInterface(aIID, aInstancePtr); \
115
NS_IMETHODIMP_(nsrefcnt) \
116
_class::Internal::AddRef(void) \
118
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
119
NS_PRECONDITION(PRInt32(agg->mRefCnt) >= 0, "illegal refcnt"); \
121
NS_LOG_ADDREF(this, agg->mRefCnt, #_class, sizeof(*this)); \
122
return agg->mRefCnt; \
125
NS_IMETHODIMP_(nsrefcnt) \
126
_class::Internal::Release(void) \
128
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
129
NS_PRECONDITION(0 != agg->mRefCnt, "dup release"); \
131
NS_LOG_RELEASE(this, agg->mRefCnt, #_class); \
132
if (agg->mRefCnt == 0) { \
133
agg->mRefCnt = 1; /* stabilize */ \
134
NS_DELETEXPCOM(agg); \
137
return agg->mRefCnt; \
140
// for use with QI macros in nsISupportsUtils.h:
142
#define NS_INTERFACE_MAP_BEGIN_AGGREGATED(_class) \
143
NS_IMPL_AGGREGATED_QUERY_HEAD(_class)
145
#define NS_IMPL_AGGREGATED_QUERY_HEAD(_class) \
147
_class::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr) \
149
NS_ASSERTION(aInstancePtr, \
150
"AggregatedQueryInterface requires a non-NULL result ptr!"); \
151
if ( !aInstancePtr ) \
152
return NS_ERROR_NULL_POINTER; \
153
nsISupports* foundInterface;
155
#endif /* nsAgg_h___ */