1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Dan Rosen <dr@netscape.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "nsSupportsPrimitives.h"
40 : #include "nsCRT.h"
41 : #include "nsMemory.h"
42 : #include "prprf.h"
43 : #include "nsIInterfaceInfoManager.h"
44 : #include "nsDependentString.h"
45 : #include "nsReadableUtils.h"
46 : #include "nsPromiseFlatString.h"
47 :
48 : /***************************************************************************/
49 :
50 0 : NS_IMPL_ISUPPORTS2(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive)
51 :
52 0 : nsSupportsIDImpl::nsSupportsIDImpl()
53 0 : : mData(nsnull)
54 : {
55 0 : }
56 :
57 0 : NS_IMETHODIMP nsSupportsIDImpl::GetType(PRUint16 *aType)
58 : {
59 0 : NS_ASSERTION(aType, "Bad pointer");
60 0 : *aType = TYPE_ID;
61 :
62 0 : return NS_OK;
63 : }
64 :
65 0 : NS_IMETHODIMP nsSupportsIDImpl::GetData(nsID **aData)
66 : {
67 0 : NS_ASSERTION(aData, "Bad pointer");
68 0 : if(mData)
69 : {
70 0 : *aData = (nsID*) nsMemory::Clone(mData, sizeof(nsID));
71 0 : return *aData ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
72 : }
73 0 : *aData = nsnull;
74 0 : return NS_OK;
75 : }
76 :
77 0 : NS_IMETHODIMP nsSupportsIDImpl::SetData(const nsID *aData)
78 : {
79 0 : if(mData)
80 0 : nsMemory::Free(mData);
81 0 : if(aData)
82 0 : mData = (nsID*) nsMemory::Clone(aData, sizeof(nsID));
83 : else
84 0 : mData = nsnull;
85 0 : return NS_OK;
86 : }
87 :
88 0 : NS_IMETHODIMP nsSupportsIDImpl::ToString(char **_retval)
89 : {
90 : char* result;
91 0 : NS_ASSERTION(_retval, "Bad pointer");
92 0 : if(mData)
93 : {
94 0 : result = mData->ToString();
95 : }
96 : else
97 : {
98 : static const char nullStr[] = "null";
99 0 : result = (char*) nsMemory::Clone(nullStr, sizeof(nullStr));
100 : }
101 :
102 0 : *_retval = result;
103 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
104 : }
105 :
106 : /*****************************************************************************
107 : * nsSupportsCStringImpl
108 : *****************************************************************************/
109 :
110 2683 : NS_IMPL_ISUPPORTS2(nsSupportsCStringImpl, nsISupportsCString,
111 : nsISupportsPrimitive)
112 :
113 0 : NS_IMETHODIMP nsSupportsCStringImpl::GetType(PRUint16 *aType)
114 : {
115 0 : NS_ASSERTION(aType, "Bad pointer");
116 :
117 0 : *aType = TYPE_CSTRING;
118 0 : return NS_OK;
119 : }
120 :
121 10 : NS_IMETHODIMP nsSupportsCStringImpl::GetData(nsACString& aData)
122 : {
123 10 : aData = mData;
124 10 : return NS_OK;
125 : }
126 :
127 0 : NS_IMETHODIMP nsSupportsCStringImpl::ToString(char **_retval)
128 : {
129 0 : *_retval = ToNewCString(mData);
130 :
131 0 : if (!*_retval)
132 0 : return NS_ERROR_OUT_OF_MEMORY;
133 :
134 0 : return NS_OK;
135 : }
136 :
137 233 : NS_IMETHODIMP nsSupportsCStringImpl::SetData(const nsACString& aData)
138 : {
139 233 : mData = aData;
140 233 : return NS_OK;
141 : }
142 :
143 : /*****************************************************************************
144 : * nsSupportsStringImpl
145 : *****************************************************************************/
146 :
147 831703 : NS_IMPL_ISUPPORTS2(nsSupportsStringImpl, nsISupportsString,
148 : nsISupportsPrimitive)
149 :
150 0 : NS_IMETHODIMP nsSupportsStringImpl::GetType(PRUint16 *aType)
151 : {
152 0 : NS_ASSERTION(aType, "Bad pointer");
153 :
154 0 : *aType = TYPE_STRING;
155 0 : return NS_OK;
156 : }
157 :
158 30348 : NS_IMETHODIMP nsSupportsStringImpl::GetData(nsAString& aData)
159 : {
160 30348 : aData = mData;
161 30348 : return NS_OK;
162 : }
163 :
164 2407 : NS_IMETHODIMP nsSupportsStringImpl::ToString(PRUnichar **_retval)
165 : {
166 2407 : *_retval = ToNewUnicode(mData);
167 :
168 2407 : if (!*_retval)
169 0 : return NS_ERROR_OUT_OF_MEMORY;
170 :
171 2407 : return NS_OK;
172 : }
173 :
174 33240 : NS_IMETHODIMP nsSupportsStringImpl::SetData(const nsAString& aData)
175 : {
176 33240 : mData = aData;
177 33240 : return NS_OK;
178 : }
179 :
180 : /***************************************************************************/
181 :
182 12840 : NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsPRBoolImpl, nsISupportsPRBool,
183 : nsISupportsPrimitive)
184 :
185 474 : nsSupportsPRBoolImpl::nsSupportsPRBoolImpl()
186 474 : : mData(false)
187 : {
188 474 : }
189 :
190 0 : NS_IMETHODIMP nsSupportsPRBoolImpl::GetType(PRUint16 *aType)
191 : {
192 0 : NS_ASSERTION(aType, "Bad pointer");
193 0 : *aType = TYPE_PRBOOL;
194 :
195 0 : return NS_OK;
196 : }
197 :
198 345 : NS_IMETHODIMP nsSupportsPRBoolImpl::GetData(bool *aData)
199 : {
200 345 : NS_ASSERTION(aData, "Bad pointer");
201 345 : *aData = mData;
202 345 : return NS_OK;
203 : }
204 :
205 482 : NS_IMETHODIMP nsSupportsPRBoolImpl::SetData(bool aData)
206 : {
207 482 : mData = aData;
208 482 : return NS_OK;
209 : }
210 :
211 0 : NS_IMETHODIMP nsSupportsPRBoolImpl::ToString(char **_retval)
212 : {
213 0 : NS_ASSERTION(_retval, "Bad pointer");
214 0 : const char * str = mData ? "true" : "false";
215 : char* result = (char*) nsMemory::Clone(str,
216 0 : (strlen(str)+1)*sizeof(char));
217 0 : *_retval = result;
218 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
219 : }
220 :
221 : /***************************************************************************/
222 :
223 18 : NS_IMPL_ISUPPORTS2(nsSupportsPRUint8Impl, nsISupportsPRUint8,
224 : nsISupportsPrimitive)
225 :
226 1 : nsSupportsPRUint8Impl::nsSupportsPRUint8Impl()
227 1 : : mData(0)
228 : {
229 1 : }
230 :
231 0 : NS_IMETHODIMP nsSupportsPRUint8Impl::GetType(PRUint16 *aType)
232 : {
233 0 : NS_ASSERTION(aType, "Bad pointer");
234 0 : *aType = TYPE_PRUINT8;
235 :
236 0 : return NS_OK;
237 : }
238 :
239 1 : NS_IMETHODIMP nsSupportsPRUint8Impl::GetData(PRUint8 *aData)
240 : {
241 1 : NS_ASSERTION(aData, "Bad pointer");
242 1 : *aData = mData;
243 1 : return NS_OK;
244 : }
245 :
246 1 : NS_IMETHODIMP nsSupportsPRUint8Impl::SetData(PRUint8 aData)
247 : {
248 1 : mData = aData;
249 1 : return NS_OK;
250 : }
251 :
252 0 : NS_IMETHODIMP nsSupportsPRUint8Impl::ToString(char **_retval)
253 : {
254 0 : NS_ASSERTION(_retval, "Bad pointer");
255 : static const int size = 8;
256 : char buf[size];
257 :
258 0 : PR_snprintf(buf, size, "%u", (PRUint16) mData);
259 :
260 : char* result = (char*) nsMemory::Clone(buf,
261 0 : (strlen(buf)+1)*sizeof(char));
262 0 : *_retval = result;
263 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
264 : }
265 :
266 : /***************************************************************************/
267 :
268 18 : NS_IMPL_ISUPPORTS2(nsSupportsPRUint16Impl, nsISupportsPRUint16,
269 : nsISupportsPrimitive)
270 :
271 1 : nsSupportsPRUint16Impl::nsSupportsPRUint16Impl()
272 1 : : mData(0)
273 : {
274 1 : }
275 :
276 0 : NS_IMETHODIMP nsSupportsPRUint16Impl::GetType(PRUint16 *aType)
277 : {
278 0 : NS_ASSERTION(aType, "Bad pointer");
279 0 : *aType = TYPE_PRUINT16;
280 :
281 0 : return NS_OK;
282 : }
283 :
284 1 : NS_IMETHODIMP nsSupportsPRUint16Impl::GetData(PRUint16 *aData)
285 : {
286 1 : NS_ASSERTION(aData, "Bad pointer");
287 1 : *aData = mData;
288 1 : return NS_OK;
289 : }
290 :
291 1 : NS_IMETHODIMP nsSupportsPRUint16Impl::SetData(PRUint16 aData)
292 : {
293 1 : mData = aData;
294 1 : return NS_OK;
295 : }
296 :
297 0 : NS_IMETHODIMP nsSupportsPRUint16Impl::ToString(char **_retval)
298 : {
299 0 : NS_ASSERTION(_retval, "Bad pointer");
300 : static const int size = 8;
301 : char buf[size];
302 :
303 0 : PR_snprintf(buf, size, "%u", (int) mData);
304 :
305 : char* result = (char*) nsMemory::Clone(buf,
306 0 : (strlen(buf)+1)*sizeof(char));
307 0 : *_retval = result;
308 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
309 : }
310 :
311 : /***************************************************************************/
312 :
313 165 : NS_IMPL_ISUPPORTS2(nsSupportsPRUint32Impl, nsISupportsPRUint32,
314 : nsISupportsPrimitive)
315 :
316 14 : nsSupportsPRUint32Impl::nsSupportsPRUint32Impl()
317 14 : : mData(0)
318 : {
319 14 : }
320 :
321 0 : NS_IMETHODIMP nsSupportsPRUint32Impl::GetType(PRUint16 *aType)
322 : {
323 0 : NS_ASSERTION(aType, "Bad pointer");
324 0 : *aType = TYPE_PRUINT32;
325 :
326 0 : return NS_OK;
327 : }
328 :
329 9 : NS_IMETHODIMP nsSupportsPRUint32Impl::GetData(PRUint32 *aData)
330 : {
331 9 : NS_ASSERTION(aData, "Bad pointer");
332 9 : *aData = mData;
333 9 : return NS_OK;
334 : }
335 :
336 16 : NS_IMETHODIMP nsSupportsPRUint32Impl::SetData(PRUint32 aData)
337 : {
338 16 : mData = aData;
339 16 : return NS_OK;
340 : }
341 :
342 0 : NS_IMETHODIMP nsSupportsPRUint32Impl::ToString(char **_retval)
343 : {
344 0 : NS_ASSERTION(_retval, "Bad pointer");
345 : static const int size = 16;
346 : char buf[size];
347 :
348 0 : PR_snprintf(buf, size, "%lu", mData);
349 :
350 : char* result = (char*) nsMemory::Clone(buf,
351 0 : (strlen(buf)+1)*sizeof(char));
352 0 : *_retval = result;
353 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
354 : }
355 :
356 : /***************************************************************************/
357 :
358 18 : NS_IMPL_ISUPPORTS2(nsSupportsPRUint64Impl, nsISupportsPRUint64,
359 : nsISupportsPrimitive)
360 :
361 1 : nsSupportsPRUint64Impl::nsSupportsPRUint64Impl()
362 1 : : mData(LL_ZERO)
363 : {
364 1 : }
365 :
366 0 : NS_IMETHODIMP nsSupportsPRUint64Impl::GetType(PRUint16 *aType)
367 : {
368 0 : NS_ASSERTION(aType, "Bad pointer");
369 0 : *aType = TYPE_PRUINT64;
370 :
371 0 : return NS_OK;
372 : }
373 :
374 1 : NS_IMETHODIMP nsSupportsPRUint64Impl::GetData(PRUint64 *aData)
375 : {
376 1 : NS_ASSERTION(aData, "Bad pointer");
377 1 : *aData = mData;
378 1 : return NS_OK;
379 : }
380 :
381 1 : NS_IMETHODIMP nsSupportsPRUint64Impl::SetData(PRUint64 aData)
382 : {
383 1 : mData = aData;
384 1 : return NS_OK;
385 : }
386 :
387 0 : NS_IMETHODIMP nsSupportsPRUint64Impl::ToString(char **_retval)
388 : {
389 0 : NS_ASSERTION(_retval, "Bad pointer");
390 : static const int size = 32;
391 : char buf[size];
392 :
393 0 : PR_snprintf(buf, size, "%llu", mData);
394 :
395 : char* result = (char*) nsMemory::Clone(buf,
396 0 : (strlen(buf)+1)*sizeof(char));
397 0 : *_retval = result;
398 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
399 : }
400 :
401 : /***************************************************************************/
402 :
403 0 : NS_IMPL_ISUPPORTS2(nsSupportsPRTimeImpl, nsISupportsPRTime,
404 : nsISupportsPrimitive)
405 :
406 0 : nsSupportsPRTimeImpl::nsSupportsPRTimeImpl()
407 0 : : mData(LL_ZERO)
408 : {
409 0 : }
410 :
411 0 : NS_IMETHODIMP nsSupportsPRTimeImpl::GetType(PRUint16 *aType)
412 : {
413 0 : NS_ASSERTION(aType, "Bad pointer");
414 0 : *aType = TYPE_PRTIME;
415 :
416 0 : return NS_OK;
417 : }
418 :
419 0 : NS_IMETHODIMP nsSupportsPRTimeImpl::GetData(PRTime *aData)
420 : {
421 0 : NS_ASSERTION(aData, "Bad pointer");
422 0 : *aData = mData;
423 0 : return NS_OK;
424 : }
425 :
426 0 : NS_IMETHODIMP nsSupportsPRTimeImpl::SetData(PRTime aData)
427 : {
428 0 : mData = aData;
429 0 : return NS_OK;
430 : }
431 :
432 0 : NS_IMETHODIMP nsSupportsPRTimeImpl::ToString(char **_retval)
433 : {
434 0 : NS_ASSERTION(_retval, "Bad pointer");
435 : static const int size = 32;
436 : char buf[size];
437 :
438 0 : PR_snprintf(buf, size, "%llu", mData);
439 :
440 : char* result = (char*) nsMemory::Clone(buf,
441 0 : (strlen(buf)+1)*sizeof(char));
442 0 : *_retval = result;
443 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
444 : }
445 :
446 : /***************************************************************************/
447 :
448 0 : NS_IMPL_ISUPPORTS2(nsSupportsCharImpl, nsISupportsChar,
449 : nsISupportsPrimitive)
450 :
451 0 : nsSupportsCharImpl::nsSupportsCharImpl()
452 0 : : mData(0)
453 : {
454 0 : }
455 :
456 0 : NS_IMETHODIMP nsSupportsCharImpl::GetType(PRUint16 *aType)
457 : {
458 0 : NS_ASSERTION(aType, "Bad pointer");
459 0 : *aType = TYPE_CHAR;
460 :
461 0 : return NS_OK;
462 : }
463 :
464 0 : NS_IMETHODIMP nsSupportsCharImpl::GetData(char *aData)
465 : {
466 0 : NS_ASSERTION(aData, "Bad pointer");
467 0 : *aData = mData;
468 0 : return NS_OK;
469 : }
470 :
471 0 : NS_IMETHODIMP nsSupportsCharImpl::SetData(char aData)
472 : {
473 0 : mData = aData;
474 0 : return NS_OK;
475 : }
476 :
477 0 : NS_IMETHODIMP nsSupportsCharImpl::ToString(char **_retval)
478 : {
479 : char* result;
480 0 : NS_ASSERTION(_retval, "Bad pointer");
481 :
482 0 : if(nsnull != (result = (char*) nsMemory::Alloc(2*sizeof(char))))
483 : {
484 0 : result[0] = mData;
485 0 : result[1] = '\0';
486 : }
487 0 : *_retval = result;
488 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
489 : }
490 :
491 : /***************************************************************************/
492 :
493 18 : NS_IMPL_ISUPPORTS2(nsSupportsPRInt16Impl, nsISupportsPRInt16,
494 : nsISupportsPrimitive)
495 :
496 1 : nsSupportsPRInt16Impl::nsSupportsPRInt16Impl()
497 1 : : mData(0)
498 : {
499 1 : }
500 :
501 0 : NS_IMETHODIMP nsSupportsPRInt16Impl::GetType(PRUint16 *aType)
502 : {
503 0 : NS_ASSERTION(aType, "Bad pointer");
504 0 : *aType = TYPE_PRINT16;
505 :
506 0 : return NS_OK;
507 : }
508 :
509 1 : NS_IMETHODIMP nsSupportsPRInt16Impl::GetData(PRInt16 *aData)
510 : {
511 1 : NS_ASSERTION(aData, "Bad pointer");
512 1 : *aData = mData;
513 1 : return NS_OK;
514 : }
515 :
516 1 : NS_IMETHODIMP nsSupportsPRInt16Impl::SetData(PRInt16 aData)
517 : {
518 1 : mData = aData;
519 1 : return NS_OK;
520 : }
521 :
522 0 : NS_IMETHODIMP nsSupportsPRInt16Impl::ToString(char **_retval)
523 : {
524 0 : NS_ASSERTION(_retval, "Bad pointer");
525 : static const int size = 8;
526 : char buf[size];
527 :
528 0 : PR_snprintf(buf, size, "%d", mData);
529 :
530 : char* result = (char*) nsMemory::Clone(buf,
531 0 : (strlen(buf)+1)*sizeof(char));
532 0 : *_retval = result;
533 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
534 : }
535 :
536 : /***************************************************************************/
537 :
538 18 : NS_IMPL_ISUPPORTS2(nsSupportsPRInt32Impl, nsISupportsPRInt32,
539 : nsISupportsPrimitive)
540 :
541 1 : nsSupportsPRInt32Impl::nsSupportsPRInt32Impl()
542 1 : : mData(0)
543 : {
544 1 : }
545 :
546 0 : NS_IMETHODIMP nsSupportsPRInt32Impl::GetType(PRUint16 *aType)
547 : {
548 0 : NS_ASSERTION(aType, "Bad pointer");
549 0 : *aType = TYPE_PRINT32;
550 :
551 0 : return NS_OK;
552 : }
553 :
554 1 : NS_IMETHODIMP nsSupportsPRInt32Impl::GetData(PRInt32 *aData)
555 : {
556 1 : NS_ASSERTION(aData, "Bad pointer");
557 1 : *aData = mData;
558 1 : return NS_OK;
559 : }
560 :
561 1 : NS_IMETHODIMP nsSupportsPRInt32Impl::SetData(PRInt32 aData)
562 : {
563 1 : mData = aData;
564 1 : return NS_OK;
565 : }
566 :
567 0 : NS_IMETHODIMP nsSupportsPRInt32Impl::ToString(char **_retval)
568 : {
569 0 : NS_ASSERTION(_retval, "Bad pointer");
570 : static const int size = 16;
571 : char buf[size];
572 :
573 0 : PR_snprintf(buf, size, "%ld", mData);
574 :
575 : char* result = (char*) nsMemory::Clone(buf,
576 0 : (strlen(buf)+1)*sizeof(char));
577 0 : *_retval = result;
578 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
579 : }
580 :
581 : /***************************************************************************/
582 :
583 821 : NS_IMPL_ISUPPORTS2(nsSupportsPRInt64Impl, nsISupportsPRInt64,
584 : nsISupportsPrimitive)
585 :
586 33 : nsSupportsPRInt64Impl::nsSupportsPRInt64Impl()
587 33 : : mData(LL_ZERO)
588 : {
589 33 : }
590 :
591 0 : NS_IMETHODIMP nsSupportsPRInt64Impl::GetType(PRUint16 *aType)
592 : {
593 0 : NS_ASSERTION(aType, "Bad pointer");
594 0 : *aType = TYPE_PRINT64;
595 :
596 0 : return NS_OK;
597 : }
598 :
599 6 : NS_IMETHODIMP nsSupportsPRInt64Impl::GetData(PRInt64 *aData)
600 : {
601 6 : NS_ASSERTION(aData, "Bad pointer");
602 6 : *aData = mData;
603 6 : return NS_OK;
604 : }
605 :
606 33 : NS_IMETHODIMP nsSupportsPRInt64Impl::SetData(PRInt64 aData)
607 : {
608 33 : mData = aData;
609 33 : return NS_OK;
610 : }
611 :
612 8 : NS_IMETHODIMP nsSupportsPRInt64Impl::ToString(char **_retval)
613 : {
614 8 : NS_ASSERTION(_retval, "Bad pointer");
615 : static const int size = 32;
616 : char buf[size];
617 :
618 8 : PR_snprintf(buf, size, "%lld", mData);
619 :
620 : char* result = (char*) nsMemory::Clone(buf,
621 8 : (strlen(buf)+1)*sizeof(char));
622 8 : *_retval = result;
623 8 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
624 : }
625 :
626 : /***************************************************************************/
627 :
628 18 : NS_IMPL_ISUPPORTS2(nsSupportsFloatImpl, nsISupportsFloat,
629 : nsISupportsPrimitive)
630 :
631 1 : nsSupportsFloatImpl::nsSupportsFloatImpl()
632 1 : : mData(float(0.0))
633 : {
634 1 : }
635 :
636 0 : NS_IMETHODIMP nsSupportsFloatImpl::GetType(PRUint16 *aType)
637 : {
638 0 : NS_ASSERTION(aType, "Bad pointer");
639 0 : *aType = TYPE_FLOAT;
640 :
641 0 : return NS_OK;
642 : }
643 :
644 1 : NS_IMETHODIMP nsSupportsFloatImpl::GetData(float *aData)
645 : {
646 1 : NS_ASSERTION(aData, "Bad pointer");
647 1 : *aData = mData;
648 1 : return NS_OK;
649 : }
650 :
651 1 : NS_IMETHODIMP nsSupportsFloatImpl::SetData(float aData)
652 : {
653 1 : mData = aData;
654 1 : return NS_OK;
655 : }
656 :
657 0 : NS_IMETHODIMP nsSupportsFloatImpl::ToString(char **_retval)
658 : {
659 0 : NS_ASSERTION(_retval, "Bad pointer");
660 : static const int size = 32;
661 : char buf[size];
662 :
663 0 : PR_snprintf(buf, size, "%f", (double) mData);
664 :
665 : char* result = (char*) nsMemory::Clone(buf,
666 0 : (strlen(buf)+1)*sizeof(char));
667 0 : *_retval = result;
668 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
669 : }
670 :
671 : /***************************************************************************/
672 :
673 18 : NS_IMPL_ISUPPORTS2(nsSupportsDoubleImpl, nsISupportsDouble,
674 : nsISupportsPrimitive)
675 :
676 1 : nsSupportsDoubleImpl::nsSupportsDoubleImpl()
677 1 : : mData(double(0.0))
678 : {
679 1 : }
680 :
681 0 : NS_IMETHODIMP nsSupportsDoubleImpl::GetType(PRUint16 *aType)
682 : {
683 0 : NS_ASSERTION(aType, "Bad pointer");
684 0 : *aType = TYPE_DOUBLE;
685 :
686 0 : return NS_OK;
687 : }
688 :
689 1 : NS_IMETHODIMP nsSupportsDoubleImpl::GetData(double *aData)
690 : {
691 1 : NS_ASSERTION(aData, "Bad pointer");
692 1 : *aData = mData;
693 1 : return NS_OK;
694 : }
695 :
696 1 : NS_IMETHODIMP nsSupportsDoubleImpl::SetData(double aData)
697 : {
698 1 : mData = aData;
699 1 : return NS_OK;
700 : }
701 :
702 0 : NS_IMETHODIMP nsSupportsDoubleImpl::ToString(char **_retval)
703 : {
704 0 : NS_ASSERTION(_retval, "Bad pointer");
705 : static const int size = 32;
706 : char buf[size];
707 :
708 0 : PR_snprintf(buf, size, "%f", mData);
709 :
710 : char* result = (char*) nsMemory::Clone(buf,
711 0 : (strlen(buf)+1)*sizeof(char));
712 0 : *_retval = result;
713 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
714 : }
715 :
716 : /***************************************************************************/
717 :
718 :
719 0 : NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsVoidImpl, nsISupportsVoid,
720 : nsISupportsPrimitive)
721 :
722 0 : nsSupportsVoidImpl::nsSupportsVoidImpl()
723 0 : : mData(nsnull)
724 : {
725 0 : }
726 :
727 0 : NS_IMETHODIMP nsSupportsVoidImpl::GetType(PRUint16 *aType)
728 : {
729 0 : NS_ASSERTION(aType, "Bad pointer");
730 0 : *aType = TYPE_VOID;
731 :
732 0 : return NS_OK;
733 : }
734 :
735 0 : NS_IMETHODIMP nsSupportsVoidImpl::GetData(void * *aData)
736 : {
737 0 : NS_ASSERTION(aData, "Bad pointer");
738 0 : *aData = mData;
739 0 : return NS_OK;
740 : }
741 :
742 0 : NS_IMETHODIMP nsSupportsVoidImpl::SetData(void * aData)
743 : {
744 0 : mData = aData;
745 0 : return NS_OK;
746 : }
747 :
748 0 : NS_IMETHODIMP nsSupportsVoidImpl::ToString(char **_retval)
749 : {
750 0 : NS_ASSERTION(_retval, "Bad pointer");
751 :
752 : static const char str[] = "[raw data]";
753 0 : char* result = (char*) nsMemory::Clone(str, sizeof(str));
754 0 : *_retval = result;
755 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
756 : }
757 :
758 : /***************************************************************************/
759 :
760 :
761 0 : NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsInterfacePointerImpl,
762 : nsISupportsInterfacePointer,
763 : nsISupportsPrimitive)
764 :
765 0 : nsSupportsInterfacePointerImpl::nsSupportsInterfacePointerImpl()
766 0 : : mIID(nsnull)
767 : {
768 0 : }
769 :
770 0 : nsSupportsInterfacePointerImpl::~nsSupportsInterfacePointerImpl()
771 : {
772 0 : if (mIID) {
773 0 : nsMemory::Free(mIID);
774 : }
775 0 : }
776 :
777 0 : NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetType(PRUint16 *aType)
778 : {
779 0 : NS_ASSERTION(aType, "Bad pointer");
780 0 : *aType = TYPE_INTERFACE_POINTER;
781 :
782 0 : return NS_OK;
783 : }
784 :
785 0 : NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetData(nsISupports **aData)
786 : {
787 0 : NS_ASSERTION(aData,"Bad pointer");
788 :
789 0 : *aData = mData;
790 0 : NS_IF_ADDREF(*aData);
791 :
792 0 : return NS_OK;
793 : }
794 :
795 0 : NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetData(nsISupports * aData)
796 : {
797 0 : mData = aData;
798 :
799 0 : return NS_OK;
800 : }
801 :
802 0 : NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetDataIID(nsID **aIID)
803 : {
804 0 : NS_ASSERTION(aIID,"Bad pointer");
805 :
806 0 : if(mIID)
807 : {
808 0 : *aIID = (nsID*) nsMemory::Clone(mIID, sizeof(nsID));
809 0 : return *aIID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
810 : }
811 0 : *aIID = nsnull;
812 0 : return NS_OK;
813 : }
814 :
815 0 : NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetDataIID(const nsID *aIID)
816 : {
817 0 : if(mIID)
818 0 : nsMemory::Free(mIID);
819 0 : if(aIID)
820 0 : mIID = (nsID*) nsMemory::Clone(aIID, sizeof(nsID));
821 : else
822 0 : mIID = nsnull;
823 :
824 0 : return NS_OK;
825 : }
826 :
827 0 : NS_IMETHODIMP nsSupportsInterfacePointerImpl::ToString(char **_retval)
828 : {
829 0 : NS_ASSERTION(_retval, "Bad pointer");
830 :
831 : static const char str[] = "[interface pointer]";
832 :
833 : // jband sez: think about asking nsIInterfaceInfoManager whether
834 : // the interface has a known human-readable name
835 0 : char* result = (char*) nsMemory::Clone(str, sizeof(str));
836 0 : *_retval = result;
837 0 : return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
838 : }
839 :
840 : /***************************************************************************/
841 :
842 66702 : NS_IMPL_ISUPPORTS2(nsSupportsDependentCString,nsISupportsCString,nsISupportsPrimitive)
843 :
844 7111 : nsSupportsDependentCString::nsSupportsDependentCString(const char* aStr)
845 7111 : : mData(aStr)
846 7111 : { }
847 :
848 : NS_IMETHODIMP
849 0 : nsSupportsDependentCString::GetType(PRUint16 *aType)
850 : {
851 0 : NS_ENSURE_ARG_POINTER(aType);
852 :
853 0 : *aType = TYPE_CSTRING;
854 0 : return NS_OK;
855 : }
856 :
857 : NS_IMETHODIMP
858 7111 : nsSupportsDependentCString::GetData(nsACString& aData)
859 : {
860 7111 : aData = mData;
861 7111 : return NS_OK;
862 : }
863 :
864 : NS_IMETHODIMP
865 0 : nsSupportsDependentCString::ToString(char **_retval)
866 : {
867 0 : NS_ENSURE_ARG_POINTER(_retval);
868 :
869 0 : *_retval = ToNewCString(mData);
870 0 : if (!*_retval)
871 0 : return NS_ERROR_OUT_OF_MEMORY;
872 :
873 0 : return NS_OK;
874 : }
875 :
876 : NS_IMETHODIMP
877 0 : nsSupportsDependentCString::SetData(const nsACString& aData)
878 : {
879 0 : return NS_ERROR_NOT_IMPLEMENTED;
880 : }
|