sbVariant.cpp
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 "sbVariant.h"
34 #include <nsStringAPI.h>
35 #include <prprf.h>
36 #include <prdtoa.h>
37 #include <math.h>
38 #include <nsAutoLock.h>
39 #include <nsCRT.h>
40 
41 #include <sbMemoryUtils.h>
42 
43 /***************************************************************************/
44 // Helpers for static convert functions...
45 
52 static void
53 Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)
54 {
55  PRIntn decpt, sign, numdigits;
56  char *num, *nump;
57  char *bufp = buf;
58  char *endnum;
59 
60  /* If anything fails, we store an empty string in 'buf' */
61  num = (char*)malloc(bufsz);
62  if (num == NULL) {
63  buf[0] = '\0';
64  return;
65  }
66  if (PR_dtoa(fval, 2, prcsn, &decpt, &sign, &endnum, num, bufsz)
67  == PR_FAILURE) {
68  buf[0] = '\0';
69  goto done;
70  }
71  numdigits = endnum - num;
72  nump = num;
73 
74  /*
75  * The NSPR code had a fancy way of checking that we weren't dealing
76  * with -0.0 or -NaN, but I'll just use < instead.
77  * XXX Should we check !isnan(fval) as well? Is it portable? We
78  * probably don't need to bother since NAN isn't portable.
79  */
80  if (sign && fval < 0.0f) {
81  *bufp++ = '-';
82  }
83 
84  if (decpt == 9999) {
85  while ((*bufp++ = *nump++) != 0) {} /* nothing to execute */
86  goto done;
87  }
88 
89  if (decpt > (prcsn+1) || decpt < -(prcsn-1) || decpt < -5) {
90  *bufp++ = *nump++;
91  if (numdigits != 1) {
92  *bufp++ = '.';
93  }
94 
95  while (*nump != '\0') {
96  *bufp++ = *nump++;
97  }
98  *bufp++ = 'e';
99  PR_snprintf(bufp, bufsz - (bufp - buf), "%+d", decpt-1);
100  }
101  else if (decpt >= 0) {
102  if (decpt == 0) {
103  *bufp++ = '0';
104  }
105  else {
106  while (decpt--) {
107  if (*nump != '\0') {
108  *bufp++ = *nump++;
109  }
110  else {
111  *bufp++ = '0';
112  }
113  }
114  }
115  if (*nump != '\0') {
116  *bufp++ = '.';
117  while (*nump != '\0') {
118  *bufp++ = *nump++;
119  }
120  }
121  *bufp++ = '\0';
122  }
123  else if (decpt < 0) {
124  *bufp++ = '0';
125  *bufp++ = '.';
126  while (decpt++) {
127  *bufp++ = '0';
128  }
129 
130  while (*nump != '\0') {
131  *bufp++ = *nump++;
132  }
133  *bufp++ = '\0';
134  }
135 done:
136  free(num);
137 }
138 
139 static nsresult String2Double(const char* aString, double* retval)
140 {
141  char* next;
142  double value = PR_strtod(aString, &next);
143  if(next == aString)
144  return NS_ERROR_CANNOT_CONVERT_DATA;
145  *retval = value;
146  return NS_OK;
147 }
148 
149 static nsresult AString2Double(const nsAString& aString, double* retval)
150 {
151  char* pChars = ToNewCString(NS_ConvertUTF16toUTF8(aString));
152  if(!pChars)
153  return NS_ERROR_OUT_OF_MEMORY;
154  nsresult rv = String2Double(pChars, retval);
155  NS_Free(pChars);
156  return rv;
157 }
158 
159 static nsresult AUTF8String2Double(const nsAUTF8String& aString, double* retval)
160 {
161  return String2Double(PromiseFlatUTF8String(aString).get(), retval);
162 }
163 
164 static nsresult ACString2Double(const nsACString& aString, double* retval)
165 {
166  return String2Double(PromiseFlatCString(aString).get(), retval);
167 }
168 
169 // Fills outVariant with double, PRUint32, or PRInt32.
170 // Returns NS_OK, an error code, or a non-NS_OK success code
171 static nsresult ToManageableNumber(const nsDiscriminatedUnion& inData,
172  nsDiscriminatedUnion* outData)
173 {
174  nsresult rv;
175 
176  switch(inData.mType)
177  {
178  // This group results in a PRInt32...
179 
180 #define CASE__NUMBER_INT32(type_, member_) \
181  case nsIDataType :: type_ : \
182  outData->u.mInt32Value = inData.u. member_ ; \
183  outData->mType = nsIDataType::VTYPE_INT32; \
184  return NS_OK;
185 
186  CASE__NUMBER_INT32(VTYPE_INT8, mInt8Value)
187  CASE__NUMBER_INT32(VTYPE_INT16, mInt16Value)
188  CASE__NUMBER_INT32(VTYPE_INT32, mInt32Value)
189  CASE__NUMBER_INT32(VTYPE_UINT8, mUint8Value)
190  CASE__NUMBER_INT32(VTYPE_UINT16, mUint16Value)
191  CASE__NUMBER_INT32(VTYPE_BOOL, mBoolValue)
192  CASE__NUMBER_INT32(VTYPE_CHAR, mCharValue)
193  CASE__NUMBER_INT32(VTYPE_WCHAR, mWCharValue)
194 
195 #undef CASE__NUMBER_INT32
196 
197  // This group results in a PRUint32...
198 
199  case nsIDataType::VTYPE_UINT32:
200  outData->u.mInt32Value = inData.u.mUint32Value;
201  outData->mType = nsIDataType::VTYPE_INT32;
202  return NS_OK;
203 
204  // This group results in a double...
205 
206  case nsIDataType::VTYPE_INT64:
207  case nsIDataType::VTYPE_UINT64:
208  // XXX Need boundary checking here.
209  // We may need to return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA
210  LL_L2D(outData->u.mDoubleValue, inData.u.mInt64Value);
211  outData->mType = nsIDataType::VTYPE_DOUBLE;
212  return NS_OK;
213  case nsIDataType::VTYPE_FLOAT:
214  outData->u.mDoubleValue = inData.u.mFloatValue;
215  outData->mType = nsIDataType::VTYPE_DOUBLE;
216  return NS_OK;
217  case nsIDataType::VTYPE_DOUBLE:
218  outData->u.mDoubleValue = inData.u.mDoubleValue;
219  outData->mType = nsIDataType::VTYPE_DOUBLE;
220  return NS_OK;
221  case nsIDataType::VTYPE_CHAR_STR:
222  case nsIDataType::VTYPE_STRING_SIZE_IS:
223  rv = String2Double(inData.u.str.mStringValue, &outData->u.mDoubleValue);
224  if(NS_FAILED(rv))
225  return rv;
226  outData->mType = nsIDataType::VTYPE_DOUBLE;
227  return NS_OK;
228  case nsIDataType::VTYPE_DOMSTRING:
229  case nsIDataType::VTYPE_ASTRING:
230  rv = AString2Double(*inData.u.mAStringValue, &outData->u.mDoubleValue);
231  if(NS_FAILED(rv))
232  return rv;
233  outData->mType = nsIDataType::VTYPE_DOUBLE;
234  return NS_OK;
235  case nsIDataType::VTYPE_UTF8STRING:
237  &outData->u.mDoubleValue);
238  if(NS_FAILED(rv))
239  return rv;
240  outData->mType = nsIDataType::VTYPE_DOUBLE;
241  return NS_OK;
242  case nsIDataType::VTYPE_CSTRING:
243  rv = ACString2Double(*inData.u.mCStringValue,
244  &outData->u.mDoubleValue);
245  if(NS_FAILED(rv))
246  return rv;
247  outData->mType = nsIDataType::VTYPE_DOUBLE;
248  return NS_OK;
249  case nsIDataType::VTYPE_WCHAR_STR:
250  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
251  rv = AString2Double(nsDependentString(inData.u.wstr.mWStringValue),
252  &outData->u.mDoubleValue);
253  if(NS_FAILED(rv))
254  return rv;
255  outData->mType = nsIDataType::VTYPE_DOUBLE;
256  return NS_OK;
257 
258  // This group fails...
259 
260  case nsIDataType::VTYPE_VOID:
261  case nsIDataType::VTYPE_ID:
262  case nsIDataType::VTYPE_INTERFACE:
263  case nsIDataType::VTYPE_INTERFACE_IS:
264  case nsIDataType::VTYPE_ARRAY:
265  case nsIDataType::VTYPE_EMPTY_ARRAY:
266  case nsIDataType::VTYPE_EMPTY:
267  default:
268  return NS_ERROR_CANNOT_CONVERT_DATA;
269  }
270 }
271 
272 /***************************************************************************/
273 // Array helpers...
274 
276 {
277  NS_ASSERTION(data->mType == nsIDataType::VTYPE_ARRAY, "bad FreeArray call");
278  NS_ASSERTION(data->u.array.mArrayValue, "bad array");
279  NS_ASSERTION(data->u.array.mArrayCount, "bad array count");
280 
281 #define CASE__FREE_ARRAY_PTR(type_, ctype_) \
282  case nsIDataType:: type_ : \
283  { \
284  ctype_ ** p = (ctype_ **) data->u.array.mArrayValue; \
285  for(PRUint32 i = data->u.array.mArrayCount; i > 0; p++, i--) \
286  if(*p) \
287  NS_Free((char*)*p); \
288  break; \
289  }
290 
291 #define CASE__FREE_ARRAY_IFACE(type_, ctype_) \
292  case nsIDataType:: type_ : \
293  { \
294  ctype_ ** p = (ctype_ **) data->u.array.mArrayValue; \
295  for(PRUint32 i = data->u.array.mArrayCount; i > 0; p++, i--) \
296  if(*p) \
297  (*p)->Release(); \
298  break; \
299  }
300 
301  switch(data->u.array.mArrayType)
302  {
303  case nsIDataType::VTYPE_INT8:
304  case nsIDataType::VTYPE_INT16:
305  case nsIDataType::VTYPE_INT32:
306  case nsIDataType::VTYPE_INT64:
307  case nsIDataType::VTYPE_UINT8:
308  case nsIDataType::VTYPE_UINT16:
309  case nsIDataType::VTYPE_UINT32:
310  case nsIDataType::VTYPE_UINT64:
311  case nsIDataType::VTYPE_FLOAT:
312  case nsIDataType::VTYPE_DOUBLE:
313  case nsIDataType::VTYPE_BOOL:
314  case nsIDataType::VTYPE_CHAR:
315  case nsIDataType::VTYPE_WCHAR:
316  break;
317 
318  // XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
319  CASE__FREE_ARRAY_PTR(VTYPE_ID, nsID)
320  CASE__FREE_ARRAY_PTR(VTYPE_CHAR_STR, char)
321  CASE__FREE_ARRAY_PTR(VTYPE_WCHAR_STR, PRUnichar)
322  CASE__FREE_ARRAY_IFACE(VTYPE_INTERFACE, nsISupports)
323  CASE__FREE_ARRAY_IFACE(VTYPE_INTERFACE_IS, nsISupports)
324 
325  // The rest are illegal.
326  case nsIDataType::VTYPE_VOID:
327  case nsIDataType::VTYPE_ASTRING:
328  case nsIDataType::VTYPE_DOMSTRING:
329  case nsIDataType::VTYPE_UTF8STRING:
330  case nsIDataType::VTYPE_CSTRING:
331  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
332  case nsIDataType::VTYPE_STRING_SIZE_IS:
333  case nsIDataType::VTYPE_ARRAY:
334  case nsIDataType::VTYPE_EMPTY_ARRAY:
335  case nsIDataType::VTYPE_EMPTY:
336  default:
337  NS_ERROR("bad type in array!");
338  break;
339  }
340 
341  // Free the array memory.
342  NS_Free((char*)data->u.array.mArrayValue);
343 
344 #undef CASE__FREE_ARRAY_PTR
345 #undef CASE__FREE_ARRAY_IFACE
346 }
347 
348 static nsresult CloneArray(PRUint16 inType, const nsIID* inIID,
349  PRUint32 inCount, void* inValue,
350  PRUint16* outType, nsIID* outIID,
351  PRUint32* outCount, void** outValue)
352 {
353  NS_ASSERTION(inCount, "bad param");
354  NS_ASSERTION(inValue, "bad param");
355  NS_ASSERTION(outType, "bad param");
356  NS_ASSERTION(outCount, "bad param");
357  NS_ASSERTION(outValue, "bad param");
358 
359  PRUint32 allocatedValueCount = 0;
360  nsresult rv = NS_OK;
361  PRUint32 i;
362 
363  // First we figure out the size of the elements for the new u.array.
364 
365  size_t elementSize;
366  size_t allocSize;
367 
368  switch(inType)
369  {
370  case nsIDataType::VTYPE_INT8:
371  elementSize = sizeof(PRInt8);
372  break;
373  case nsIDataType::VTYPE_INT16:
374  elementSize = sizeof(PRInt16);
375  break;
376  case nsIDataType::VTYPE_INT32:
377  elementSize = sizeof(PRInt32);
378  break;
379  case nsIDataType::VTYPE_INT64:
380  elementSize = sizeof(PRInt64);
381  break;
382  case nsIDataType::VTYPE_UINT8:
383  elementSize = sizeof(PRUint8);
384  break;
385  case nsIDataType::VTYPE_UINT16:
386  elementSize = sizeof(PRUint16);
387  break;
388  case nsIDataType::VTYPE_UINT32:
389  elementSize = sizeof(PRUint32);
390  break;
391  case nsIDataType::VTYPE_UINT64:
392  elementSize = sizeof(PRUint64);
393  break;
394  case nsIDataType::VTYPE_FLOAT:
395  elementSize = sizeof(float);
396  break;
397  case nsIDataType::VTYPE_DOUBLE:
398  elementSize = sizeof(double);
399  break;
400  case nsIDataType::VTYPE_BOOL:
401  elementSize = sizeof(PRBool);
402  break;
403  case nsIDataType::VTYPE_CHAR:
404  elementSize = sizeof(char);
405  break;
406  case nsIDataType::VTYPE_WCHAR:
407  elementSize = sizeof(PRUnichar);
408  break;
409 
410  // XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
411  case nsIDataType::VTYPE_ID:
412  case nsIDataType::VTYPE_CHAR_STR:
413  case nsIDataType::VTYPE_WCHAR_STR:
414  case nsIDataType::VTYPE_INTERFACE:
415  case nsIDataType::VTYPE_INTERFACE_IS:
416  elementSize = sizeof(void*);
417  break;
418 
419  // The rest are illegal.
420  case nsIDataType::VTYPE_ASTRING:
421  case nsIDataType::VTYPE_DOMSTRING:
422  case nsIDataType::VTYPE_UTF8STRING:
423  case nsIDataType::VTYPE_CSTRING:
424  case nsIDataType::VTYPE_STRING_SIZE_IS:
425  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
426  case nsIDataType::VTYPE_VOID:
427  case nsIDataType::VTYPE_ARRAY:
428  case nsIDataType::VTYPE_EMPTY_ARRAY:
429  case nsIDataType::VTYPE_EMPTY:
430  default:
431  NS_ERROR("bad type in array!");
432  return NS_ERROR_CANNOT_CONVERT_DATA;
433  }
434 
435 
436  // Alloc the u.array.
437 
438  allocSize = inCount * elementSize;
439  *outValue = NS_Alloc(allocSize);
440  if(!*outValue)
441  return NS_ERROR_OUT_OF_MEMORY;
442 
443  // Clone the elements.
444 
445  switch(inType)
446  {
447  case nsIDataType::VTYPE_INT8:
448  case nsIDataType::VTYPE_INT16:
449  case nsIDataType::VTYPE_INT32:
450  case nsIDataType::VTYPE_INT64:
451  case nsIDataType::VTYPE_UINT8:
452  case nsIDataType::VTYPE_UINT16:
453  case nsIDataType::VTYPE_UINT32:
454  case nsIDataType::VTYPE_UINT64:
455  case nsIDataType::VTYPE_FLOAT:
456  case nsIDataType::VTYPE_DOUBLE:
457  case nsIDataType::VTYPE_BOOL:
458  case nsIDataType::VTYPE_CHAR:
459  case nsIDataType::VTYPE_WCHAR:
460  memcpy(*outValue, inValue, allocSize);
461  break;
462 
463  case nsIDataType::VTYPE_INTERFACE_IS:
464  if(outIID)
465  *outIID = *inIID;
466  // fall through...
467  case nsIDataType::VTYPE_INTERFACE:
468  {
469  memcpy(*outValue, inValue, allocSize);
470 
471  nsISupports** p = (nsISupports**) *outValue;
472  for(i = inCount; i > 0; p++, i--)
473  if(*p)
474  (*p)->AddRef();
475  break;
476  }
477 
478  // XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
479  case nsIDataType::VTYPE_ID:
480  {
481  nsID** inp = (nsID**) inValue;
482  nsID** outp = (nsID**) *outValue;
483  for(i = inCount; i > 0; i--)
484  {
485  nsID* idp = *(inp++);
486  if(idp)
487  {
488  if(nsnull == (*(outp++) = (nsID*)
489  SB_CloneMemory((char*)idp, sizeof(nsID))))
490  goto bad;
491  }
492  else
493  *(outp++) = nsnull;
494  allocatedValueCount++;
495  }
496  break;
497  }
498 
499  case nsIDataType::VTYPE_CHAR_STR:
500  {
501  char** inp = (char**) inValue;
502  char** outp = (char**) *outValue;
503  for(i = inCount; i > 0; i--)
504  {
505  char* str = *(inp++);
506  if(str)
507  {
508  if(nsnull == (*(outp++) = (char*)
509  SB_CloneMemory(str, (strlen(str)+1)*sizeof(char))))
510  goto bad;
511  }
512  else
513  *(outp++) = nsnull;
514  allocatedValueCount++;
515  }
516  break;
517  }
518 
519  case nsIDataType::VTYPE_WCHAR_STR:
520  {
521  PRUnichar** inp = (PRUnichar**) inValue;
522  PRUnichar** outp = (PRUnichar**) *outValue;
523  for(i = inCount; i > 0; i--)
524  {
525  PRUnichar* str = *(inp++);
526  if(str)
527  {
528  if(nsnull == (*(outp++) = (PRUnichar*)
529  SB_CloneMemory(str,
530  (nsCRT::strlen(str)+1)*sizeof(PRUnichar))))
531  goto bad;
532  }
533  else
534  *(outp++) = nsnull;
535  allocatedValueCount++;
536  }
537  break;
538  }
539 
540  // The rest are illegal.
541  case nsIDataType::VTYPE_VOID:
542  case nsIDataType::VTYPE_ARRAY:
543  case nsIDataType::VTYPE_EMPTY_ARRAY:
544  case nsIDataType::VTYPE_EMPTY:
545  case nsIDataType::VTYPE_ASTRING:
546  case nsIDataType::VTYPE_DOMSTRING:
547  case nsIDataType::VTYPE_UTF8STRING:
548  case nsIDataType::VTYPE_CSTRING:
549  case nsIDataType::VTYPE_STRING_SIZE_IS:
550  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
551  default:
552  NS_ERROR("bad type in array!");
553  return NS_ERROR_CANNOT_CONVERT_DATA;
554  }
555 
556  *outType = inType;
557  *outCount = inCount;
558  return NS_OK;
559 
560 bad:
561  if(*outValue)
562  {
563  char** p = (char**) *outValue;
564  for(i = allocatedValueCount; i > 0; p++, i--)
565  if(*p)
566  NS_Free(*p);
567  NS_Free((char*)*outValue);
568  *outValue = nsnull;
569  }
570  return rv;
571 }
572 
573 /***************************************************************************/
574 
575 #define TRIVIAL_DATA_CONVERTER(type_, data_, member_, retval_) \
576  if(data_.mType == nsIDataType :: type_) { \
577  *retval_ = data_.u.member_; \
578  return NS_OK; \
579  }
580 
581 #define NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_) \
582  /* static */ nsresult \
583  sbVariant::ConvertTo##name_ (const nsDiscriminatedUnion& data, \
584  Ctype_ *_retval) \
585 { \
586  TRIVIAL_DATA_CONVERTER(type_, data, m##name_##Value, _retval) \
587  nsDiscriminatedUnion tempData; \
588  sbVariant::Initialize(&tempData); \
589  nsresult rv = ToManageableNumber(data, &tempData); \
590  /* */ \
591  /* NOTE: rv may indicate a success code that we want to preserve */ \
592  /* For the final return. So all the return cases below should return */ \
593  /* this rv when indicating success. */ \
594  /* */ \
595  if(NS_FAILED(rv)) \
596  return rv; \
597  switch(tempData.mType) \
598 {
599 
600 #define CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(Ctype_) \
601  case nsIDataType::VTYPE_INT32: \
602  *_retval = ( Ctype_ ) tempData.u.mInt32Value; \
603  return rv;
604 
605 #define CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_) \
606  case nsIDataType::VTYPE_INT32: \
607 { \
608  PRInt32 value = tempData.u.mInt32Value; \
609  if(value < min_ || value > max_) \
610  return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
611  *_retval = ( Ctype_ ) value; \
612  return rv; \
613 }
614 
615 #define CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(Ctype_) \
616  case nsIDataType::VTYPE_UINT32: \
617  *_retval = ( Ctype_ ) tempData.u.mUint32Value; \
618  return rv;
619 
620 #define CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_) \
621  case nsIDataType::VTYPE_UINT32: \
622 { \
623  PRUint32 value = tempData.u.mUint32Value; \
624  if(value > max_) \
625  return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
626  *_retval = ( Ctype_ ) value; \
627  return rv; \
628 }
629 
630 #define CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(Ctype_) \
631  case nsIDataType::VTYPE_DOUBLE: \
632  *_retval = ( Ctype_ ) tempData.u.mDoubleValue; \
633  return rv;
634 
635 #define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX(Ctype_, min_, max_) \
636  case nsIDataType::VTYPE_DOUBLE: \
637 { \
638  double value = tempData.u.mDoubleValue; \
639  if(value < min_ || value > max_) \
640  return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
641  *_retval = ( Ctype_ ) value; \
642  return rv; \
643 }
644 
645 #define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_) \
646  case nsIDataType::VTYPE_DOUBLE: \
647 { \
648  double value = tempData.u.mDoubleValue; \
649  if(value < min_ || value > max_) \
650  return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; \
651  *_retval = ( Ctype_ ) value; \
652  return (0.0 == fmod(value,1.0)) ? \
653 rv : NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA; \
654 }
655 
656 #define CASES__NUMERIC_CONVERSION_NORMAL(Ctype_, min_, max_) \
657  CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_) \
658  CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_) \
659  CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_)
660 
661 #define NUMERIC_CONVERSION_METHOD_END \
662  default: \
663  NS_ERROR("bad type returned from ToManageableNumber"); \
664  return NS_ERROR_CANNOT_CONVERT_DATA; \
665 } \
666 }
667 
668 #define NUMERIC_CONVERSION_METHOD_NORMAL(type_, Ctype_, name_, min_, max_) \
669  NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_) \
670  CASES__NUMERIC_CONVERSION_NORMAL(Ctype_, min_, max_) \
671  NUMERIC_CONVERSION_METHOD_END
672 
673 /***************************************************************************/
674 // These expand into full public methods...
675 
676 NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_INT8, PRUint8, Int8, (-127-1), 127)
677 NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_INT16, PRInt16, Int16, (-32767-1), 32767)
678 
679 NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_INT32, PRInt32, Int32)
681 CASE__NUMERIC_CONVERSION_UINT32_MAX(PRInt32, 2147483647)
682 CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(PRInt32, (-2147483647-1), 2147483647)
684 
685 NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_UINT8, PRUint8, Uint8, 0, 255)
686 NUMERIC_CONVERSION_METHOD_NORMAL(VTYPE_UINT16, PRUint16, Uint16, 0, 65535)
687 
688 NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_UINT32, PRUint32, Uint32)
689 CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(PRUint32, 0, 2147483647)
691 CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(PRUint32, 0, 4294967295U)
693 
694 // XXX toFloat convertions need to be fixed!
695 NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_FLOAT, float, Float)
700 
701 NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_DOUBLE, double, Double)
706 
707 // XXX toChar convertions need to be fixed!
708 NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_CHAR, char, Char)
713 
714 // XXX toWChar convertions need to be fixed!
715 NUMERIC_CONVERSION_METHOD_BEGIN(VTYPE_WCHAR, PRUnichar, WChar)
720 
721 #undef NUMERIC_CONVERSION_METHOD_BEGIN
722 #undef CASE__NUMERIC_CONVERSION_INT32_JUST_CAST
723 #undef CASE__NUMERIC_CONVERSION_INT32_MIN_MAX
724 #undef CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST
725 #undef CASE__NUMERIC_CONVERSION_UINT32_MIN_MAX
726 #undef CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST
727 #undef CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX
728 #undef CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT
729 #undef CASES__NUMERIC_CONVERSION_NORMAL
730 #undef NUMERIC_CONVERSION_METHOD_END
731 #undef NUMERIC_CONVERSION_METHOD_NORMAL
732 
733 /***************************************************************************/
734 
735 // Just leverage a numeric converter for bool (but restrict the values).
736 // XXX Is this really what we want to do?
737 
738 /* static */ nsresult
740 {
741  TRIVIAL_DATA_CONVERTER(VTYPE_BOOL, data, mBoolValue, _retval)
742 
743  double val;
744  nsresult rv = sbVariant::ConvertToDouble(data, &val);
745  if(NS_FAILED(rv))
746  return rv;
747  *_retval = 0.0 != val;
748  return rv;
749 }
750 
751 /***************************************************************************/
752 
753 /* static */ nsresult
755 {
756  TRIVIAL_DATA_CONVERTER(VTYPE_INT64, data, mInt64Value, _retval)
757  TRIVIAL_DATA_CONVERTER(VTYPE_UINT64, data, mUint64Value, _retval)
758 
759  nsDiscriminatedUnion tempData;
760  sbVariant::Initialize(&tempData);
761  nsresult rv = ToManageableNumber(data, &tempData);
762  if(NS_FAILED(rv))
763  return rv;
764  switch(tempData.mType)
765  {
766  case nsIDataType::VTYPE_INT32:
767  LL_I2L(*_retval, tempData.u.mInt32Value);
768  return rv;
769  case nsIDataType::VTYPE_UINT32:
770  LL_UI2L(*_retval, tempData.u.mUint32Value);
771  return rv;
772  case nsIDataType::VTYPE_DOUBLE:
773  // XXX should check for data loss here!
774  LL_D2L(*_retval, tempData.u.mDoubleValue);
775  return rv;
776  default:
777  NS_ERROR("bad type returned from ToManageableNumber");
778  return NS_ERROR_CANNOT_CONVERT_DATA;
779  }
780 }
781 
782 /* static */ nsresult
784 {
785  return sbVariant::ConvertToInt64(data, (PRInt64 *)_retval);
786 }
787 
788 /***************************************************************************/
789 
790 static PRBool String2ID(const nsDiscriminatedUnion& data, nsID* pid)
791 {
792  nsAutoString tempString;
793  nsAString* pString;
794 
795  switch(data.mType)
796  {
797  case nsIDataType::VTYPE_CHAR_STR:
798  case nsIDataType::VTYPE_STRING_SIZE_IS:
799  return pid->Parse(data.u.str.mStringValue);
800  case nsIDataType::VTYPE_CSTRING:
801  return pid->Parse(PromiseFlatCString(*data.u.mCStringValue).get());
802  case nsIDataType::VTYPE_UTF8STRING:
803  return pid->Parse(PromiseFlatUTF8String(*data.u.mUTF8StringValue).get());
804  case nsIDataType::VTYPE_ASTRING:
805  case nsIDataType::VTYPE_DOMSTRING:
806  pString = data.u.mAStringValue;
807  break;
808  case nsIDataType::VTYPE_WCHAR_STR:
809  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
810  tempString.Assign(data.u.wstr.mWStringValue);
811  pString = &tempString;
812  break;
813  default:
814  NS_ERROR("bad type in call to String2ID");
815  return PR_FALSE;
816  }
817 
818  char* pChars = ToNewCString(NS_LossyConvertUTF16toASCII(*pString));
819  if(!pChars)
820  return PR_FALSE;
821  PRBool result = pid->Parse(pChars);
822  NS_Free(pChars);
823  return result;
824 }
825 
826 /* static */ nsresult
828 {
829  nsID id;
830 
831  switch(data.mType)
832  {
833  case nsIDataType::VTYPE_ID:
834  *_retval = data.u.mIDValue;
835  return NS_OK;
836  case nsIDataType::VTYPE_INTERFACE:
837  *_retval = NS_GET_IID(nsISupports);
838  return NS_OK;
839  case nsIDataType::VTYPE_INTERFACE_IS:
840  *_retval = data.u.iface.mInterfaceID;
841  return NS_OK;
842  case nsIDataType::VTYPE_ASTRING:
843  case nsIDataType::VTYPE_DOMSTRING:
844  case nsIDataType::VTYPE_UTF8STRING:
845  case nsIDataType::VTYPE_CSTRING:
846  case nsIDataType::VTYPE_CHAR_STR:
847  case nsIDataType::VTYPE_WCHAR_STR:
848  case nsIDataType::VTYPE_STRING_SIZE_IS:
849  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
850  if(!String2ID(data, &id))
851  return NS_ERROR_CANNOT_CONVERT_DATA;
852  *_retval = id;
853  return NS_OK;
854  default:
855  return NS_ERROR_CANNOT_CONVERT_DATA;
856  }
857 }
858 
859 /***************************************************************************/
860 
861 static nsresult ToString(const nsDiscriminatedUnion& data,
862  nsACString & outString)
863 {
864  char* ptr;
865 
866  switch(data.mType)
867  {
868  // all the stuff we don't handle...
869  case nsIDataType::VTYPE_ASTRING:
870  case nsIDataType::VTYPE_DOMSTRING:
871  case nsIDataType::VTYPE_UTF8STRING:
872  case nsIDataType::VTYPE_CSTRING:
873  case nsIDataType::VTYPE_CHAR_STR:
874  case nsIDataType::VTYPE_WCHAR_STR:
875  case nsIDataType::VTYPE_STRING_SIZE_IS:
876  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
877  case nsIDataType::VTYPE_WCHAR:
878  NS_ERROR("ToString being called for a string type - screwy logic!");
879  // fall through...
880 
881  // XXX We might want stringified versions of these... ???
882 
883  case nsIDataType::VTYPE_VOID:
884  case nsIDataType::VTYPE_EMPTY:
885  outString.Truncate();
886  outString.SetIsVoid(true);
887  return NS_OK;
888 
889  case nsIDataType::VTYPE_EMPTY_ARRAY:
890  case nsIDataType::VTYPE_ARRAY:
891  case nsIDataType::VTYPE_INTERFACE:
892  case nsIDataType::VTYPE_INTERFACE_IS:
893  default:
894  return NS_ERROR_CANNOT_CONVERT_DATA;
895 
896  // nsID has its own text formater.
897 
898  case nsIDataType::VTYPE_ID:
899  ptr = data.u.mIDValue.ToString();
900  if(!ptr)
901  return NS_ERROR_OUT_OF_MEMORY;
902  outString.Assign(ptr);
903  NS_Free(ptr);
904  return NS_OK;
905 
906  // Can't use PR_smprintf for floats, since it's locale-dependent
907 #define CASE__APPENDFLOAT_NUMBER(type_, member_) \
908  case nsIDataType :: type_ : \
909  { \
910  char buf[40]; \
911  Modified_cnvtf(buf, sizeof(buf), 6, data.u. member_); \
912  outString.Assign(buf); \
913  return NS_OK; \
914  }
915 
916 #define CASE__APPENDDOUBLE_NUMBER(type_, member_) \
917  case nsIDataType :: type_ : \
918  { \
919  char buf[40]; \
920  Modified_cnvtf(buf, sizeof(buf), 15, data.u. member_); \
921  outString.Assign(buf); \
922  return NS_OK; \
923  }
924 
925  CASE__APPENDFLOAT_NUMBER(VTYPE_FLOAT, mFloatValue)
926  CASE__APPENDDOUBLE_NUMBER(VTYPE_DOUBLE, mDoubleValue)
927 
928 #undef CASE__APPENDFLOAT_NUMBER
929 #undef CASE__APPENDDOUBLE_NUMBER
930 
931  // the rest can be PR_smprintf'd and use common code.
932 
933 #define CASE__SMPRINTF_NUMBER(type_, format_, cast_, member_) \
934  case nsIDataType :: type_ : \
935  ptr = PR_smprintf( format_ , (cast_) data.u. member_ ); \
936  break;
937 
938  CASE__SMPRINTF_NUMBER(VTYPE_INT8, "%d", int, mInt8Value)
939  CASE__SMPRINTF_NUMBER(VTYPE_INT16, "%d", int, mInt16Value)
940  CASE__SMPRINTF_NUMBER(VTYPE_INT32, "%d", int, mInt32Value)
941  CASE__SMPRINTF_NUMBER(VTYPE_INT64, "%lld", PRInt64, mInt64Value)
942 
943  CASE__SMPRINTF_NUMBER(VTYPE_UINT8, "%u", unsigned, mUint8Value)
944  CASE__SMPRINTF_NUMBER(VTYPE_UINT16, "%u", unsigned, mUint16Value)
945  CASE__SMPRINTF_NUMBER(VTYPE_UINT32, "%u", unsigned, mUint32Value)
946  CASE__SMPRINTF_NUMBER(VTYPE_UINT64, "%llu", PRInt64, mUint64Value)
947 
948  // XXX Would we rather print "true" / "false" ?
949  CASE__SMPRINTF_NUMBER(VTYPE_BOOL, "%d", int, mBoolValue)
950 
951  CASE__SMPRINTF_NUMBER(VTYPE_CHAR, "%c", char, mCharValue)
952 
953 #undef CASE__SMPRINTF_NUMBER
954  }
955 
956  if(!ptr)
957  return NS_ERROR_OUT_OF_MEMORY;
958  outString.Assign(ptr);
959  PR_smprintf_free(ptr);
960  return NS_OK;
961 }
962 
963 /* static */ nsresult
965  nsAString & _retval)
966 {
967  switch(data.mType)
968  {
969  case nsIDataType::VTYPE_ASTRING:
970  case nsIDataType::VTYPE_DOMSTRING:
971  _retval.Assign(*data.u.mAStringValue);
972  return NS_OK;
973  case nsIDataType::VTYPE_CSTRING:
974  CopyASCIItoUTF16(*data.u.mCStringValue, _retval);
975  return NS_OK;
976  case nsIDataType::VTYPE_UTF8STRING:
977  CopyUTF8toUTF16(*data.u.mUTF8StringValue, _retval);
978  return NS_OK;
979  case nsIDataType::VTYPE_CHAR_STR:
980  CopyASCIItoUTF16(nsDependentCString(data.u.str.mStringValue), _retval);
981  return NS_OK;
982  case nsIDataType::VTYPE_WCHAR_STR:
983  _retval.Assign(data.u.wstr.mWStringValue);
984  return NS_OK;
985  case nsIDataType::VTYPE_STRING_SIZE_IS:
986  CopyASCIItoUTF16(nsDependentCString(data.u.str.mStringValue,
987  data.u.str.mStringLength),
988  _retval);
989  return NS_OK;
990  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
991  _retval.Assign(data.u.wstr.mWStringValue, data.u.wstr.mWStringLength);
992  return NS_OK;
993  case nsIDataType::VTYPE_WCHAR:
994  _retval.Assign(data.u.mWCharValue);
995  return NS_OK;
996  default:
997  {
998  nsCAutoString tempCString;
999  nsresult rv = ToString(data, tempCString);
1000  if(NS_FAILED(rv))
1001  return rv;
1002  CopyASCIItoUTF16(tempCString, _retval);
1003  return NS_OK;
1004  }
1005  }
1006 }
1007 
1008 /* static */ nsresult
1010  nsACString & _retval)
1011 {
1012  switch(data.mType)
1013  {
1014  case nsIDataType::VTYPE_ASTRING:
1015  case nsIDataType::VTYPE_DOMSTRING:
1016  LossyCopyUTF16toASCII(*data.u.mAStringValue, _retval);
1017  return NS_OK;
1018  case nsIDataType::VTYPE_CSTRING:
1019  _retval.Assign(*data.u.mCStringValue);
1020  return NS_OK;
1021  case nsIDataType::VTYPE_UTF8STRING:
1022  // XXX This is an extra copy that should be avoided
1023  // once Jag lands support for UTF8String and associated
1024  // conversion methods.
1025  LossyCopyUTF16toASCII(NS_ConvertUTF8toUTF16(*data.u.mUTF8StringValue),
1026  _retval);
1027  return NS_OK;
1028  case nsIDataType::VTYPE_CHAR_STR:
1029  _retval.Assign(*data.u.str.mStringValue);
1030  return NS_OK;
1031  case nsIDataType::VTYPE_WCHAR_STR:
1032  LossyCopyUTF16toASCII(nsDependentString(data.u.wstr.mWStringValue),
1033  _retval);
1034  return NS_OK;
1035  case nsIDataType::VTYPE_STRING_SIZE_IS:
1036  _retval.Assign(data.u.str.mStringValue, data.u.str.mStringLength);
1037  return NS_OK;
1038  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
1039  LossyCopyUTF16toASCII(nsDependentString(data.u.wstr.mWStringValue,
1040  data.u.wstr.mWStringLength), _retval);
1041  return NS_OK;
1042  case nsIDataType::VTYPE_WCHAR:
1043  {
1044  const PRUnichar* str = &data.u.mWCharValue;
1045  LossyCopyUTF16toASCII(Substring(str, str + 1), _retval);
1046  return NS_OK;
1047  }
1048  default:
1049  return ToString(data, _retval);
1050  }
1051 }
1052 
1053 /* static */ nsresult
1055  nsAUTF8String & _retval)
1056 {
1057  switch(data.mType)
1058  {
1059  case nsIDataType::VTYPE_ASTRING:
1060  case nsIDataType::VTYPE_DOMSTRING:
1061  CopyUTF16toUTF8(*data.u.mAStringValue, _retval);
1062  return NS_OK;
1063  case nsIDataType::VTYPE_CSTRING:
1064  // XXX Extra copy, can be removed if we're sure CSTRING can
1065  // only contain ASCII.
1066  CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(*data.u.mCStringValue),
1067  _retval);
1068  return NS_OK;
1069  case nsIDataType::VTYPE_UTF8STRING:
1070  _retval.Assign(*data.u.mUTF8StringValue);
1071  return NS_OK;
1072  case nsIDataType::VTYPE_CHAR_STR:
1073  // XXX Extra copy, can be removed if we're sure CHAR_STR can
1074  // only contain ASCII.
1075  CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(data.u.str.mStringValue),
1076  _retval);
1077  return NS_OK;
1078  case nsIDataType::VTYPE_WCHAR_STR:
1079  CopyUTF16toUTF8(nsDependentString(data.u.wstr.mWStringValue), _retval);
1080  return NS_OK;
1081  case nsIDataType::VTYPE_STRING_SIZE_IS:
1082  // XXX Extra copy, can be removed if we're sure CHAR_STR can
1083  // only contain ASCII.
1084  CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(
1085  nsDependentCString(data.u.str.mStringValue,
1086  data.u.str.mStringLength)), _retval);
1087  return NS_OK;
1088  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
1089  CopyUTF16toUTF8(nsDependentString(data.u.wstr.mWStringValue,
1090  data.u.wstr.mWStringLength),
1091  _retval);
1092  return NS_OK;
1093  case nsIDataType::VTYPE_WCHAR:
1094  {
1095  const PRUnichar* str = &data.u.mWCharValue;
1096  CopyUTF16toUTF8(Substring(str, str + 1), _retval);
1097  return NS_OK;
1098  }
1099  default:
1100  {
1101  nsCAutoString tempCString;
1102  nsresult rv = ToString(data, tempCString);
1103  if(NS_FAILED(rv))
1104  return rv;
1105  // XXX Extra copy, can be removed if we're sure tempCString can
1106  // only contain ASCII.
1107  CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(tempCString), _retval);
1108  return NS_OK;
1109  }
1110  }
1111 }
1112 
1113 /* static */ nsresult
1115 {
1116  PRUint32 ignored;
1117  return sbVariant::ConvertToStringWithSize(data, &ignored, _retval);
1118 }
1119 
1120 /* static */ nsresult
1122 {
1123  PRUint32 ignored;
1124  return sbVariant::ConvertToWStringWithSize(data, &ignored, _retval);
1125 }
1126 
1127 /* static */ nsresult
1129  PRUint32 *size, char **str)
1130 {
1131  nsAutoString tempString;
1132  nsCAutoString tempCString;
1133  nsresult rv;
1134 
1135  switch(data.mType)
1136  {
1137  case nsIDataType::VTYPE_ASTRING:
1138  case nsIDataType::VTYPE_DOMSTRING:
1139  *size = data.u.mAStringValue->Length();
1140  tempString = *data.u.mAStringValue;
1141  *str = ToNewCString(NS_ConvertUTF16toUTF8(tempString));
1142  break;
1143  case nsIDataType::VTYPE_CSTRING:
1144  *size = data.u.mCStringValue->Length();
1145  tempCString = *data.u.mCStringValue;
1146  *str = ToNewCString(tempCString);
1147  break;
1148  case nsIDataType::VTYPE_UTF8STRING:
1149  {
1150  // XXX This is doing 1 extra copy. Need to fix this
1151  // when Jag lands UTF8String
1152  // we want:
1153  // *size = *data.mUTF8StringValue->Length();
1154  // *str = ToNewCString(*data.mUTF8StringValue);
1155  // But this will have to do for now.
1156  NS_ConvertUTF8toUTF16 tempString(*data.u.mUTF8StringValue);
1157  *size = tempString.Length();
1158 
1159  tempCString = *data.u.mUTF8StringValue;
1160  *str = ToNewCString(tempCString );
1161  break;
1162  }
1163  case nsIDataType::VTYPE_CHAR_STR:
1164  {
1165  nsDependentCString cString(data.u.str.mStringValue);
1166  *size = cString.Length();
1167  *str = ToNewCString(cString);
1168  break;
1169  }
1170  case nsIDataType::VTYPE_WCHAR_STR:
1171  {
1172  nsDependentString string(data.u.wstr.mWStringValue);
1173  *size = string.Length();
1174  *str = ToNewCString(NS_ConvertUTF16toUTF8(string));
1175  break;
1176  }
1177  case nsIDataType::VTYPE_STRING_SIZE_IS:
1178  {
1179  nsDependentCString cString(data.u.str.mStringValue,
1180  data.u.str.mStringLength);
1181  *size = cString.Length();
1182  *str = ToNewCString(cString);
1183  break;
1184  }
1185  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
1186  {
1187  nsDependentString string(data.u.wstr.mWStringValue,
1188  data.u.wstr.mWStringLength);
1189  *size = string.Length();
1190  *str = ToNewCString(NS_ConvertUTF16toUTF8(string));
1191  break;
1192  }
1193  case nsIDataType::VTYPE_WCHAR:
1194  tempString.Assign(data.u.mWCharValue);
1195  *size = tempString.Length();
1196  *str = ToNewCString(NS_ConvertUTF16toUTF8(tempString));
1197  break;
1198  default:
1199  rv = ToString(data, tempCString);
1200  if(NS_FAILED(rv))
1201  return rv;
1202  *size = tempCString.Length();
1203  *str = ToNewCString(tempCString);
1204  break;
1205  }
1206 
1207  return *str ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
1208 }
1209 /* static */ nsresult
1211  PRUint32 *size, PRUnichar **str)
1212 {
1213  nsAutoString tempString;
1214  nsCAutoString tempCString;
1215  nsresult rv;
1216 
1217  switch(data.mType)
1218  {
1219  case nsIDataType::VTYPE_ASTRING:
1220  case nsIDataType::VTYPE_DOMSTRING:
1221  *size = data.u.mAStringValue->Length();
1222  *str = ToNewUnicode(*data.u.mAStringValue);
1223  break;
1224  case nsIDataType::VTYPE_CSTRING:
1225  *size = data.u.mCStringValue->Length();
1226  *str = ToNewUnicode(NS_ConvertUTF8toUTF16(*data.u.mCStringValue));
1227  break;
1228  case nsIDataType::VTYPE_UTF8STRING:
1229  {
1230  *str = ToNewUnicode(NS_ConvertUTF8toUTF16(*data.u.mUTF8StringValue));
1231  break;
1232  }
1233  case nsIDataType::VTYPE_CHAR_STR:
1234  {
1235  nsDependentCString cString(data.u.str.mStringValue);
1236  *size = cString.Length();
1237  *str = ToNewUnicode(NS_ConvertUTF8toUTF16(cString));
1238  break;
1239  }
1240  case nsIDataType::VTYPE_WCHAR_STR:
1241  {
1242  nsDependentString string(data.u.wstr.mWStringValue);
1243  *size = string.Length();
1244  *str = ToNewUnicode(string);
1245  break;
1246  }
1247  case nsIDataType::VTYPE_STRING_SIZE_IS:
1248  {
1249  nsDependentCString cString(data.u.str.mStringValue,
1250  data.u.str.mStringLength);
1251  *size = cString.Length();
1252  *str = ToNewUnicode(NS_ConvertUTF8toUTF16(cString));
1253  break;
1254  }
1255  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
1256  {
1257  nsDependentString string(data.u.wstr.mWStringValue,
1258  data.u.wstr.mWStringLength);
1259  *size = string.Length();
1260  *str = ToNewUnicode(string);
1261  break;
1262  }
1263  case nsIDataType::VTYPE_WCHAR:
1264  tempString.Assign(data.u.mWCharValue);
1265  *size = tempString.Length();
1266  *str = ToNewUnicode(tempString);
1267  break;
1268  default:
1269  rv = ToString(data, tempCString);
1270  if(NS_FAILED(rv))
1271  return rv;
1272  *size = tempCString.Length();
1273  *str = ToNewUnicode(NS_ConvertUTF8toUTF16(tempCString));
1274  break;
1275  }
1276 
1277  return *str ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
1278 }
1279 
1280 /* static */ nsresult
1282  nsISupports **_retval)
1283 {
1284  switch(data.mType)
1285  {
1286  case nsIDataType::VTYPE_INTERFACE:
1287  case nsIDataType::VTYPE_INTERFACE_IS:
1288  if (data.u.iface.mInterfaceValue) {
1289  return data.u.iface.mInterfaceValue->
1290  QueryInterface(NS_GET_IID(nsISupports), (void**)_retval);
1291  } else {
1292  *_retval = nsnull;
1293  return NS_OK;
1294  }
1295  default:
1296  return NS_ERROR_CANNOT_CONVERT_DATA;
1297  }
1298 }
1299 
1300 /* static */ nsresult
1302  void * *iface)
1303 {
1304  const nsIID* piid;
1305 
1306  switch(data.mType)
1307  {
1308  case nsIDataType::VTYPE_INTERFACE:
1309  piid = &NS_GET_IID(nsISupports);
1310  break;
1311  case nsIDataType::VTYPE_INTERFACE_IS:
1312  piid = &data.u.iface.mInterfaceID;
1313  break;
1314  default:
1315  return NS_ERROR_CANNOT_CONVERT_DATA;
1316  }
1317 
1318  *iid = (nsIID*) SB_CloneMemory(piid, sizeof(nsIID));
1319  if(!*iid)
1320  return NS_ERROR_OUT_OF_MEMORY;
1321 
1322  if (data.u.iface.mInterfaceValue) {
1323  return data.u.iface.mInterfaceValue->QueryInterface(*piid, iface);
1324  }
1325 
1326  *iface = nsnull;
1327  return NS_OK;
1328 }
1329 
1330 /* static */ nsresult
1332  nsIID* iid, PRUint32 *count, void * *ptr)
1333 {
1334  // XXX perhaps we'd like to add support for converting each of the various
1335  // types into an array containing one element of that type. We can leverage
1336  // CloneArray to do this if we want to support this.
1337 
1338  if(data.mType == nsIDataType::VTYPE_ARRAY)
1339  return CloneArray(data.u.array.mArrayType, &data.u.array.mArrayInterfaceID,
1340  data.u.array.mArrayCount, data.u.array.mArrayValue,
1341  type, iid, count, ptr);
1342  return NS_ERROR_CANNOT_CONVERT_DATA;
1343 }
1344 
1345 /***************************************************************************/
1346 // static setter functions...
1347 
1348 #define DATA_SETTER_PROLOGUE(data_) \
1349  sbVariant::Cleanup(data_);
1350 
1351 #define DATA_SETTER_EPILOGUE(data_, type_) \
1352  data_->mType = nsIDataType :: type_; \
1353  return NS_OK;
1354 
1355 #define DATA_SETTER(data_, type_, member_, value_) \
1356  DATA_SETTER_PROLOGUE(data_) \
1357  data_->u.member_ = value_; \
1358  DATA_SETTER_EPILOGUE(data_, type_)
1359 
1360 #define DATA_SETTER_WITH_CAST(data_, type_, member_, cast_, value_) \
1361  DATA_SETTER_PROLOGUE(data_) \
1362  data_->u.member_ = cast_ value_; \
1363  DATA_SETTER_EPILOGUE(data_, type_)
1364 
1365 
1366 /********************************************/
1367 
1368 #define CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_) \
1369 { \
1370 
1371 #define CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_) \
1372  rv = aValue->GetAs##name_ (&(data->u. member_ ));
1373 
1374 #define CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_) \
1375  rv = aValue->GetAs##name_ ( cast_ &(data->u. member_ ));
1376 
1377 #define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_) \
1378  if(NS_SUCCEEDED(rv)) \
1379 { \
1380  data->mType = nsIDataType :: type_ ; \
1381 } \
1382  break; \
1383 }
1384 
1385 #define CASE__SET_FROM_VARIANT_TYPE(type_, member_, name_) \
1386  case nsIDataType :: type_ : \
1387  CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_) \
1388  CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_) \
1389  CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
1390 
1391 #define CASE__SET_FROM_VARIANT_VTYPE_CAST(type_, cast_, member_, name_) \
1392  case nsIDataType :: type_ : \
1393  CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_) \
1394  CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_) \
1395  CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
1396 
1397 
1398 /* static */ nsresult
1400 {
1401  PRUint16 type;
1402  nsresult rv;
1403 
1404  sbVariant::Cleanup(data);
1405 
1406  rv = aValue->GetDataType(&type);
1407  if(NS_FAILED(rv))
1408  return rv;
1409 
1410  switch(type)
1411  {
1412  CASE__SET_FROM_VARIANT_VTYPE_CAST(VTYPE_INT8, (PRUint8*), mInt8Value,
1413  Int8)
1414  CASE__SET_FROM_VARIANT_TYPE(VTYPE_INT16, mInt16Value, Int16)
1415  CASE__SET_FROM_VARIANT_TYPE(VTYPE_INT32, mInt32Value, Int32)
1416  CASE__SET_FROM_VARIANT_TYPE(VTYPE_UINT8, mUint8Value, Uint8)
1417  CASE__SET_FROM_VARIANT_TYPE(VTYPE_UINT16, mUint16Value, Uint16)
1418  CASE__SET_FROM_VARIANT_TYPE(VTYPE_UINT32, mUint32Value, Uint32)
1419  CASE__SET_FROM_VARIANT_TYPE(VTYPE_FLOAT, mFloatValue, Float)
1420  CASE__SET_FROM_VARIANT_TYPE(VTYPE_DOUBLE, mDoubleValue, Double)
1421  CASE__SET_FROM_VARIANT_TYPE(VTYPE_BOOL , mBoolValue, Bool)
1422  CASE__SET_FROM_VARIANT_TYPE(VTYPE_CHAR, mCharValue, Char)
1423  CASE__SET_FROM_VARIANT_TYPE(VTYPE_WCHAR, mWCharValue, WChar)
1424  CASE__SET_FROM_VARIANT_TYPE(VTYPE_ID, mIDValue, ID)
1425 
1426  case nsIDataType::VTYPE_ASTRING:
1427  case nsIDataType::VTYPE_DOMSTRING:
1428  case nsIDataType::VTYPE_WCHAR_STR:
1429  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
1431  data->u.mAStringValue = new nsString();
1432  if(!data->u.mAStringValue)
1433  return NS_ERROR_OUT_OF_MEMORY;
1434  rv = aValue->GetAsAString(*data->u.mAStringValue);
1435  if(NS_FAILED(rv)) {
1436  nsString *p = static_cast<nsString *>(data->u.mAStringValue);
1437  delete p;
1438  data->u.mAStringValue = nsnull;
1439  }
1441 
1442  case nsIDataType::VTYPE_CSTRING:
1444  data->u.mCStringValue = new nsCString();
1445  if(!data->u.mCStringValue)
1446  return NS_ERROR_OUT_OF_MEMORY;
1447  rv = aValue->GetAsACString(*data->u.mCStringValue);
1448  if(NS_FAILED(rv)) {
1449  nsCString *p = static_cast<nsCString *>(data->u.mCStringValue);
1450  delete p;
1451  data->u.mCStringValue = nsnull;
1452  }
1454 
1455  case nsIDataType::VTYPE_UTF8STRING:
1456  CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_UTF8STRING);
1457  data->u.mUTF8StringValue = new nsUTF8String();
1458  if(!data->u.mUTF8StringValue)
1459  return NS_ERROR_OUT_OF_MEMORY;
1460  rv = aValue->GetAsAUTF8String(*data->u.mUTF8StringValue);
1461  if(NS_FAILED(rv)) {
1462  nsUTF8String *p = static_cast<nsUTF8String *>(data->u.mUTF8StringValue);
1463  delete p;
1464  data->u.mUTF8StringValue = nsnull;
1465  }
1466  CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_UTF8STRING)
1467 
1468  case nsIDataType::VTYPE_CHAR_STR:
1469  case nsIDataType::VTYPE_STRING_SIZE_IS:
1470  CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_STRING_SIZE_IS);
1471  rv = aValue->GetAsStringWithSize(&data->u.str.mStringLength,
1472  &data->u.str.mStringValue);
1473  CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_STRING_SIZE_IS)
1474 
1475  case nsIDataType::VTYPE_INTERFACE:
1476  case nsIDataType::VTYPE_INTERFACE_IS:
1477  CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_INTERFACE_IS);
1478  // XXX This iid handling is ugly!
1479  nsIID* iid;
1480  rv = aValue->GetAsInterface(&iid, (void**)&data->u.iface.mInterfaceValue);
1481  if(NS_SUCCEEDED(rv))
1482  {
1483  data->u.iface.mInterfaceID = *iid;
1484  NS_Free((char*)iid);
1485  }
1486  CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_INTERFACE_IS)
1487 
1488  case nsIDataType::VTYPE_ARRAY:
1490  rv = aValue->GetAsArray(&data->u.array.mArrayType,
1491  &data->u.array.mArrayInterfaceID,
1492  &data->u.array.mArrayCount,
1493  &data->u.array.mArrayValue);
1495 
1496  case nsIDataType::VTYPE_VOID:
1497  rv = sbVariant::SetToVoid(data);
1498  break;
1499  case nsIDataType::VTYPE_EMPTY_ARRAY:
1500  rv = sbVariant::SetToEmptyArray(data);
1501  break;
1502  case nsIDataType::VTYPE_EMPTY:
1503  rv = sbVariant::SetToEmpty(data);
1504  break;
1505  default:
1506  NS_ERROR("bad type in variant!");
1507  rv = NS_ERROR_FAILURE;
1508  break;
1509  }
1510  return rv;
1511 }
1512 
1513 /* static */ nsresult
1515 {
1516  DATA_SETTER_WITH_CAST(data, VTYPE_INT8, mInt8Value, (PRUint8), aValue)
1517 }
1518 /* static */ nsresult
1520 {
1521  DATA_SETTER(data, VTYPE_INT16, mInt16Value, aValue)
1522 }
1523 /* static */ nsresult
1525 {
1526  DATA_SETTER(data, VTYPE_INT32, mInt32Value, aValue)
1527 }
1528 /* static */ nsresult
1530 {
1531  DATA_SETTER(data, VTYPE_INT64, mInt64Value, aValue)
1532 }
1533 /* static */ nsresult
1535 {
1536  DATA_SETTER(data, VTYPE_UINT8, mUint8Value, aValue)
1537 }
1538 /* static */ nsresult
1540 {
1541  DATA_SETTER(data, VTYPE_UINT16, mUint16Value, aValue)
1542 }
1543 /* static */ nsresult
1545 {
1546  DATA_SETTER(data, VTYPE_UINT32, mUint32Value, aValue)
1547 }
1548 /* static */ nsresult
1550 {
1551  DATA_SETTER(data, VTYPE_UINT64, mUint64Value, aValue)
1552 }
1553 /* static */ nsresult
1555 {
1556  DATA_SETTER(data, VTYPE_FLOAT, mFloatValue, aValue)
1557 }
1558 /* static */ nsresult
1560 {
1561  DATA_SETTER(data, VTYPE_DOUBLE, mDoubleValue, aValue)
1562 }
1563 /* static */ nsresult
1565 {
1566  DATA_SETTER(data, VTYPE_BOOL, mBoolValue, aValue)
1567 }
1568 /* static */ nsresult
1570 {
1571  DATA_SETTER(data, VTYPE_CHAR, mCharValue, aValue)
1572 }
1573 /* static */ nsresult
1575 {
1576  DATA_SETTER(data, VTYPE_WCHAR, mWCharValue, aValue)
1577 }
1578 /* static */ nsresult
1580 {
1581  DATA_SETTER(data, VTYPE_ID, mIDValue, aValue)
1582 }
1583 /* static */ nsresult
1585 {
1586  DATA_SETTER_PROLOGUE(data);
1587  if(!(data->u.mAStringValue = new nsString(aValue)))
1588  return NS_ERROR_OUT_OF_MEMORY;
1589  DATA_SETTER_EPILOGUE(data, VTYPE_ASTRING);
1590 }
1591 
1592 /* static */ nsresult
1594  const nsACString & aValue)
1595 {
1596  DATA_SETTER_PROLOGUE(data);
1597  if(!(data->u.mCStringValue = new nsCString(aValue)))
1598  return NS_ERROR_OUT_OF_MEMORY;
1599  DATA_SETTER_EPILOGUE(data, VTYPE_CSTRING);
1600 }
1601 
1602 /* static */ nsresult
1604  const nsAUTF8String & aValue)
1605 {
1606  DATA_SETTER_PROLOGUE(data);
1607  if(!(data->u.mUTF8StringValue = new nsUTF8String(aValue)))
1608  return NS_ERROR_OUT_OF_MEMORY;
1609  DATA_SETTER_EPILOGUE(data, VTYPE_UTF8STRING);
1610 }
1611 
1612 /* static */ nsresult
1614 {
1615  DATA_SETTER_PROLOGUE(data);
1616  if(!aValue)
1617  return NS_ERROR_NULL_POINTER;
1618  return SetFromStringWithSize(data, strlen(aValue), aValue);
1619 }
1620 /* static */ nsresult
1622 {
1623  DATA_SETTER_PROLOGUE(data);
1624  if(!aValue)
1625  return NS_ERROR_NULL_POINTER;
1626  return SetFromWStringWithSize(data, nsCRT::strlen(aValue), aValue);
1627 }
1628 /* static */ nsresult
1630 {
1631  return SetFromInterface(data, NS_GET_IID(nsISupports), aValue);
1632 }
1633 /* static */ nsresult
1636 {
1637  DATA_SETTER_PROLOGUE(data);
1638  NS_IF_ADDREF(aValue);
1639  data->u.iface.mInterfaceValue = aValue;
1640  data->u.iface.mInterfaceID = iid;
1641  DATA_SETTER_EPILOGUE(data, VTYPE_INTERFACE_IS);
1642 }
1643 /* static */ nsresult
1645  const nsIID* iid, PRUint32 count, void * aValue)
1646 {
1647  DATA_SETTER_PROLOGUE(data);
1648  if(!aValue || !count)
1649  return NS_ERROR_NULL_POINTER;
1650 
1651  nsresult rv = CloneArray(type, iid, count, aValue,
1652  &data->u.array.mArrayType,
1653  &data->u.array.mArrayInterfaceID,
1654  &data->u.array.mArrayCount,
1655  &data->u.array.mArrayValue);
1656  if(NS_FAILED(rv))
1657  return rv;
1658  DATA_SETTER_EPILOGUE(data, VTYPE_ARRAY);
1659 }
1660 /* static */ nsresult
1662 {
1663  DATA_SETTER_PROLOGUE(data);
1664  if(!aValue)
1665  return NS_ERROR_NULL_POINTER;
1666  if(!(data->u.str.mStringValue =
1667  (char*) SB_CloneMemory(aValue, (size+1)*sizeof(char))))
1668  return NS_ERROR_OUT_OF_MEMORY;
1669  data->u.str.mStringLength = size;
1670  DATA_SETTER_EPILOGUE(data, VTYPE_STRING_SIZE_IS);
1671 }
1672 /* static */ nsresult
1674 {
1675  DATA_SETTER_PROLOGUE(data);
1676  if(!aValue)
1677  return NS_ERROR_NULL_POINTER;
1678  if(!(data->u.wstr.mWStringValue =
1679  (PRUnichar*) SB_CloneMemory(aValue, (size+1)*sizeof(PRUnichar))))
1680  return NS_ERROR_OUT_OF_MEMORY;
1681  data->u.wstr.mWStringLength = size;
1682  DATA_SETTER_EPILOGUE(data, VTYPE_WSTRING_SIZE_IS);
1683 }
1684 /* static */ nsresult
1686 {
1687  DATA_SETTER_PROLOGUE(data);
1688  DATA_SETTER_EPILOGUE(data, VTYPE_VOID);
1689 }
1690 /* static */ nsresult
1692 {
1693  DATA_SETTER_PROLOGUE(data);
1694  DATA_SETTER_EPILOGUE(data, VTYPE_EMPTY);
1695 }
1696 /* static */ nsresult
1698 {
1699  DATA_SETTER_PROLOGUE(data);
1700  DATA_SETTER_EPILOGUE(data, VTYPE_EMPTY_ARRAY);
1701 }
1702 
1703 /***************************************************************************/
1704 
1705 /* static */ nsresult
1707 {
1708  data->mType = nsIDataType::VTYPE_EMPTY;
1709  return NS_OK;
1710 }
1711 
1712 /* static */ nsresult
1714 {
1715  switch(data->mType)
1716  {
1717  case nsIDataType::VTYPE_INT8:
1718  case nsIDataType::VTYPE_INT16:
1719  case nsIDataType::VTYPE_INT32:
1720  case nsIDataType::VTYPE_INT64:
1721  case nsIDataType::VTYPE_UINT8:
1722  case nsIDataType::VTYPE_UINT16:
1723  case nsIDataType::VTYPE_UINT32:
1724  case nsIDataType::VTYPE_UINT64:
1725  case nsIDataType::VTYPE_FLOAT:
1726  case nsIDataType::VTYPE_DOUBLE:
1727  case nsIDataType::VTYPE_BOOL:
1728  case nsIDataType::VTYPE_CHAR:
1729  case nsIDataType::VTYPE_WCHAR:
1730  case nsIDataType::VTYPE_VOID:
1731  case nsIDataType::VTYPE_ID:
1732  break;
1733  case nsIDataType::VTYPE_ASTRING:
1734  case nsIDataType::VTYPE_DOMSTRING:
1735  {
1736  nsString *p = static_cast<nsString *>(data->u.mAStringValue);
1737  delete p;
1738  data->u.mAStringValue = nsnull;
1739  }
1740  break;
1741  case nsIDataType::VTYPE_CSTRING:
1742  {
1743  nsCString *p = static_cast<nsCString *>(data->u.mCStringValue);
1744  delete p;
1745  data->u.mCStringValue = nsnull;
1746  }
1747  break;
1748  case nsIDataType::VTYPE_UTF8STRING:
1749  {
1750  nsUTF8String *p = static_cast<nsUTF8String *>(data->u.mUTF8StringValue);
1751  delete p;
1752  data->u.mUTF8StringValue= nsnull;
1753  }
1754  break;
1755  case nsIDataType::VTYPE_CHAR_STR:
1756  case nsIDataType::VTYPE_STRING_SIZE_IS:
1757  NS_Free((char*)data->u.str.mStringValue);
1758  break;
1759  case nsIDataType::VTYPE_WCHAR_STR:
1760  case nsIDataType::VTYPE_WSTRING_SIZE_IS:
1761  NS_Free((char*)data->u.wstr.mWStringValue);
1762  break;
1763  case nsIDataType::VTYPE_INTERFACE:
1764  case nsIDataType::VTYPE_INTERFACE_IS:
1765  NS_IF_RELEASE(data->u.iface.mInterfaceValue);
1766  break;
1767  case nsIDataType::VTYPE_ARRAY:
1768  FreeArray(data);
1769  break;
1770  case nsIDataType::VTYPE_EMPTY_ARRAY:
1771  case nsIDataType::VTYPE_EMPTY:
1772  break;
1773  default:
1774  NS_ERROR("bad type in variant!");
1775  break;
1776  }
1777 
1778  data->mType = nsIDataType::VTYPE_EMPTY;
1779  return NS_OK;
1780 }
1781 
1782 /***************************************************************************/
1783 /***************************************************************************/
1784 // members...
1785 
1787  nsIVariant,
1788  nsIWritableVariant)
1789 
1791 : mDataLock(nsnull)
1792 , mWritable(PR_TRUE)
1793 {
1794  sbVariant::Initialize(&mData);
1795  mDataLock = nsAutoLock::NewLock("sbVariant::mLock");
1796  NS_WARN_IF_FALSE(mDataLock, "Failed to create data lock.");
1797 
1798 #ifdef DEBUG
1799  {
1800  // Assert that the nsIDataType consts match the values #defined in
1801  // xpt_struct.h. Bad things happen somewhere if they don't.
1802  struct THE_TYPES {PRUint16 a; PRUint16 b;};
1803  static const THE_TYPES array[] = {
1804  {nsIDataType::VTYPE_INT8 , TD_INT8 },
1805  {nsIDataType::VTYPE_INT16 , TD_INT16 },
1806  {nsIDataType::VTYPE_INT32 , TD_INT32 },
1807  {nsIDataType::VTYPE_INT64 , TD_INT64 },
1808  {nsIDataType::VTYPE_UINT8 , TD_UINT8 },
1809  {nsIDataType::VTYPE_UINT16 , TD_UINT16 },
1810  {nsIDataType::VTYPE_UINT32 , TD_UINT32 },
1811  {nsIDataType::VTYPE_UINT64 , TD_UINT64 },
1812  {nsIDataType::VTYPE_FLOAT , TD_FLOAT },
1813  {nsIDataType::VTYPE_DOUBLE , TD_DOUBLE },
1814  {nsIDataType::VTYPE_BOOL , TD_BOOL },
1815  {nsIDataType::VTYPE_CHAR , TD_CHAR },
1816  {nsIDataType::VTYPE_WCHAR , TD_WCHAR },
1817  {nsIDataType::VTYPE_VOID , TD_VOID },
1818  {nsIDataType::VTYPE_ID , TD_PNSIID },
1819  {nsIDataType::VTYPE_DOMSTRING , TD_DOMSTRING },
1820  {nsIDataType::VTYPE_CHAR_STR , TD_PSTRING },
1821  {nsIDataType::VTYPE_WCHAR_STR , TD_PWSTRING },
1822  {nsIDataType::VTYPE_INTERFACE , TD_INTERFACE_TYPE },
1823  {nsIDataType::VTYPE_INTERFACE_IS , TD_INTERFACE_IS_TYPE},
1824  {nsIDataType::VTYPE_ARRAY , TD_ARRAY },
1825  {nsIDataType::VTYPE_STRING_SIZE_IS , TD_PSTRING_SIZE_IS },
1826  {nsIDataType::VTYPE_WSTRING_SIZE_IS , TD_PWSTRING_SIZE_IS },
1827  {nsIDataType::VTYPE_UTF8STRING , TD_UTF8STRING },
1828  {nsIDataType::VTYPE_CSTRING , TD_CSTRING },
1829  {nsIDataType::VTYPE_ASTRING , TD_ASTRING }
1830  };
1831  static const int length = sizeof(array)/sizeof(array[0]);
1832  static PRBool inited = PR_FALSE;
1833  if(!inited)
1834  {
1835  for(int i = 0; i < length; i++)
1836  NS_ASSERTION(array[i].a == array[i].b, "bad const declaration");
1837  inited = PR_TRUE;
1838  }
1839  }
1840 #endif
1841 }
1842 
1843 sbVariant::~sbVariant()
1844 {
1846  if(mDataLock) {
1847  nsAutoLock::DestroyLock(mDataLock);
1848  }
1849 }
1850 
1851 // For all the data getters we just forward to the static (and sharable)
1852 // 'ConvertTo' functions.
1853 
1854 /* readonly attribute PRUint16 dataType; */
1855 NS_IMETHODIMP sbVariant::GetDataType(PRUint16 *aDataType)
1856 {
1857  nsAutoLock lock(mDataLock);
1858  *aDataType = mData.mType;
1859  return NS_OK;
1860 }
1861 
1862 /* PRUint8 getAsInt8 (); */
1863 NS_IMETHODIMP sbVariant::GetAsInt8(PRUint8 *_retval)
1864 {
1865  nsAutoLock lock(mDataLock);
1866  return sbVariant::ConvertToInt8(mData, _retval);
1867 }
1868 
1869 /* PRInt16 getAsInt16 (); */
1870 NS_IMETHODIMP sbVariant::GetAsInt16(PRInt16 *_retval)
1871 {
1872  nsAutoLock lock(mDataLock);
1873  return sbVariant::ConvertToInt16(mData, _retval);
1874 }
1875 
1876 /* PRInt32 getAsInt32 (); */
1877 NS_IMETHODIMP sbVariant::GetAsInt32(PRInt32 *_retval)
1878 {
1879  nsAutoLock lock(mDataLock);
1880  return sbVariant::ConvertToInt32(mData, _retval);
1881 }
1882 
1883 /* PRInt64 getAsInt64 (); */
1884 NS_IMETHODIMP sbVariant::GetAsInt64(PRInt64 *_retval)
1885 {
1886  nsAutoLock lock(mDataLock);
1887  return sbVariant::ConvertToInt64(mData, _retval);
1888 }
1889 
1890 /* PRUint8 getAsUint8 (); */
1891 NS_IMETHODIMP sbVariant::GetAsUint8(PRUint8 *_retval)
1892 {
1893  nsAutoLock lock(mDataLock);
1894  return sbVariant::ConvertToUint8(mData, _retval);
1895 }
1896 
1897 /* PRUint16 getAsUint16 (); */
1898 NS_IMETHODIMP sbVariant::GetAsUint16(PRUint16 *_retval)
1899 {
1900  nsAutoLock lock(mDataLock);
1901  return sbVariant::ConvertToUint16(mData, _retval);
1902 }
1903 
1904 /* PRUint32 getAsUint32 (); */
1905 NS_IMETHODIMP sbVariant::GetAsUint32(PRUint32 *_retval)
1906 {
1907  nsAutoLock lock(mDataLock);
1908  return sbVariant::ConvertToUint32(mData, _retval);
1909 }
1910 
1911 /* PRUint64 getAsUint64 (); */
1912 NS_IMETHODIMP sbVariant::GetAsUint64(PRUint64 *_retval)
1913 {
1914  nsAutoLock lock(mDataLock);
1915  return sbVariant::ConvertToUint64(mData, _retval);
1916 }
1917 
1918 /* float getAsFloat (); */
1919 NS_IMETHODIMP sbVariant::GetAsFloat(float *_retval)
1920 {
1921  nsAutoLock lock(mDataLock);
1922  return sbVariant::ConvertToFloat(mData, _retval);
1923 }
1924 
1925 /* double getAsDouble (); */
1926 NS_IMETHODIMP sbVariant::GetAsDouble(double *_retval)
1927 {
1928  nsAutoLock lock(mDataLock);
1929  return sbVariant::ConvertToDouble(mData, _retval);
1930 }
1931 
1932 /* PRBool getAsBool (); */
1933 NS_IMETHODIMP sbVariant::GetAsBool(PRBool *_retval)
1934 {
1935  nsAutoLock lock(mDataLock);
1936  return sbVariant::ConvertToBool(mData, _retval);
1937 }
1938 
1939 /* char getAsChar (); */
1940 NS_IMETHODIMP sbVariant::GetAsChar(char *_retval)
1941 {
1942  nsAutoLock lock(mDataLock);
1943  return sbVariant::ConvertToChar(mData, _retval);
1944 }
1945 
1946 /* wchar getAsWChar (); */
1947 NS_IMETHODIMP sbVariant::GetAsWChar(PRUnichar *_retval)
1948 {
1949  nsAutoLock lock(mDataLock);
1950  return sbVariant::ConvertToWChar(mData, _retval);
1951 }
1952 
1953 /* [notxpcom] nsresult getAsID (out nsID retval); */
1954 NS_IMETHODIMP_(nsresult) sbVariant::GetAsID(nsID *retval)
1955 {
1956  nsAutoLock lock(mDataLock);
1957  return sbVariant::ConvertToID(mData, retval);
1958 }
1959 
1960 /* AString getAsAString (); */
1961 NS_IMETHODIMP sbVariant::GetAsAString(nsAString & _retval)
1962 {
1963  nsAutoLock lock(mDataLock);
1964  return sbVariant::ConvertToAString(mData, _retval);
1965 }
1966 
1967 /* DOMString getAsDOMString (); */
1968 NS_IMETHODIMP sbVariant::GetAsDOMString(nsAString & _retval)
1969 {
1970  nsAutoLock lock(mDataLock);
1971 
1972  // A DOMString maps to an AString internally, so we can re-use
1973  // ConvertToAString here.
1974  return sbVariant::ConvertToAString(mData, _retval);
1975 }
1976 
1977 /* ACString getAsACString (); */
1978 NS_IMETHODIMP sbVariant::GetAsACString(nsACString & _retval)
1979 {
1980  nsAutoLock lock(mDataLock);
1981  return sbVariant::ConvertToACString(mData, _retval);
1982 }
1983 
1984 /* AUTF8String getAsAUTF8String (); */
1985 NS_IMETHODIMP sbVariant::GetAsAUTF8String(nsAUTF8String & _retval)
1986 {
1987  nsAutoLock lock(mDataLock);
1988  return sbVariant::ConvertToAUTF8String(mData, _retval);
1989 }
1990 
1991 /* string getAsString (); */
1992 NS_IMETHODIMP sbVariant::GetAsString(char **_retval)
1993 {
1994  nsAutoLock lock(mDataLock);
1995  return sbVariant::ConvertToString(mData, _retval);
1996 }
1997 
1998 /* wstring getAsWString (); */
1999 NS_IMETHODIMP sbVariant::GetAsWString(PRUnichar **_retval)
2000 {
2001  nsAutoLock lock(mDataLock);
2002  return sbVariant::ConvertToWString(mData, _retval);
2003 }
2004 
2005 /* nsISupports getAsISupports (); */
2006 NS_IMETHODIMP sbVariant::GetAsISupports(nsISupports **_retval)
2007 {
2008  nsAutoLock lock(mDataLock);
2009  return sbVariant::ConvertToISupports(mData, _retval);
2010 }
2011 
2012 /* void getAsInterface (out nsIIDPtr iid, [iid_is (iid), retval] out nsQIResult iface); */
2013 NS_IMETHODIMP sbVariant::GetAsInterface(nsIID * *iid, void * *iface)
2014 {
2015  nsAutoLock lock(mDataLock);
2016  return sbVariant::ConvertToInterface(mData, iid, iface);
2017 }
2018 
2019 /* [notxpcom] nsresult getAsArray (out PRUint16 type, out nsIID iid, out PRUint32 count, out voidPtr ptr); */
2020 NS_IMETHODIMP_(nsresult) sbVariant::GetAsArray(PRUint16 *type, nsIID *iid, PRUint32 *count, void * *ptr)
2021 {
2022  nsAutoLock lock(mDataLock);
2023  return sbVariant::ConvertToArray(mData, type, iid, count, ptr);
2024 }
2025 
2026 /* void getAsStringWithSize (out PRUint32 size, [size_is (size), retval] out string str); */
2027 NS_IMETHODIMP sbVariant::GetAsStringWithSize(PRUint32 *size, char **str)
2028 {
2029  nsAutoLock lock(mDataLock);
2030  return sbVariant::ConvertToStringWithSize(mData, size, str);
2031 }
2032 
2033 /* void getAsWStringWithSize (out PRUint32 size, [size_is (size), retval] out wstring str); */
2034 NS_IMETHODIMP sbVariant::GetAsWStringWithSize(PRUint32 *size, PRUnichar **str)
2035 {
2036  nsAutoLock lock(mDataLock);
2037  return sbVariant::ConvertToWStringWithSize(mData, size, str);
2038 }
2039 
2040 /***************************************************************************/
2041 
2042 /* attribute PRBool writable; */
2043 NS_IMETHODIMP sbVariant::GetWritable(PRBool *aWritable)
2044 {
2045  nsAutoLock lock(mDataLock);
2046  *aWritable = mWritable;
2047  return NS_OK;
2048 }
2049 NS_IMETHODIMP sbVariant::SetWritable(PRBool aWritable)
2050 {
2051  nsAutoLock lock(mDataLock);
2052  if(!mWritable && aWritable)
2053  return NS_ERROR_FAILURE;
2054  mWritable = aWritable;
2055  return NS_OK;
2056 }
2057 
2058 /***************************************************************************/
2059 
2060 // For all the data setters we just forward to the static (and sharable)
2061 // 'SetFrom' functions.
2062 
2063 /* void setAsInt8 (in PRUint8 aValue); */
2064 NS_IMETHODIMP sbVariant::SetAsInt8(PRUint8 aValue)
2065 {
2066  nsAutoLock lock(mDataLock);
2067  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2068  return sbVariant::SetFromInt8(&mData, aValue);
2069 }
2070 
2071 /* void setAsInt16 (in PRInt16 aValue); */
2072 NS_IMETHODIMP sbVariant::SetAsInt16(PRInt16 aValue)
2073 {
2074  nsAutoLock lock(mDataLock);
2075  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2076  return sbVariant::SetFromInt16(&mData, aValue);
2077 }
2078 
2079 /* void setAsInt32 (in PRInt32 aValue); */
2080 NS_IMETHODIMP sbVariant::SetAsInt32(PRInt32 aValue)
2081 {
2082  nsAutoLock lock(mDataLock);
2083  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2084  return sbVariant::SetFromInt32(&mData, aValue);
2085 }
2086 
2087 /* void setAsInt64 (in PRInt64 aValue); */
2088 NS_IMETHODIMP sbVariant::SetAsInt64(PRInt64 aValue)
2089 {
2090  nsAutoLock lock(mDataLock);
2091  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2092  return sbVariant::SetFromInt64(&mData, aValue);
2093 }
2094 
2095 /* void setAsUint8 (in PRUint8 aValue); */
2096 NS_IMETHODIMP sbVariant::SetAsUint8(PRUint8 aValue)
2097 {
2098  nsAutoLock lock(mDataLock);
2099  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2100  return sbVariant::SetFromUint8(&mData, aValue);
2101 }
2102 
2103 /* void setAsUint16 (in PRUint16 aValue); */
2104 NS_IMETHODIMP sbVariant::SetAsUint16(PRUint16 aValue)
2105 {
2106  nsAutoLock lock(mDataLock);
2107  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2108  return sbVariant::SetFromUint16(&mData, aValue);
2109 }
2110 
2111 /* void setAsUint32 (in PRUint32 aValue); */
2112 NS_IMETHODIMP sbVariant::SetAsUint32(PRUint32 aValue)
2113 {
2114  nsAutoLock lock(mDataLock);
2115  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2116  return sbVariant::SetFromUint32(&mData, aValue);
2117 }
2118 
2119 /* void setAsUint64 (in PRUint64 aValue); */
2120 NS_IMETHODIMP sbVariant::SetAsUint64(PRUint64 aValue)
2121 {
2122  nsAutoLock lock(mDataLock);
2123  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2124  return sbVariant::SetFromUint64(&mData, aValue);
2125 }
2126 
2127 /* void setAsFloat (in float aValue); */
2128 NS_IMETHODIMP sbVariant::SetAsFloat(float aValue)
2129 {
2130  nsAutoLock lock(mDataLock);
2131  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2132  return sbVariant::SetFromFloat(&mData, aValue);
2133 }
2134 
2135 /* void setAsDouble (in double aValue); */
2136 NS_IMETHODIMP sbVariant::SetAsDouble(double aValue)
2137 {
2138  nsAutoLock lock(mDataLock);
2139  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2140  return sbVariant::SetFromDouble(&mData, aValue);
2141 }
2142 
2143 /* void setAsBool (in PRBool aValue); */
2144 NS_IMETHODIMP sbVariant::SetAsBool(PRBool aValue)
2145 {
2146  nsAutoLock lock(mDataLock);
2147  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2148  return sbVariant::SetFromBool(&mData, aValue);
2149 }
2150 
2151 /* void setAsChar (in char aValue); */
2152 NS_IMETHODIMP sbVariant::SetAsChar(char aValue)
2153 {
2154  nsAutoLock lock(mDataLock);
2155  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2156  return sbVariant::SetFromChar(&mData, aValue);
2157 }
2158 
2159 /* void setAsWChar (in wchar aValue); */
2160 NS_IMETHODIMP sbVariant::SetAsWChar(PRUnichar aValue)
2161 {
2162  nsAutoLock lock(mDataLock);
2163  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2164  return sbVariant::SetFromWChar(&mData, aValue);
2165 }
2166 
2167 /* void setAsID (in nsIDRef aValue); */
2168 NS_IMETHODIMP sbVariant::SetAsID(const nsID & aValue)
2169 {
2170  nsAutoLock lock(mDataLock);
2171  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2172  return sbVariant::SetFromID(&mData, aValue);
2173 }
2174 
2175 /* void setAsAString (in AString aValue); */
2176 NS_IMETHODIMP sbVariant::SetAsAString(const nsAString & aValue)
2177 {
2178  nsAutoLock lock(mDataLock);
2179  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2180  return sbVariant::SetFromAString(&mData, aValue);
2181 }
2182 
2183 /* void setAsDOMString (in DOMString aValue); */
2184 NS_IMETHODIMP sbVariant::SetAsDOMString(const nsAString & aValue)
2185 {
2186  nsAutoLock lock(mDataLock);
2187  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2188 
2190  if(!(mData.u.mAStringValue = new nsString(aValue)))
2191  return NS_ERROR_OUT_OF_MEMORY;
2192  DATA_SETTER_EPILOGUE((&mData), VTYPE_DOMSTRING);
2193 }
2194 
2195 /* void setAsACString (in ACString aValue); */
2196 NS_IMETHODIMP sbVariant::SetAsACString(const nsACString & aValue)
2197 {
2198  nsAutoLock lock(mDataLock);
2199  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2200  return sbVariant::SetFromACString(&mData, aValue);
2201 }
2202 
2203 /* void setAsAUTF8String (in AUTF8String aValue); */
2204 NS_IMETHODIMP sbVariant::SetAsAUTF8String(const nsAUTF8String & aValue)
2205 {
2206  nsAutoLock lock(mDataLock);
2207  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2208  return sbVariant::SetFromAUTF8String(&mData, aValue);
2209 }
2210 
2211 /* void setAsString (in string aValue); */
2212 NS_IMETHODIMP sbVariant::SetAsString(const char *aValue)
2213 {
2214  nsAutoLock lock(mDataLock);
2215  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2216  return sbVariant::SetFromString(&mData, aValue);
2217 }
2218 
2219 /* void setAsWString (in wstring aValue); */
2220 NS_IMETHODIMP sbVariant::SetAsWString(const PRUnichar *aValue)
2221 {
2222  nsAutoLock lock(mDataLock);
2223  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2224  return sbVariant::SetFromWString(&mData, aValue);
2225 }
2226 
2227 /* void setAsISupports (in nsISupports aValue); */
2228 NS_IMETHODIMP sbVariant::SetAsISupports(nsISupports *aValue)
2229 {
2230  nsAutoLock lock(mDataLock);
2231  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2232  return sbVariant::SetFromISupports(&mData, aValue);
2233 }
2234 
2235 /* void setAsInterface (in nsIIDRef iid, [iid_is (iid)] in nsQIResult iface); */
2236 NS_IMETHODIMP sbVariant::SetAsInterface(const nsIID & iid, void * iface)
2237 {
2238  nsAutoLock lock(mDataLock);
2239  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2240  return sbVariant::SetFromInterface(&mData, iid, (nsISupports*)iface);
2241 }
2242 
2243 /* [noscript] void setAsArray (in PRUint16 type, in nsIIDPtr iid, in PRUint32 count, in voidPtr ptr); */
2244 NS_IMETHODIMP sbVariant::SetAsArray(PRUint16 type, const nsIID * iid, PRUint32 count, void * ptr)
2245 {
2246  nsAutoLock lock(mDataLock);
2247  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2248  return sbVariant::SetFromArray(&mData, type, iid, count, ptr);
2249 }
2250 
2251 /* void setAsStringWithSize (in PRUint32 size, [size_is (size)] in string str); */
2252 NS_IMETHODIMP sbVariant::SetAsStringWithSize(PRUint32 size, const char *str)
2253 {
2254  nsAutoLock lock(mDataLock);
2255  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2256  return sbVariant::SetFromStringWithSize(&mData, size, str);
2257 }
2258 
2259 /* void setAsWStringWithSize (in PRUint32 size, [size_is (size)] in wstring str); */
2260 NS_IMETHODIMP sbVariant::SetAsWStringWithSize(PRUint32 size, const PRUnichar *str)
2261 {
2262  nsAutoLock lock(mDataLock);
2263  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2264  return sbVariant::SetFromWStringWithSize(&mData, size, str);
2265 }
2266 
2267 /* void setAsVoid (); */
2268 NS_IMETHODIMP sbVariant::SetAsVoid()
2269 {
2270  nsAutoLock lock(mDataLock);
2271  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2272  return sbVariant::SetToVoid(&mData);
2273 }
2274 
2275 /* void setAsEmpty (); */
2276 NS_IMETHODIMP sbVariant::SetAsEmpty()
2277 {
2278  nsAutoLock lock(mDataLock);
2279  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2280  return sbVariant::SetToEmpty(&mData);
2281 }
2282 
2283 /* void setAsEmptyArray (); */
2284 NS_IMETHODIMP sbVariant::SetAsEmptyArray()
2285 {
2286  nsAutoLock lock(mDataLock);
2287  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2289 }
2290 
2291 /* void setFromVariant (in nsIVariant aValue); */
2292 NS_IMETHODIMP sbVariant::SetFromVariant(nsIVariant *aValue)
2293 {
2294  nsAutoLock lock(mDataLock);
2295  if(!mWritable) return NS_ERROR_OBJECT_IS_IMMUTABLE;
2296  return sbVariant::SetFromVariant(&mData, aValue);
2297 }
static nsresult ACString2Double(const nsACString &aString, double *retval)
Definition: sbVariant.cpp:164
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
void * SB_CloneMemory(const void *ptr, PRSize size)
Clone a block of contiguous memory.
#define CASE__NUMBER_INT32(type_, member_)
static nsresult ConvertToString(nsDiscriminatedUnion &data, char **_retval)
Definition: sbVariant.cpp:1114
static nsresult ConvertToFloat(const nsDiscriminatedUnion &data, float *_retval)
Definition: sbVariant.cpp:695
return NS_OK
static nsresult SetFromWStringWithSize(nsDiscriminatedUnion *data, PRUint32 size, const PRUnichar *aValue)
Definition: sbVariant.cpp:1673
#define CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(Ctype_)
Definition: sbVariant.cpp:615
static nsresult SetFromUint32(nsDiscriminatedUnion *data, PRUint32 aValue)
Definition: sbVariant.cpp:1544
#define CASE__SET_FROM_VARIANT_VTYPE_CAST(type_, cast_, member_, name_)
Definition: sbVariant.cpp:1391
#define CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(Ctype_)
Definition: sbVariant.cpp:600
struct nsDiscriminatedUnion::@10::@11 iface
PRUint32 mUint32Value
Definition: sbVariant.h:61
nsDiscriminatedUnion mData
Definition: sbVariant.h:183
menuItem id
Definition: FeedWriter.js:971
static nsresult AString2Double(const nsAString &aString, double *retval)
Definition: sbVariant.cpp:149
onPageChanged aValue
Definition: FeedWriter.js:1395
#define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
Definition: sbVariant.cpp:1377
#define CASE__APPENDDOUBLE_NUMBER(type_, member_)
inArray array
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
#define DATA_SETTER(data_, type_, member_, value_)
Definition: sbVariant.cpp:1355
#define CASE__FREE_ARRAY_PTR(type_, ctype_)
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 void Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)
Definition: sbVariant.cpp:53
static nsresult SetFromISupports(nsDiscriminatedUnion *data, nsISupports *aValue)
Definition: sbVariant.cpp:1629
static nsresult ConvertToWString(const nsDiscriminatedUnion &data, PRUnichar **_retval)
Definition: sbVariant.cpp:1121
#define CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(Ctype_)
Definition: sbVariant.cpp:630
static nsresult SetFromChar(nsDiscriminatedUnion *data, char aValue)
Definition: sbVariant.cpp:1569
#define CASE__FREE_ARRAY_IFACE(type_, ctype_)
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
static nsresult ToManageableNumber(const nsDiscriminatedUnion &inData, nsDiscriminatedUnion *outData)
Definition: sbVariant.cpp:171
#define nsAUTF8String
Definition: sbVariant.h:42
sbOSDControlService prototype QueryInterface
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
static nsresult ToString(const nsDiscriminatedUnion &data, nsACString &outString)
Definition: sbVariant.cpp:861
#define CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_)
Definition: sbVariant.cpp:1368
#define DATA_SETTER_WITH_CAST(data_, type_, member_, cast_, value_)
Definition: sbVariant.cpp:1360
#define DATA_SETTER_PROLOGUE(data_)
Definition: sbVariant.cpp:1348
static nsresult SetFromUint16(nsDiscriminatedUnion *data, PRUint16 aValue)
Definition: sbVariant.cpp:1539
#define CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_)
Definition: sbVariant.cpp:605
static nsresult String2Double(const char *aString, double *retval)
Definition: sbVariant.cpp:139
PRBool mWritable
Definition: sbVariant.h:186
#define CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_)
Definition: sbVariant.cpp:620
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
#define NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_)
Definition: sbVariant.cpp:581
static nsresult SetFromAString(nsDiscriminatedUnion *data, const nsAString &aValue)
Definition: sbVariant.cpp:1584
function num(elem, prop)
static nsresult ConvertToISupports(const nsDiscriminatedUnion &data, nsISupports **_retval)
Definition: sbVariant.cpp:1281
static nsresult ConvertToACString(const nsDiscriminatedUnion &data, nsACString &_retval)
Definition: sbVariant.cpp:1009
this _dialogInput val(dateText)
nsAString * mAStringValue
Definition: sbVariant.h:69
static nsresult ConvertToInt16(const nsDiscriminatedUnion &data, PRInt16 *_retval)
Definition: sbVariant.cpp:677
unique done
static nsresult SetFromUint8(nsDiscriminatedUnion *data, PRUint8 aValue)
Definition: sbVariant.cpp:1534
#define NUMERIC_CONVERSION_METHOD_END
Definition: sbVariant.cpp:661
#define TRIVIAL_DATA_CONVERTER(type_, data_, member_, retval_)
Definition: sbVariant.cpp:575
nsACString * mCStringValue
Definition: sbVariant.h:71
NS_IMETHODIMP_(nsresult) sbVariant
Definition: sbVariant.cpp:1954
union nsDiscriminatedUnion::@10 u
struct nsDiscriminatedUnion::@10::@14 wstr
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
#define PromiseFlatUTF8String
Definition: sbVariant.h:44
static nsresult SetFromString(nsDiscriminatedUnion *data, const char *aValue)
Definition: sbVariant.cpp:1613
static nsresult ConvertToUint16(const nsDiscriminatedUnion &data, PRUint16 *_retval)
Definition: sbVariant.cpp:686
static nsresult Cleanup(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:1713
#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_)
Definition: sbVariant.cpp:645
static nsresult ConvertToInt32(const nsDiscriminatedUnion &data, PRInt32 *_retval)
Definition: sbVariant.cpp:679
static nsresult SetFromACString(nsDiscriminatedUnion *data, const nsACString &aValue)
Definition: sbVariant.cpp:1593
countRef value
Definition: FeedWriter.js:1423
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
#define CASE__APPENDFLOAT_NUMBER(type_, member_)
static nsresult ConvertToBool(const nsDiscriminatedUnion &data, PRBool *_retval)
Definition: sbVariant.cpp:739
static nsresult ConvertToUint64(const nsDiscriminatedUnion &data, PRUint64 *_retval)
Definition: sbVariant.cpp:783
#define DATA_SETTER_EPILOGUE(data_, type_)
Definition: sbVariant.cpp:1351
static void FreeArray(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:275
static nsresult SetFromUint64(nsDiscriminatedUnion *data, PRUint64 aValue)
Definition: sbVariant.cpp:1549
static nsresult SetFromDouble(nsDiscriminatedUnion *data, double aValue)
Definition: sbVariant.cpp:1559
#define nsUTF8String
Definition: sbVariant.h:43
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
static PRBool String2ID(const nsDiscriminatedUnion &data, nsID *pid)
Definition: sbVariant.cpp:790
static nsresult CloneArray(PRUint16 inType, const nsIID *inIID, PRUint32 inCount, void *inValue, PRUint16 *outType, nsIID *outIID, PRUint32 *outCount, void **outValue)
Definition: sbVariant.cpp:348
#define NUMERIC_CONVERSION_METHOD_NORMAL(type_, Ctype_, name_, min_, max_)
Definition: sbVariant.cpp:668
static nsresult ConvertToAUTF8String(const nsDiscriminatedUnion &data, nsACString &_retval)
Definition: sbVariant.cpp:1054
#define CASE__SMPRINTF_NUMBER(type_, format_, cast_, member_)
observe data
Definition: FeedWriter.js:1329
_getSelectedPageStyle s i
#define CASE__SET_FROM_VARIANT_TYPE(type_, member_, name_)
Definition: sbVariant.cpp:1385
NS_IMPL_THREADSAFE_ISUPPORTS2(sbVariant, nsIVariant, nsIWritableVariant) sbVariant
Definition: sbVariant.cpp:1786
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 AUTF8String2Double(const nsACString &aString, double *retval)
Definition: sbVariant.cpp:159
function next()
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