VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/ds/nsSupportsPrimitives.cpp@ 4837

Last change on this file since 4837 was 1, checked in by vboxsync, 54 years ago

import

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

© 2023 Oracle
ContactPrivacy policyTerms of Use