sbVariant.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 /*
28 // Original code is nsVariant.h from the Mozilla Foundation.
29 */
30 
31 /* The long avoided variant support for xpcom. */
32 
33 #include <nsIVariant.h>
34 #include <nsStringGlue.h>
35 #include <xpt_struct.h>
36 
42 #define nsAUTF8String nsACString
43 #define nsUTF8String nsCString
44 #define PromiseFlatUTF8String PromiseFlatCString
45 
53 {
54  union {
55  PRInt8 mInt8Value;
56  PRInt16 mInt16Value;
57  PRInt32 mInt32Value;
58  PRInt64 mInt64Value;
59  PRUint8 mUint8Value;
60  PRUint16 mUint16Value;
61  PRUint32 mUint32Value;
62  PRUint64 mUint64Value;
63  float mFloatValue;
64  double mDoubleValue;
65  PRBool mBoolValue;
66  char mCharValue;
67  PRUnichar mWCharValue;
68  nsIID mIDValue;
69  nsAString* mAStringValue;
71  nsACString* mCStringValue;
72  struct {
74  nsIID mInterfaceID;
75  } iface;
76  struct {
78  void* mArrayValue;
79  PRUint32 mArrayCount;
80  PRUint16 mArrayType;
81  } array;
82  struct {
83  char* mStringValue;
84  PRUint32 mStringLength;
85  } str;
86  struct {
87  PRUnichar* mWStringValue;
88  PRUint32 mWStringLength;
89  } wstr;
90  } u;
91  PRUint16 mType;
92 };
93 
103 class sbVariant : public nsIWritableVariant
104 {
105 public:
107  NS_DECL_NSIVARIANT
108  NS_DECL_NSIWRITABLEVARIANT
109 
110  sbVariant();
111 
112  static nsresult Initialize(nsDiscriminatedUnion* data);
113  static nsresult Cleanup(nsDiscriminatedUnion* data);
114 
115  static nsresult ConvertToInt8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
116  static nsresult ConvertToInt16(const nsDiscriminatedUnion& data, PRInt16 *_retval);
117  static nsresult ConvertToInt32(const nsDiscriminatedUnion& data, PRInt32 *_retval);
118  static nsresult ConvertToInt64(const nsDiscriminatedUnion& data, PRInt64 *_retval);
119  static nsresult ConvertToUint8(const nsDiscriminatedUnion& data, PRUint8 *_retval);
120  static nsresult ConvertToUint16(const nsDiscriminatedUnion& data, PRUint16 *_retval);
121  static nsresult ConvertToUint32(const nsDiscriminatedUnion& data, PRUint32 *_retval);
122  static nsresult ConvertToUint64(const nsDiscriminatedUnion& data, PRUint64 *_retval);
123  static nsresult ConvertToFloat(const nsDiscriminatedUnion& data, float *_retval);
124  static nsresult ConvertToDouble(const nsDiscriminatedUnion& data, double *_retval);
125  static nsresult ConvertToBool(const nsDiscriminatedUnion& data, PRBool *_retval);
126  static nsresult ConvertToChar(const nsDiscriminatedUnion& data, char *_retval);
127  static nsresult ConvertToWChar(const nsDiscriminatedUnion& data, PRUnichar *_retval);
128  static nsresult ConvertToID(const nsDiscriminatedUnion& data, nsID * _retval);
129  static nsresult ConvertToAString(const nsDiscriminatedUnion& data, nsAString & _retval);
130  static nsresult ConvertToAUTF8String(const nsDiscriminatedUnion& data, nsAUTF8String & _retval);
131  static nsresult ConvertToACString(const nsDiscriminatedUnion& data, nsACString & _retval);
132 
133  //Cannot accept a const nsDiscriminationUnion struct for this method because of the kinds of
134  //conversion that need to occur internally. The data itself will _not_ be modified.
135  static nsresult ConvertToString(nsDiscriminatedUnion& data, char **_retval);
136 
137  static nsresult ConvertToWString(const nsDiscriminatedUnion& data, PRUnichar **_retval);
138  static nsresult ConvertToISupports(const nsDiscriminatedUnion& data, nsISupports **_retval);
139  static nsresult ConvertToInterface(const nsDiscriminatedUnion& data, nsIID * *iid, void * *iface);
140  static nsresult ConvertToArray(const nsDiscriminatedUnion& data, PRUint16 *type, nsIID* iid, PRUint32 *count, void * *ptr);
141 
142  //Cannot accept a const nsDiscriminationUnion struct for this method because of the kinds of
143  //conversion that need to occur internally. The data itself will _not_ be modified.
144  static nsresult ConvertToStringWithSize(nsDiscriminatedUnion& data, PRUint32 *size, char **str);
145 
146  static nsresult ConvertToWStringWithSize(const nsDiscriminatedUnion& data, PRUint32 *size, PRUnichar **str);
147 
148  static nsresult SetFromVariant(nsDiscriminatedUnion* data, nsIVariant* aValue);
149 
150  static nsresult SetFromInt8(nsDiscriminatedUnion* data, PRUint8 aValue);
151  static nsresult SetFromInt16(nsDiscriminatedUnion* data, PRInt16 aValue);
152  static nsresult SetFromInt32(nsDiscriminatedUnion* data, PRInt32 aValue);
153  static nsresult SetFromInt64(nsDiscriminatedUnion* data, PRInt64 aValue);
154  static nsresult SetFromUint8(nsDiscriminatedUnion* data, PRUint8 aValue);
155  static nsresult SetFromUint16(nsDiscriminatedUnion* data, PRUint16 aValue);
156  static nsresult SetFromUint32(nsDiscriminatedUnion* data, PRUint32 aValue);
157  static nsresult SetFromUint64(nsDiscriminatedUnion* data, PRUint64 aValue);
158  static nsresult SetFromFloat(nsDiscriminatedUnion* data, float aValue);
159  static nsresult SetFromDouble(nsDiscriminatedUnion* data, double aValue);
160  static nsresult SetFromBool(nsDiscriminatedUnion* data, PRBool aValue);
161  static nsresult SetFromChar(nsDiscriminatedUnion* data, char aValue);
162  static nsresult SetFromWChar(nsDiscriminatedUnion* data, PRUnichar aValue);
163  static nsresult SetFromID(nsDiscriminatedUnion* data, const nsID & aValue);
164  static nsresult SetFromAString(nsDiscriminatedUnion* data, const nsAString & aValue);
165  static nsresult SetFromAUTF8String(nsDiscriminatedUnion* data, const nsAUTF8String & aValue);
166  static nsresult SetFromACString(nsDiscriminatedUnion* data, const nsACString & aValue);
167  static nsresult SetFromString(nsDiscriminatedUnion* data, const char *aValue);
168  static nsresult SetFromWString(nsDiscriminatedUnion* data, const PRUnichar *aValue);
169  static nsresult SetFromISupports(nsDiscriminatedUnion* data, nsISupports *aValue);
170  static nsresult SetFromInterface(nsDiscriminatedUnion* data, const nsIID& iid, nsISupports *aValue);
171  static nsresult SetFromArray(nsDiscriminatedUnion* data, PRUint16 type, const nsIID* iid, PRUint32 count, void * aValue);
172  static nsresult SetFromStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const char *aValue);
173  static nsresult SetFromWStringWithSize(nsDiscriminatedUnion* data, PRUint32 size, const PRUnichar *aValue);
174 
175  static nsresult SetToVoid(nsDiscriminatedUnion* data);
176  static nsresult SetToEmpty(nsDiscriminatedUnion* data);
177  static nsresult SetToEmptyArray(nsDiscriminatedUnion* data);
178 
179 private:
180  ~sbVariant();
181 
182 protected:
184  PRLock* mDataLock;
185 
186  PRBool mWritable;
187 };
188 
189 #define SONGBIRD_VARIANT_CID \
190 { /*{B522C2E8-826F-477f-86B7-4A143CD1A188}*/ \
191  0xb522c2e8, \
192  0x826f, \
193  0x477f, \
194 { 0x86, 0xb7, 0x4a, 0x14, 0x3c, 0xd1, 0xa1, 0x88 }}
195 
196 #define SONGBIRD_VARIANT_CLASSNAME "sbVariant"
197 
198 #define SONGBIRD_VARIANT_CONTRACTID "@songbirdnest.com/Songbird/Variant;1"
static nsresult ConvertToInt64(const nsDiscriminatedUnion &data, PRInt64 *_retval)
Definition: sbVariant.cpp:754
static nsresult SetFromInterface(nsDiscriminatedUnion *data, const nsIID &iid, nsISupports *aValue)
Definition: sbVariant.cpp:1634
static nsresult ConvertToString(nsDiscriminatedUnion &data, char **_retval)
Definition: sbVariant.cpp:1114
static nsresult ConvertToFloat(const nsDiscriminatedUnion &data, float *_retval)
Definition: sbVariant.cpp:695
static nsresult SetFromWStringWithSize(nsDiscriminatedUnion *data, PRUint32 size, const PRUnichar *aValue)
Definition: sbVariant.cpp:1673
static nsresult SetFromUint32(nsDiscriminatedUnion *data, PRUint32 aValue)
Definition: sbVariant.cpp:1544
PRUint16 mUint16Value
Definition: sbVariant.h:60
struct nsDiscriminatedUnion::@10::@11 iface
PRUint32 mUint32Value
Definition: sbVariant.h:61
nsDiscriminatedUnion mData
Definition: sbVariant.h:183
onPageChanged aValue
Definition: FeedWriter.js:1395
static nsresult ConvertToStringWithSize(nsDiscriminatedUnion &data, PRUint32 *size, char **str)
Definition: sbVariant.cpp:1128
static nsresult SetFromStringWithSize(nsDiscriminatedUnion *data, PRUint32 size, const char *aValue)
Definition: sbVariant.cpp:1661
static nsresult SetToVoid(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:1685
struct nsDiscriminatedUnion::@10::@12 array
static nsresult SetFromAUTF8String(nsDiscriminatedUnion *data, const nsACString &aValue)
Definition: sbVariant.cpp:1603
static nsresult SetFromISupports(nsDiscriminatedUnion *data, nsISupports *aValue)
Definition: sbVariant.cpp:1629
static nsresult ConvertToWString(const nsDiscriminatedUnion &data, PRUnichar **_retval)
Definition: sbVariant.cpp:1121
static nsresult SetFromChar(nsDiscriminatedUnion *data, char aValue)
Definition: sbVariant.cpp:1569
static nsresult SetFromInt32(nsDiscriminatedUnion *data, PRInt32 aValue)
Definition: sbVariant.cpp:1524
static nsresult SetToEmpty(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:1691
static nsresult ConvertToID(const nsDiscriminatedUnion &data, nsID *_retval)
Definition: sbVariant.cpp:827
#define nsAUTF8String
Definition: sbVariant.h:42
static nsresult SetFromFloat(nsDiscriminatedUnion *data, float aValue)
Definition: sbVariant.cpp:1554
static nsresult ConvertToInterface(const nsDiscriminatedUnion &data, nsIID **iid, void **iface)
Definition: sbVariant.cpp:1301
static nsresult ConvertToChar(const nsDiscriminatedUnion &data, char *_retval)
Definition: sbVariant.cpp:708
PRUnichar * mWStringValue
Definition: sbVariant.h:87
static nsresult SetFromUint16(nsDiscriminatedUnion *data, PRUint16 aValue)
Definition: sbVariant.cpp:1539
PRBool mWritable
Definition: sbVariant.h:186
static nsresult SetFromID(nsDiscriminatedUnion *data, const nsID &aValue)
Definition: sbVariant.cpp:1579
static nsresult ConvertToArray(const nsDiscriminatedUnion &data, PRUint16 *type, nsIID *iid, PRUint32 *count, void **ptr)
Definition: sbVariant.cpp:1331
nsACString * mUTF8StringValue
Definition: sbVariant.h:70
static nsresult SetFromBool(nsDiscriminatedUnion *data, PRBool aValue)
Definition: sbVariant.cpp:1564
var count
Definition: test_bug7406.js:32
static nsresult SetFromInt16(nsDiscriminatedUnion *data, PRInt16 aValue)
Definition: sbVariant.cpp:1519
static nsresult ConvertToUint32(const nsDiscriminatedUnion &data, PRUint32 *_retval)
Definition: sbVariant.cpp:688
PRLock * mDataLock
Definition: sbVariant.h:184
static nsresult SetFromWChar(nsDiscriminatedUnion *data, PRUnichar aValue)
Definition: sbVariant.cpp:1574
static nsresult SetFromAString(nsDiscriminatedUnion *data, const nsAString &aValue)
Definition: sbVariant.cpp:1584
static nsresult ConvertToISupports(const nsDiscriminatedUnion &data, nsISupports **_retval)
Definition: sbVariant.cpp:1281
static nsresult ConvertToACString(const nsDiscriminatedUnion &data, nsACString &_retval)
Definition: sbVariant.cpp:1009
nsAString * mAStringValue
Definition: sbVariant.h:69
static nsresult ConvertToInt16(const nsDiscriminatedUnion &data, PRInt16 *_retval)
Definition: sbVariant.cpp:677
static nsresult SetFromUint8(nsDiscriminatedUnion *data, PRUint8 aValue)
Definition: sbVariant.cpp:1534
nsACString * mCStringValue
Definition: sbVariant.h:71
union nsDiscriminatedUnion::@10 u
struct nsDiscriminatedUnion::@10::@14 wstr
PRUint64 mUint64Value
Definition: sbVariant.h:62
static nsresult Initialize(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:1706
static nsresult SetFromArray(nsDiscriminatedUnion *data, PRUint16 type, const nsIID *iid, PRUint32 count, void *aValue)
Definition: sbVariant.cpp:1644
static nsresult SetFromString(nsDiscriminatedUnion *data, const char *aValue)
Definition: sbVariant.cpp:1613
static nsresult ConvertToUint16(const nsDiscriminatedUnion &data, PRUint16 *_retval)
Definition: sbVariant.cpp:686
PRUint16 mArrayType
Definition: sbVariant.h:80
static nsresult Cleanup(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:1713
static nsresult ConvertToInt32(const nsDiscriminatedUnion &data, PRInt32 *_retval)
Definition: sbVariant.cpp:679
static nsresult SetFromACString(nsDiscriminatedUnion *data, const nsACString &aValue)
Definition: sbVariant.cpp:1593
static nsresult SetFromInt8(nsDiscriminatedUnion *data, PRUint8 aValue)
Definition: sbVariant.cpp:1514
static nsresult ConvertToWStringWithSize(const nsDiscriminatedUnion &data, PRUint32 *size, PRUnichar **str)
Definition: sbVariant.cpp:1210
PRUint32 mStringLength
Definition: sbVariant.h:84
static nsresult ConvertToBool(const nsDiscriminatedUnion &data, PRBool *_retval)
Definition: sbVariant.cpp:739
static nsresult ConvertToUint64(const nsDiscriminatedUnion &data, PRUint64 *_retval)
Definition: sbVariant.cpp:783
NS_DECL_ISUPPORTS NS_DECL_NSIVARIANT NS_DECL_NSIWRITABLEVARIANT sbVariant()
static nsresult SetFromUint64(nsDiscriminatedUnion *data, PRUint64 aValue)
Definition: sbVariant.cpp:1549
static nsresult SetFromDouble(nsDiscriminatedUnion *data, double aValue)
Definition: sbVariant.cpp:1559
static nsresult ConvertToUint8(const nsDiscriminatedUnion &data, PRUint8 *_retval)
Definition: sbVariant.cpp:685
static nsresult SetToEmptyArray(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:1697
static nsresult ConvertToInt8(const nsDiscriminatedUnion &data, PRUint8 *_retval)
Definition: sbVariant.cpp:676
PRUint32 mArrayCount
Definition: sbVariant.h:79
static nsresult ConvertToAUTF8String(const nsDiscriminatedUnion &data, nsACString &_retval)
Definition: sbVariant.cpp:1054
PRUint32 mWStringLength
Definition: sbVariant.h:88
observe data
Definition: FeedWriter.js:1329
nsISupports * mInterfaceValue
Definition: sbVariant.h:73
static nsresult ConvertToDouble(const nsDiscriminatedUnion &data, double *_retval)
Definition: sbVariant.cpp:701
static nsresult SetFromVariant(nsDiscriminatedUnion *data, nsIVariant *aValue)
Definition: sbVariant.cpp:1399
static nsresult ConvertToWChar(const nsDiscriminatedUnion &data, PRUnichar *_retval)
Definition: sbVariant.cpp:715
static nsresult ConvertToAString(const nsDiscriminatedUnion &data, nsAString &_retval)
Definition: sbVariant.cpp:964
struct nsDiscriminatedUnion::@10::@13 str
static nsresult SetFromWString(nsDiscriminatedUnion *data, const PRUnichar *aValue)
Definition: sbVariant.cpp:1621
static nsresult SetFromInt64(nsDiscriminatedUnion *data, PRInt64 aValue)
Definition: sbVariant.cpp:1529
PRUnichar mWCharValue
Definition: sbVariant.h:67