~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpcom/components/nsComponentManagerUtils.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/*
 
3
 * The contents of this file are subject to the Netscape Public License
 
4
 * Version 1.1 (the "NPL"); you may not use this file except in
 
5
 * compliance with the NPL.  You may obtain a copy of the NPL at
 
6
 * http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the NPL is distributed on an "AS IS" basis,
 
9
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
 
10
 * for the specific language governing rights and limitations under the
 
11
 * NPL.
 
12
 *
 
13
 * The Initial Developer of this code under the NPL is Netscape
 
14
 * Communications Corporation.  Portions created by Netscape are
 
15
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 
16
 * Reserved.
 
17
 */
 
18
 
 
19
#ifndef nsComponentManagerUtils_h__
 
20
#define nsComponentManagerUtils_h__
 
21
 
 
22
/*
 
23
 * Do not include this file directly.  Instead,
 
24
 * |#include "nsIComponentManager.h"|.
 
25
 */
 
26
 
 
27
#ifndef nsCOMPtr_h__
 
28
#include "nsCOMPtr.h"
 
29
#endif
 
30
 
 
31
#ifndef nsComponentManagerObsolete_h___
 
32
#include "nsComponentManagerObsolete.h"
 
33
#endif
 
34
 
 
35
#define NS_COMPONENTMANAGER_CID                      \
 
36
{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */         \
 
37
    0x91775d60,                                      \
 
38
    0xd5dc,                                          \
 
39
    0x11d2,                                          \
 
40
    {0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
 
41
}
 
42
 
 
43
class NS_COM nsCreateInstanceByCID : public nsCOMPtr_helper
 
44
{
 
45
public:
 
46
    nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
 
47
        : mCID(aCID),
 
48
          mOuter(aOuter),
 
49
          mErrorPtr(aErrorPtr)
 
50
    {
 
51
        // nothing else to do here
 
52
    }
 
53
    
 
54
    virtual nsresult operator()( const nsIID&, void** ) const;
 
55
    
 
56
private:
 
57
    const nsCID&        mCID;
 
58
    nsISupports*        mOuter;
 
59
    nsresult*           mErrorPtr;
 
60
};
 
61
 
 
62
class NS_COM nsCreateInstanceByContractID : public nsCOMPtr_helper
 
63
{
 
64
public:
 
65
    nsCreateInstanceByContractID( const char* aContractID, nsISupports* aOuter, nsresult* aErrorPtr )
 
66
        : mContractID(aContractID),
 
67
          mOuter(aOuter),
 
68
          mErrorPtr(aErrorPtr)
 
69
                                {
 
70
                                        // nothing else to do here
 
71
                                }
 
72
    
 
73
    virtual nsresult operator()( const nsIID&, void** ) const;
 
74
    
 
75
private:
 
76
    const char*   mContractID;
 
77
    nsISupports*  mOuter;
 
78
    nsresult*     mErrorPtr;
 
79
};
 
80
 
 
81
inline
 
82
const nsCreateInstanceByCID
 
83
do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
 
84
{
 
85
    return nsCreateInstanceByCID(aCID, 0, error);
 
86
}
 
87
 
 
88
inline
 
89
const nsCreateInstanceByCID
 
90
do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
 
91
{
 
92
    return nsCreateInstanceByCID(aCID, aOuter, error);
 
93
}
 
94
 
 
95
inline
 
96
const nsCreateInstanceByContractID
 
97
do_CreateInstance( const char* aContractID, nsresult* error = 0 )
 
98
{
 
99
    return nsCreateInstanceByContractID(aContractID, 0, error);
 
100
}
 
101
 
 
102
inline
 
103
const nsCreateInstanceByContractID
 
104
do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error = 0 )
 
105
{
 
106
    return nsCreateInstanceByContractID(aContractID, aOuter, error);
 
107
}
 
108
 
 
109
// type-safe shortcuts for calling |CreateInstance|
 
110
template <class DestinationType>
 
111
inline
 
112
nsresult
 
113
CallCreateInstance( const nsCID &aClass,
 
114
                    nsISupports *aDelegate,
 
115
                    DestinationType** aDestination )
 
116
{
 
117
    NS_PRECONDITION(aDestination, "null parameter");
 
118
    
 
119
    return nsComponentManager::CreateInstance(aClass, aDelegate,
 
120
                                              NS_GET_IID(DestinationType),
 
121
                                              NS_REINTERPRET_CAST(void**, aDestination));
 
122
}
 
123
 
 
124
template <class DestinationType>
 
125
inline
 
126
nsresult
 
127
CallCreateInstance( const nsCID &aClass,
 
128
                    DestinationType** aDestination )
 
129
{
 
130
    NS_PRECONDITION(aDestination, "null parameter");
 
131
    
 
132
    return nsComponentManager::CreateInstance(aClass, nsnull,
 
133
                                              NS_GET_IID(DestinationType),
 
134
                                              NS_REINTERPRET_CAST(void**, aDestination));
 
135
}
 
136
 
 
137
template <class DestinationType>
 
138
inline
 
139
nsresult
 
140
CallCreateInstance( const char *aContractID,
 
141
                    nsISupports *aDelegate,
 
142
                    DestinationType** aDestination )
 
143
{
 
144
    NS_PRECONDITION(aContractID, "null parameter");
 
145
    NS_PRECONDITION(aDestination, "null parameter");
 
146
    
 
147
    return nsComponentManager::CreateInstance(aContractID, 
 
148
                                              aDelegate,
 
149
                                              NS_GET_IID(DestinationType),
 
150
                                              NS_REINTERPRET_CAST(void**, aDestination));
 
151
}
 
152
 
 
153
template <class DestinationType>
 
154
inline
 
155
nsresult
 
156
CallCreateInstance( const char *aContractID,
 
157
                    DestinationType** aDestination )
 
158
{
 
159
    NS_PRECONDITION(aContractID, "null parameter");
 
160
    NS_PRECONDITION(aDestination, "null parameter");
 
161
    
 
162
    return nsComponentManager::CreateInstance(aContractID, nsnull,
 
163
                                              NS_GET_IID(DestinationType),
 
164
                                              NS_REINTERPRET_CAST(void**, aDestination));
 
165
}
 
166
 
 
167
/* keys for registry use */
 
168
extern const char xpcomKeyName[];
 
169
extern const char xpcomComponentsKeyName[];
 
170
extern const char lastModValueName[];
 
171
extern const char fileSizeValueName[];
 
172
extern const char nativeComponentType[];
 
173
extern const char staticComponentType[];
 
174
 
 
175
#endif /* nsComponentManagerUtils_h__ */
 
176
 
 
177