27 #ifndef __SB_VARIANT_UTILS_H__
28 #define __SB_VARIANT_UTILS_H__
50 #include <nsComponentManagerUtils.h>
51 #include <nsIVariant.h>
91 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
93 rv = mVariant->SetAsVoid();
95 NS_WARNING(
"Failed to create new variant.");
103 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
104 if (NS_SUCCEEDED(rv)) {
106 rv = mVariant->SetAsISupports(aValue);
108 rv = mVariant->SetAsEmpty();
111 NS_WARNING(
"Failed to create new variant.");
119 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
120 if (NS_SUCCEEDED(rv)) {
122 rv = mVariant->SetAsInterface(aIID, aValue);
124 rv = mVariant->SetAsEmpty();
127 NS_WARNING(
"Failed to create new variant.");
135 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
136 if (NS_SUCCEEDED(rv))
137 rv = mVariant->SetAsAString(aValue);
139 NS_WARNING(
"Failed to create new variant.");
145 PRUint16 aType = nsIDataType::VTYPE_CSTRING)
148 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
149 if (NS_SUCCEEDED(rv)) {
150 if (aType == nsIDataType::VTYPE_UTF8STRING)
151 rv = mVariant->SetAsAUTF8String(aValue);
153 rv = mVariant->SetAsACString(aValue);
156 NS_WARNING(
"Failed to create new variant.");
166 value.AssignLiteral(aValue);
167 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
168 if (NS_SUCCEEDED(rv)) {
170 rv = mVariant->SetAsAString(value);
172 rv = mVariant->SetAsEmpty();
175 NS_WARNING(
"Failed to create new variant.");
183 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
184 if (NS_SUCCEEDED(rv))
185 rv = mVariant->SetAsChar(aValue);
187 NS_WARNING(
"Failed to create new variant.");
195 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
196 if (NS_SUCCEEDED(rv))
197 rv = mVariant->SetAsInt16(aValue);
199 NS_WARNING(
"Failed to create new variant.");
207 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
208 if (NS_SUCCEEDED(rv))
209 rv = mVariant->SetAsInt32(aValue);
211 NS_WARNING(
"Failed to create new variant.");
217 PRUint16 aType = nsIDataType::VTYPE_UINT32)
220 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
221 if (NS_SUCCEEDED(rv)) {
222 if (aType == nsIDataType::VTYPE_BOOL)
223 rv = mVariant->SetAsBool(aValue);
225 rv = mVariant->SetAsUint32(aValue);
228 NS_WARNING(
"Failed to create new variant.");
236 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
237 if (NS_SUCCEEDED(rv))
238 rv = mVariant->SetAsInt64(aValue);
240 NS_WARNING(
"Failed to create new variant.");
248 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
249 if (NS_SUCCEEDED(rv))
250 rv = mVariant->SetAsUint64(aValue);
252 NS_WARNING(
"Failed to create new variant.");
260 mVariant = do_CreateInstance(
"@songbirdnest.com/Songbird/Variant;1", &rv);
261 if (NS_SUCCEEDED(rv))
262 rv = mVariant->SetAsDouble(aValue);
264 NS_WARNING(
"Failed to create new variant.");
274 nsIVariant*
get()
const {
return mVariant; }
276 operator nsIVariant*()
const {
return get(); }
280 nsCOMPtr<nsIWritableVariant> mVariant;
307 nsresult* aRV = nsnull) :
312 NS_ASSERTION(mVariant,
"Null variant");
322 operator PRUint8()
const
326 NS_WARNING(
"Null variant");
327 *mRV = NS_ERROR_NULL_POINTER;
333 *mRV = mVariant->GetAsUint8(&value);
334 NS_ENSURE_SUCCESS(*mRV, 0);
341 operator PRUint16()
const
345 NS_WARNING(
"Null variant");
346 *mRV = NS_ERROR_NULL_POINTER;
352 *mRV = mVariant->GetAsUint16(&value);
353 NS_ENSURE_SUCCESS(*mRV, 0);
358 operator PRInt16()
const
362 NS_WARNING(
"Null variant");
363 *mRV = NS_ERROR_NULL_POINTER;
369 *mRV = mVariant->GetAsInt16(&value);
370 NS_ENSURE_SUCCESS(*mRV, 0);
375 operator PRUint32()
const
379 NS_WARNING(
"Null variant");
380 *mRV = NS_ERROR_NULL_POINTER;
386 *mRV = mVariant->GetAsUint32(&value);
387 NS_ENSURE_SUCCESS(*mRV, 0);
392 operator PRInt32()
const
396 NS_WARNING(
"Null variant");
397 *mRV = NS_ERROR_NULL_POINTER;
403 *mRV = mVariant->GetAsInt32(&value);
404 NS_ENSURE_SUCCESS(*mRV, 0);
409 operator PRUint64()
const
413 NS_WARNING(
"Null variant");
414 *mRV = NS_ERROR_NULL_POINTER;
420 *mRV = mVariant->GetAsUint64(&value);
421 NS_ENSURE_SUCCESS(*mRV, 0);
426 operator PRInt64()
const
430 NS_WARNING(
"Null variant");
431 *mRV = NS_ERROR_NULL_POINTER;
437 *mRV = mVariant->GetAsInt64(&value);
438 NS_ENSURE_SUCCESS(*mRV, 0);
443 operator nsString()
const
447 NS_WARNING(
"Null variant");
448 *mRV = NS_ERROR_NULL_POINTER;
454 *mRV = mVariant->GetAsAString(value);
460 operator nsCString()
const
464 NS_WARNING(
"Null variant");
465 *mRV = NS_ERROR_NULL_POINTER;
471 *mRV = mVariant->GetAsACString(value);
503 nsCOMPtr<nsIVariant> mVariant;
505 nsresult mInternalRV;
sbNewVariant(PRInt16 aValue)
sbNewVariant(nsISupports *aValue)
sbNewVariant(char aValue)
sbNewVariant(double aValue)
sbNewVariant(REFNSIID aIID, nsISupports *aValue)
sbNewVariant(const char *aValue)
sbNewVariant(const nsACString &aValue, PRUint16 aType=nsIDataType::VTYPE_CSTRING)
sbNewVariant(PRUint32 aValue, PRUint16 aType=nsIDataType::VTYPE_UINT32)
sbNewVariant(PRUint64 aValue)
sbNewVariant(PRInt32 aValue)
sbVariantHelper(nsIVariant *aVariant, nsresult *aRV=nsnull)
sbNewVariant(const nsAString &aValue)
sbNewVariant(PRInt64 aValue)