Back to index

lightning-sunbird  0.9+nobinonly
nsVariant.h
Go to the documentation of this file.
00001 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   John Bandhauer <jband@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 /* The long avoided variant support for xpcom. */
00041 
00042 #include "nsIVariant.h"
00043 #include "nsStringFwd.h"
00044 #include "xpt_struct.h"
00045 
00051 #define nsAUTF8String nsACString
00052 #define nsUTF8String nsCString
00053 #define PromiseFlatUTF8String PromiseFlatCString
00054 
00061 struct nsDiscriminatedUnion
00062 {
00063     union {
00064         PRInt8         mInt8Value;
00065         PRInt16        mInt16Value;
00066         PRInt32        mInt32Value;
00067         PRInt64        mInt64Value;
00068         PRUint8        mUint8Value;
00069         PRUint16       mUint16Value;
00070         PRUint32       mUint32Value;
00071         PRUint64       mUint64Value;
00072         float          mFloatValue;
00073         double         mDoubleValue;
00074         PRBool         mBoolValue;
00075         char           mCharValue;
00076         PRUnichar      mWCharValue;
00077         nsIID          mIDValue;
00078         nsAString*     mAStringValue;
00079         nsAUTF8String* mUTF8StringValue;
00080         nsACString*    mCStringValue;
00081         struct {
00082             nsISupports* mInterfaceValue;
00083             nsIID        mInterfaceID;
00084         } iface;
00085         struct {
00086             nsIID        mArrayInterfaceID;
00087             void*        mArrayValue;
00088             PRUint32     mArrayCount;
00089             PRUint16     mArrayType;
00090         } array;
00091         struct {
00092             char*        mStringValue;
00093             PRUint32     mStringLength;
00094         } str;
00095         struct {
00096             PRUnichar*   mWStringValue;
00097             PRUint32     mWStringLength;
00098         } wstr;
00099     } u;
00100     PRUint16       mType;
00101 };
00102 
00114 class NS_COM nsVariant : public nsIWritableVariant
00115 {
00116 public:
00117     NS_DECL_ISUPPORTS
00118     NS_DECL_NSIVARIANT
00119     NS_DECL_NSIWRITABLEVARIANT
00120 
00121     nsVariant();
00122 
00123     static nsresult Initialize(nsDiscriminatedUnion* data);
00124     static nsresult Cleanup(nsDiscriminatedUnion* data);
00125 
00126     static nsresult ConvertToInt8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
00127     static nsresult ConvertToInt16(const nsDiscriminatedUnion& data, PRInt16 *_retval);
00128     static nsresult ConvertToInt32(const nsDiscriminatedUnion& data, PRInt32 *_retval);
00129     static nsresult ConvertToInt64(const nsDiscriminatedUnion& data, PRInt64 *_retval);
00130     static nsresult ConvertToUint8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
00131     static nsresult ConvertToUint16(const nsDiscriminatedUnion& data, PRUint16 *_retval);
00132     static nsresult ConvertToUint32(const nsDiscriminatedUnion& data, PRUint32 *_retval);
00133     static nsresult ConvertToUint64(const nsDiscriminatedUnion& data, PRUint64 *_retval);
00134     static nsresult ConvertToFloat(const nsDiscriminatedUnion& data, float *_retval);
00135     static nsresult ConvertToDouble(const nsDiscriminatedUnion& data, double *_retval);
00136     static nsresult ConvertToBool(const nsDiscriminatedUnion& data, PRBool *_retval);
00137     static nsresult ConvertToChar(const nsDiscriminatedUnion& data, char *_retval);
00138     static nsresult ConvertToWChar(const nsDiscriminatedUnion& data, PRUnichar *_retval);
00139     static nsresult ConvertToID(const nsDiscriminatedUnion& data, nsID * _retval);
00140     static nsresult ConvertToAString(const nsDiscriminatedUnion& data, nsAString & _retval);
00141     static nsresult ConvertToAUTF8String(const nsDiscriminatedUnion& data, nsAUTF8String & _retval);
00142     static nsresult ConvertToACString(const nsDiscriminatedUnion& data, nsACString & _retval);
00143     static nsresult ConvertToString(const nsDiscriminatedUnion& data, char **_retval);
00144     static nsresult ConvertToWString(const nsDiscriminatedUnion& data, PRUnichar **_retval);
00145     static nsresult ConvertToISupports(const nsDiscriminatedUnion& data, nsISupports **_retval);
00146     static nsresult ConvertToInterface(const nsDiscriminatedUnion& data, nsIID * *iid, void * *iface);
00147     static nsresult ConvertToArray(const nsDiscriminatedUnion& data, PRUint16 *type, nsIID* iid, PRUint32 *count, void * *ptr);
00148     static nsresult ConvertToStringWithSize(const nsDiscriminatedUnion& data, PRUint32 *size, char **str);
00149     static nsresult ConvertToWStringWithSize(const nsDiscriminatedUnion& data, PRUint32 *size, PRUnichar **str);
00150 
00151     static nsresult SetFromVariant(nsDiscriminatedUnion* data, nsIVariant* aValue);
00152 
00153     static nsresult SetFromInt8(nsDiscriminatedUnion* data, PRUint8 aValue);
00154     static nsresult SetFromInt16(nsDiscriminatedUnion* data, PRInt16 aValue);
00155     static nsresult SetFromInt32(nsDiscriminatedUnion* data, PRInt32 aValue);
00156     static nsresult SetFromInt64(nsDiscriminatedUnion* data, PRInt64 aValue);
00157     static nsresult SetFromUint8(nsDiscriminatedUnion* data, PRUint8 aValue);
00158     static nsresult SetFromUint16(nsDiscriminatedUnion* data, PRUint16 aValue);
00159     static nsresult SetFromUint32(nsDiscriminatedUnion* data, PRUint32 aValue);
00160     static nsresult SetFromUint64(nsDiscriminatedUnion* data, PRUint64 aValue);
00161     static nsresult SetFromFloat(nsDiscriminatedUnion* data, float aValue);
00162     static nsresult SetFromDouble(nsDiscriminatedUnion* data, double aValue);
00163     static nsresult SetFromBool(nsDiscriminatedUnion* data, PRBool aValue);
00164     static nsresult SetFromChar(nsDiscriminatedUnion* data, char aValue);
00165     static nsresult SetFromWChar(nsDiscriminatedUnion* data, PRUnichar aValue);
00166     static nsresult SetFromID(nsDiscriminatedUnion* data, const nsID & aValue);
00167     static nsresult SetFromAString(nsDiscriminatedUnion* data, const nsAString & aValue);
00168     static nsresult SetFromAUTF8String(nsDiscriminatedUnion* data, const nsAUTF8String & aValue);
00169     static nsresult SetFromACString(nsDiscriminatedUnion* data, const nsACString & aValue);
00170     static nsresult SetFromString(nsDiscriminatedUnion* data, const char *aValue);
00171     static nsresult SetFromWString(nsDiscriminatedUnion* data, const PRUnichar *aValue);
00172     static nsresult SetFromISupports(nsDiscriminatedUnion* data, nsISupports *aValue);
00173     static nsresult SetFromInterface(nsDiscriminatedUnion* data, const nsIID& iid, nsISupports *aValue);
00174     static nsresult SetFromArray(nsDiscriminatedUnion* data, PRUint16 type, const nsIID* iid, PRUint32 count, void * aValue);
00175     static nsresult SetFromStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const char *aValue);
00176     static nsresult SetFromWStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const PRUnichar *aValue);
00177 
00178     static nsresult SetToVoid(nsDiscriminatedUnion* data);
00179     static nsresult SetToEmpty(nsDiscriminatedUnion* data);
00180     static nsresult SetToEmptyArray(nsDiscriminatedUnion* data);
00181 
00182 private:
00183     ~nsVariant();
00184 
00185 protected:
00186     nsDiscriminatedUnion mData;
00187     PRBool               mWritable;
00188 };
00189 
00195 #define NS_VARIANT_CID \
00196 { /* 0D6EA1D0-879C-11d5-90EF-0010A4E73D9A */ \
00197     0xd6ea1d0,                               \
00198     0x879c,                                  \
00199     0x11d5,                                  \
00200     {0x90, 0xef, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a}}
00201 
00202 #define NS_VARIANT_CLASSNAME "Variant"
00203