49 #include <nsStringGlue.h>
74 NS_ENSURE_ARG_POINTER(aVariant);
75 NS_ENSURE_ARG_POINTER(aInt);
76 nsresult rv = aVariant->GetAsInt64(aInt);
77 NS_ENSURE_SUCCESS(rv, rv);
85 NS_ENSURE_ARG_POINTER(aVariant);
86 NS_ENSURE_ARG_POINTER(aInt);
87 nsresult rv = aVariant->GetAsUint64(aInt);
88 NS_ENSURE_SUCCESS(rv, rv);
108 NS_ENSURE_ARG_POINTER(aVariant);
109 NS_ENSURE_ARG_POINTER(aInt);
116 rv = aVariant->GetDataType(&dataType);
117 NS_ENSURE_SUCCESS(rv, rv);
119 case nsIDataType::VTYPE_DOMSTRING :
120 case nsIDataType::VTYPE_CHAR_STR :
121 case nsIDataType::VTYPE_WCHAR_STR :
122 case nsIDataType::VTYPE_UTF8STRING :
123 case nsIDataType::VTYPE_CSTRING :
124 case nsIDataType::VTYPE_ASTRING :
125 case nsIDataType::VTYPE_STRING_SIZE_IS :
126 case nsIDataType::VTYPE_WSTRING_SIZE_IS :
129 nsCAutoString variantString;
130 rv = aVariant->GetAsACString(variantString);
131 NS_ENSURE_SUCCESS(rv, rv);
133 std::istringstream iss(s);
134 iss >> std::setbase(0) >> *aInt;
140 NS_ENSURE_SUCCESS(rv, rv);
161 nsIVariant* aVariant2,
165 NS_ENSURE_ARG_POINTER(aEqual);
171 if (!aVariant1 || !aVariant2) {
172 *aEqual = (!aVariant1 && !aVariant2);
179 rv = aVariant1->GetDataType(&dataType1);
180 NS_ENSURE_SUCCESS(rv, rv);
181 rv = aVariant2->GetDataType(&dataType2);
182 NS_ENSURE_SUCCESS(rv, rv);
186 case nsIDataType::VTYPE_INT8 :
187 case nsIDataType::VTYPE_INT16 :
188 case nsIDataType::VTYPE_INT32 :
189 case nsIDataType::VTYPE_INT64 :
190 case nsIDataType::VTYPE_UINT8 :
191 case nsIDataType::VTYPE_UINT16 :
192 case nsIDataType::VTYPE_UINT32 :
196 rv = aVariant1->GetAsInt64(&value1);
197 NS_ENSURE_SUCCESS(rv, rv);
199 NS_ENSURE_SUCCESS(rv, rv);
200 *aEqual = (value1 == value2);
204 case nsIDataType::VTYPE_UINT64 :
208 rv = aVariant1->GetAsUint64(&value1);
209 NS_ENSURE_SUCCESS(rv, rv);
211 NS_ENSURE_SUCCESS(rv, rv);
212 *aEqual = (value1 == value2);
216 case nsIDataType::VTYPE_FLOAT :
217 case nsIDataType::VTYPE_DOUBLE :
221 rv = aVariant1->GetAsDouble(&value1);
222 NS_ENSURE_SUCCESS(rv, rv);
223 rv = aVariant2->GetAsDouble(&value2);
224 NS_ENSURE_SUCCESS(rv, rv);
225 *aEqual = (value1 == value2);
229 case nsIDataType::VTYPE_BOOL :
233 rv = aVariant1->GetAsBool(&value1);
234 NS_ENSURE_SUCCESS(rv, rv);
235 rv = aVariant2->GetAsBool(&value2);
236 NS_ENSURE_SUCCESS(rv, rv);
237 *aEqual = (value1 == value2);
241 case nsIDataType::VTYPE_CHAR :
245 rv = aVariant1->GetAsChar(&value1);
246 NS_ENSURE_SUCCESS(rv, rv);
247 rv = aVariant2->GetAsChar(&value2);
248 NS_ENSURE_SUCCESS(rv, rv);
249 *aEqual = (value1 == value2);
253 case nsIDataType::VTYPE_WCHAR :
257 rv = aVariant1->GetAsWChar(&value1);
258 NS_ENSURE_SUCCESS(rv, rv);
259 rv = aVariant2->GetAsWChar(&value2);
260 NS_ENSURE_SUCCESS(rv, rv);
261 *aEqual = (value1 == value2);
265 case nsIDataType::VTYPE_VOID :
266 case nsIDataType::VTYPE_EMPTY :
268 *aEqual = (dataType1 == dataType2);
272 case nsIDataType::VTYPE_ID :
276 rv = aVariant1->GetAsID(&value1);
277 NS_ENSURE_SUCCESS(rv, rv);
278 rv = aVariant2->GetAsID(&value2);
279 NS_ENSURE_SUCCESS(rv, rv);
280 *aEqual = value1.Equals(value2);
284 case nsIDataType::VTYPE_DOMSTRING :
285 case nsIDataType::VTYPE_CHAR_STR :
286 case nsIDataType::VTYPE_WCHAR_STR :
287 case nsIDataType::VTYPE_UTF8STRING :
288 case nsIDataType::VTYPE_CSTRING :
289 case nsIDataType::VTYPE_ASTRING :
290 case nsIDataType::VTYPE_STRING_SIZE_IS :
291 case nsIDataType::VTYPE_WSTRING_SIZE_IS :
295 rv = aVariant1->GetAsAString(value1);
296 NS_ENSURE_SUCCESS(rv, rv);
297 rv = aVariant2->GetAsAString(value2);
298 NS_ENSURE_SUCCESS(rv, rv);
299 *aEqual = value1.Equals(value2);
303 case nsIDataType::VTYPE_INTERFACE :
304 case nsIDataType::VTYPE_INTERFACE_IS :
306 nsCOMPtr<nsISupports> value1;
307 nsCOMPtr<nsISupports> value2;
308 rv = aVariant1->GetAsISupports(getter_AddRefs(value1));
309 NS_ENSURE_SUCCESS(rv, rv);
310 rv = aVariant2->GetAsISupports(getter_AddRefs(value2));
311 NS_ENSURE_SUCCESS(rv, rv);
312 *aEqual = (value1 == value2);
316 case nsIDataType::VTYPE_ARRAY :
317 case nsIDataType::VTYPE_EMPTY_ARRAY :
319 return NS_ERROR_NOT_IMPLEMENTED;
nsresult sbVariantsEqual(nsIVariant *aVariant1, nsIVariant *aVariant2, PRBool *aEqual)
Songbird Variant Utility Definitions.
static nsresult sbVariantToInt(nsIVariant *aVariant, T *aInt)
static nsresult sbNonStringVariantToInt(nsIVariant *aVariant, PRInt64 *aInt)