VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/ds/nsVariant.h@ 16393

Last change on this file since 16393 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is mozilla.org code.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * John Bandhauer <[email protected]>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40/* The long avoided variant support for xpcom. */
41
42#include "nsIVariant.h"
43#include "nsStringFwd.h"
44#include "xpt_struct.h"
45
46/**
47 * Map the nsAUTF8String, nsUTF8String classes to the nsACString and
48 * nsCString classes respectively for now. These defines need to be removed
49 * once Jag lands his nsUTF8String implementation.
50 */
51#define nsAUTF8String nsACString
52#define nsUTF8String nsCString
53#define PromiseFlatUTF8String PromiseFlatCString
54
55/**
56 * nsDiscriminatedUnion is a type that nsIVariant implementors *may* use
57 * to hold underlying data. It has no methods. So, its use requires no linkage
58 * to the xpcom module.
59 */
60
61struct nsDiscriminatedUnion
62{
63 union {
64 PRInt8 mInt8Value;
65 PRInt16 mInt16Value;
66 PRInt32 mInt32Value;
67 PRInt64 mInt64Value;
68 PRUint8 mUint8Value;
69 PRUint16 mUint16Value;
70 PRUint32 mUint32Value;
71 PRUint64 mUint64Value;
72 float mFloatValue;
73 double mDoubleValue;
74 PRBool mBoolValue;
75 char mCharValue;
76 PRUnichar mWCharValue;
77 nsIID mIDValue;
78 nsAString* mAStringValue;
79 nsAUTF8String* mUTF8StringValue;
80 nsACString* mCStringValue;
81 struct {
82 nsISupports* mInterfaceValue;
83 nsIID mInterfaceID;
84 } iface;
85 struct {
86 nsIID mArrayInterfaceID;
87 void* mArrayValue;
88 PRUint32 mArrayCount;
89 PRUint16 mArrayType;
90 } array;
91 struct {
92 char* mStringValue;
93 PRUint32 mStringLength;
94 } str;
95 struct {
96 PRUnichar* mWStringValue;
97 PRUint32 mWStringLength;
98 } wstr;
99 } u;
100 PRUint16 mType;
101};
102
103/**
104 * nsVariant implements the generic variant support. The xpcom module registers
105 * a factory (see NS_VARIANT_CONTRACTID in nsIVariant.idl) that will create
106 * these objects. They are created 'empty' and 'writable'.
107 *
108 * nsIVariant users won't usually need to see this class.
109 *
110 * This class also has static helper methods that nsIVariant *implementors* can
111 * use to help them do all the 'standard' nsIVariant data conversions.
112 */
113
114class NS_COM nsVariant : public nsIWritableVariant
115{
116public:
117 NS_DECL_ISUPPORTS
118 NS_DECL_NSIVARIANT
119 NS_DECL_NSIWRITABLEVARIANT
120
121 nsVariant();
122
123 static nsresult Initialize(nsDiscriminatedUnion* data);
124 static nsresult Cleanup(nsDiscriminatedUnion* data);
125
126 static nsresult ConvertToInt8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
127 static nsresult ConvertToInt16(const nsDiscriminatedUnion& data, PRInt16 *_retval);
128 static nsresult ConvertToInt32(const nsDiscriminatedUnion& data, PRInt32 *_retval);
129 static nsresult ConvertToInt64(const nsDiscriminatedUnion& data, PRInt64 *_retval);
130 static nsresult ConvertToUint8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
131 static nsresult ConvertToUint16(const nsDiscriminatedUnion& data, PRUint16 *_retval);
132 static nsresult ConvertToUint32(const nsDiscriminatedUnion& data, PRUint32 *_retval);
133 static nsresult ConvertToUint64(const nsDiscriminatedUnion& data, PRUint64 *_retval);
134 static nsresult ConvertToFloat(const nsDiscriminatedUnion& data, float *_retval);
135 static nsresult ConvertToDouble(const nsDiscriminatedUnion& data, double *_retval);
136 static nsresult ConvertToBool(const nsDiscriminatedUnion& data, PRBool *_retval);
137 static nsresult ConvertToChar(const nsDiscriminatedUnion& data, char *_retval);
138 static nsresult ConvertToWChar(const nsDiscriminatedUnion& data, PRUnichar *_retval);
139 static nsresult ConvertToID(const nsDiscriminatedUnion& data, nsID * _retval);
140 static nsresult ConvertToAString(const nsDiscriminatedUnion& data, nsAString & _retval);
141 static nsresult ConvertToAUTF8String(const nsDiscriminatedUnion& data, nsAUTF8String & _retval);
142 static nsresult ConvertToACString(const nsDiscriminatedUnion& data, nsACString & _retval);
143 static nsresult ConvertToString(const nsDiscriminatedUnion& data, char **_retval);
144 static nsresult ConvertToWString(const nsDiscriminatedUnion& data, PRUnichar **_retval);
145 static nsresult ConvertToISupports(const nsDiscriminatedUnion& data, nsISupports **_retval);
146 static nsresult ConvertToInterface(const nsDiscriminatedUnion& data, nsIID * *iid, void * *iface);
147 static nsresult ConvertToArray(const nsDiscriminatedUnion& data, PRUint16 *type, nsIID* iid, PRUint32 *count, void * *ptr);
148 static nsresult ConvertToStringWithSize(const nsDiscriminatedUnion& data, PRUint32 *size, char **str);
149 static nsresult ConvertToWStringWithSize(const nsDiscriminatedUnion& data, PRUint32 *size, PRUnichar **str);
150
151 static nsresult SetFromVariant(nsDiscriminatedUnion* data, nsIVariant* aValue);
152
153 static nsresult SetFromInt8(nsDiscriminatedUnion* data, PRUint8 aValue);
154 static nsresult SetFromInt16(nsDiscriminatedUnion* data, PRInt16 aValue);
155 static nsresult SetFromInt32(nsDiscriminatedUnion* data, PRInt32 aValue);
156 static nsresult SetFromInt64(nsDiscriminatedUnion* data, PRInt64 aValue);
157 static nsresult SetFromUint8(nsDiscriminatedUnion* data, PRUint8 aValue);
158 static nsresult SetFromUint16(nsDiscriminatedUnion* data, PRUint16 aValue);
159 static nsresult SetFromUint32(nsDiscriminatedUnion* data, PRUint32 aValue);
160 static nsresult SetFromUint64(nsDiscriminatedUnion* data, PRUint64 aValue);
161 static nsresult SetFromFloat(nsDiscriminatedUnion* data, float aValue);
162 static nsresult SetFromDouble(nsDiscriminatedUnion* data, double aValue);
163 static nsresult SetFromBool(nsDiscriminatedUnion* data, PRBool aValue);
164 static nsresult SetFromChar(nsDiscriminatedUnion* data, char aValue);
165 static nsresult SetFromWChar(nsDiscriminatedUnion* data, PRUnichar aValue);
166 static nsresult SetFromID(nsDiscriminatedUnion* data, const nsID & aValue);
167 static nsresult SetFromAString(nsDiscriminatedUnion* data, const nsAString & aValue);
168 static nsresult SetFromAUTF8String(nsDiscriminatedUnion* data, const nsAUTF8String & aValue);
169 static nsresult SetFromACString(nsDiscriminatedUnion* data, const nsACString & aValue);
170 static nsresult SetFromString(nsDiscriminatedUnion* data, const char *aValue);
171 static nsresult SetFromWString(nsDiscriminatedUnion* data, const PRUnichar *aValue);
172 static nsresult SetFromISupports(nsDiscriminatedUnion* data, nsISupports *aValue);
173 static nsresult SetFromInterface(nsDiscriminatedUnion* data, const nsIID& iid, nsISupports *aValue);
174 static nsresult SetFromArray(nsDiscriminatedUnion* data, PRUint16 type, const nsIID* iid, PRUint32 count, void * aValue);
175 static nsresult SetFromStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const char *aValue);
176 static nsresult SetFromWStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const PRUnichar *aValue);
177
178 static nsresult SetToVoid(nsDiscriminatedUnion* data);
179 static nsresult SetToEmpty(nsDiscriminatedUnion* data);
180 static nsresult SetToEmptyArray(nsDiscriminatedUnion* data);
181
182private:
183 ~nsVariant();
184
185protected:
186 nsDiscriminatedUnion mData;
187 PRBool mWritable;
188};
189
190/**
191 * Users of nsIVariant should be using the contractID and not this CID.
192 * - see NS_VARIANT_CONTRACTID in nsIVariant.idl.
193 */
194
195#define NS_VARIANT_CID \
196{ /* 0D6EA1D0-879C-11d5-90EF-0010A4E73D9A */ \
197 0xd6ea1d0, \
198 0x879c, \
199 0x11d5, \
200 {0x90, 0xef, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a}}
201
202#define NS_VARIANT_CLASSNAME "Variant"
203
Note: See TracBrowser for help on using the repository browser.

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