Bug 440351, update win32_buildPlatform for move from pacifica-vm to patrocles clones
[mozilla-1.9.git] / xpcom / ds / nsSupportsPrimitives.cpp
blob7fe5502a38460db80ae36e0f26d47c8f0cd9e2d8
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
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/
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.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
23 * Dan Rosen <dr@netscape.com>
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.
37 * ***** END LICENSE BLOCK ***** */
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"
48 /***************************************************************************/
50 NS_IMPL_ISUPPORTS2(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive)
52 nsSupportsIDImpl::nsSupportsIDImpl()
53 : mData(nsnull)
57 NS_IMETHODIMP nsSupportsIDImpl::GetType(PRUint16 *aType)
59 NS_ASSERTION(aType, "Bad pointer");
60 *aType = TYPE_ID;
62 return NS_OK;
65 NS_IMETHODIMP nsSupportsIDImpl::GetData(nsID **aData)
67 NS_ASSERTION(aData, "Bad pointer");
68 if(mData)
70 *aData = (nsID*) nsMemory::Clone(mData, sizeof(nsID));
71 return *aData ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
73 *aData = nsnull;
74 return NS_OK;
77 NS_IMETHODIMP nsSupportsIDImpl::SetData(const nsID *aData)
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;
88 NS_IMETHODIMP nsSupportsIDImpl::ToString(char **_retval)
90 char* result;
91 NS_ASSERTION(_retval, "Bad pointer");
92 if(mData)
94 result = mData->ToString();
96 else
98 static const char nullStr[] = "null";
99 result = (char*) nsMemory::Clone(nullStr, sizeof(nullStr));
102 *_retval = result;
103 return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
106 /*****************************************************************************
107 * nsSupportsCStringImpl
108 *****************************************************************************/
110 NS_IMPL_ISUPPORTS2(nsSupportsCStringImpl, nsISupportsCString,
111 nsISupportsPrimitive)
113 NS_IMETHODIMP nsSupportsCStringImpl::GetType(PRUint16 *aType)
115 NS_ASSERTION(aType, "Bad pointer");
117 *aType = TYPE_CSTRING;
118 return NS_OK;
121 NS_IMETHODIMP nsSupportsCStringImpl::GetData(nsACString& aData)
123 aData = mData;
124 return NS_OK;
127 NS_IMETHODIMP nsSupportsCStringImpl::ToString(char **_retval)
129 *_retval = ToNewCString(mData);
131 if (!*_retval)
132 return NS_ERROR_OUT_OF_MEMORY;
134 return NS_OK;
137 NS_IMETHODIMP nsSupportsCStringImpl::SetData(const nsACString& aData)
139 mData = aData;
140 return NS_OK;
143 /*****************************************************************************
144 * nsSupportsStringImpl
145 *****************************************************************************/
147 NS_IMPL_ISUPPORTS2(nsSupportsStringImpl, nsISupportsString,
148 nsISupportsPrimitive)
150 NS_IMETHODIMP nsSupportsStringImpl::GetType(PRUint16 *aType)
152 NS_ASSERTION(aType, "Bad pointer");
154 *aType = TYPE_STRING;
155 return NS_OK;
158 NS_IMETHODIMP nsSupportsStringImpl::GetData(nsAString& aData)
160 aData = mData;
161 return NS_OK;
164 NS_IMETHODIMP nsSupportsStringImpl::ToString(PRUnichar **_retval)
166 *_retval = ToNewUnicode(mData);
168 if (!*_retval)
169 return NS_ERROR_OUT_OF_MEMORY;
171 return NS_OK;
174 NS_IMETHODIMP nsSupportsStringImpl::SetData(const nsAString& aData)
176 mData = aData;
177 return NS_OK;
180 /***************************************************************************/
182 NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsPRBoolImpl, nsISupportsPRBool,
183 nsISupportsPrimitive)
185 nsSupportsPRBoolImpl::nsSupportsPRBoolImpl()
186 : mData(PR_FALSE)
190 NS_IMETHODIMP nsSupportsPRBoolImpl::GetType(PRUint16 *aType)
192 NS_ASSERTION(aType, "Bad pointer");
193 *aType = TYPE_PRBOOL;
195 return NS_OK;
198 NS_IMETHODIMP nsSupportsPRBoolImpl::GetData(PRBool *aData)
200 NS_ASSERTION(aData, "Bad pointer");
201 *aData = mData;
202 return NS_OK;
205 NS_IMETHODIMP nsSupportsPRBoolImpl::SetData(PRBool aData)
207 mData = aData;
208 return NS_OK;
211 NS_IMETHODIMP nsSupportsPRBoolImpl::ToString(char **_retval)
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;
221 /***************************************************************************/
223 NS_IMPL_ISUPPORTS2(nsSupportsPRUint8Impl, nsISupportsPRUint8,
224 nsISupportsPrimitive)
226 nsSupportsPRUint8Impl::nsSupportsPRUint8Impl()
227 : mData(0)
231 NS_IMETHODIMP nsSupportsPRUint8Impl::GetType(PRUint16 *aType)
233 NS_ASSERTION(aType, "Bad pointer");
234 *aType = TYPE_PRUINT8;
236 return NS_OK;
239 NS_IMETHODIMP nsSupportsPRUint8Impl::GetData(PRUint8 *aData)
241 NS_ASSERTION(aData, "Bad pointer");
242 *aData = mData;
243 return NS_OK;
246 NS_IMETHODIMP nsSupportsPRUint8Impl::SetData(PRUint8 aData)
248 mData = aData;
249 return NS_OK;
252 NS_IMETHODIMP nsSupportsPRUint8Impl::ToString(char **_retval)
254 NS_ASSERTION(_retval, "Bad pointer");
255 static const int size = 8;
256 char buf[size];
258 PR_snprintf(buf, size, "%u", (PRUint16) mData);
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;
266 /***************************************************************************/
268 NS_IMPL_ISUPPORTS2(nsSupportsPRUint16Impl, nsISupportsPRUint16,
269 nsISupportsPrimitive)
271 nsSupportsPRUint16Impl::nsSupportsPRUint16Impl()
272 : mData(0)
276 NS_IMETHODIMP nsSupportsPRUint16Impl::GetType(PRUint16 *aType)
278 NS_ASSERTION(aType, "Bad pointer");
279 *aType = TYPE_PRUINT16;
281 return NS_OK;
284 NS_IMETHODIMP nsSupportsPRUint16Impl::GetData(PRUint16 *aData)
286 NS_ASSERTION(aData, "Bad pointer");
287 *aData = mData;
288 return NS_OK;
291 NS_IMETHODIMP nsSupportsPRUint16Impl::SetData(PRUint16 aData)
293 mData = aData;
294 return NS_OK;
297 NS_IMETHODIMP nsSupportsPRUint16Impl::ToString(char **_retval)
299 NS_ASSERTION(_retval, "Bad pointer");
300 static const int size = 8;
301 char buf[size];
303 PR_snprintf(buf, size, "%u", (int) mData);
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;
311 /***************************************************************************/
313 NS_IMPL_ISUPPORTS2(nsSupportsPRUint32Impl, nsISupportsPRUint32,
314 nsISupportsPrimitive)
316 nsSupportsPRUint32Impl::nsSupportsPRUint32Impl()
317 : mData(0)
321 NS_IMETHODIMP nsSupportsPRUint32Impl::GetType(PRUint16 *aType)
323 NS_ASSERTION(aType, "Bad pointer");
324 *aType = TYPE_PRUINT32;
326 return NS_OK;
329 NS_IMETHODIMP nsSupportsPRUint32Impl::GetData(PRUint32 *aData)
331 NS_ASSERTION(aData, "Bad pointer");
332 *aData = mData;
333 return NS_OK;
336 NS_IMETHODIMP nsSupportsPRUint32Impl::SetData(PRUint32 aData)
338 mData = aData;
339 return NS_OK;
342 NS_IMETHODIMP nsSupportsPRUint32Impl::ToString(char **_retval)
344 NS_ASSERTION(_retval, "Bad pointer");
345 static const int size = 16;
346 char buf[size];
348 PR_snprintf(buf, size, "%lu", mData);
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;
356 /***************************************************************************/
358 NS_IMPL_ISUPPORTS2(nsSupportsPRUint64Impl, nsISupportsPRUint64,
359 nsISupportsPrimitive)
361 nsSupportsPRUint64Impl::nsSupportsPRUint64Impl()
362 : mData(LL_ZERO)
366 NS_IMETHODIMP nsSupportsPRUint64Impl::GetType(PRUint16 *aType)
368 NS_ASSERTION(aType, "Bad pointer");
369 *aType = TYPE_PRUINT64;
371 return NS_OK;
374 NS_IMETHODIMP nsSupportsPRUint64Impl::GetData(PRUint64 *aData)
376 NS_ASSERTION(aData, "Bad pointer");
377 *aData = mData;
378 return NS_OK;
381 NS_IMETHODIMP nsSupportsPRUint64Impl::SetData(PRUint64 aData)
383 mData = aData;
384 return NS_OK;
387 NS_IMETHODIMP nsSupportsPRUint64Impl::ToString(char **_retval)
389 NS_ASSERTION(_retval, "Bad pointer");
390 static const int size = 32;
391 char buf[size];
393 PR_snprintf(buf, size, "%llu", mData);
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;
401 /***************************************************************************/
403 NS_IMPL_ISUPPORTS2(nsSupportsPRTimeImpl, nsISupportsPRTime,
404 nsISupportsPrimitive)
406 nsSupportsPRTimeImpl::nsSupportsPRTimeImpl()
407 : mData(LL_ZERO)
411 NS_IMETHODIMP nsSupportsPRTimeImpl::GetType(PRUint16 *aType)
413 NS_ASSERTION(aType, "Bad pointer");
414 *aType = TYPE_PRTIME;
416 return NS_OK;
419 NS_IMETHODIMP nsSupportsPRTimeImpl::GetData(PRTime *aData)
421 NS_ASSERTION(aData, "Bad pointer");
422 *aData = mData;
423 return NS_OK;
426 NS_IMETHODIMP nsSupportsPRTimeImpl::SetData(PRTime aData)
428 mData = aData;
429 return NS_OK;
432 NS_IMETHODIMP nsSupportsPRTimeImpl::ToString(char **_retval)
434 NS_ASSERTION(_retval, "Bad pointer");
435 static const int size = 32;
436 char buf[size];
438 PR_snprintf(buf, size, "%llu", mData);
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;
446 /***************************************************************************/
448 NS_IMPL_ISUPPORTS2(nsSupportsCharImpl, nsISupportsChar,
449 nsISupportsPrimitive)
451 nsSupportsCharImpl::nsSupportsCharImpl()
452 : mData(0)
456 NS_IMETHODIMP nsSupportsCharImpl::GetType(PRUint16 *aType)
458 NS_ASSERTION(aType, "Bad pointer");
459 *aType = TYPE_CHAR;
461 return NS_OK;
464 NS_IMETHODIMP nsSupportsCharImpl::GetData(char *aData)
466 NS_ASSERTION(aData, "Bad pointer");
467 *aData = mData;
468 return NS_OK;
471 NS_IMETHODIMP nsSupportsCharImpl::SetData(char aData)
473 mData = aData;
474 return NS_OK;
477 NS_IMETHODIMP nsSupportsCharImpl::ToString(char **_retval)
479 char* result;
480 NS_ASSERTION(_retval, "Bad pointer");
482 if(nsnull != (result = (char*) nsMemory::Alloc(2*sizeof(char))))
484 result[0] = mData;
485 result[1] = '\0';
487 *_retval = result;
488 return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
491 /***************************************************************************/
493 NS_IMPL_ISUPPORTS2(nsSupportsPRInt16Impl, nsISupportsPRInt16,
494 nsISupportsPrimitive)
496 nsSupportsPRInt16Impl::nsSupportsPRInt16Impl()
497 : mData(0)
501 NS_IMETHODIMP nsSupportsPRInt16Impl::GetType(PRUint16 *aType)
503 NS_ASSERTION(aType, "Bad pointer");
504 *aType = TYPE_PRINT16;
506 return NS_OK;
509 NS_IMETHODIMP nsSupportsPRInt16Impl::GetData(PRInt16 *aData)
511 NS_ASSERTION(aData, "Bad pointer");
512 *aData = mData;
513 return NS_OK;
516 NS_IMETHODIMP nsSupportsPRInt16Impl::SetData(PRInt16 aData)
518 mData = aData;
519 return NS_OK;
522 NS_IMETHODIMP nsSupportsPRInt16Impl::ToString(char **_retval)
524 NS_ASSERTION(_retval, "Bad pointer");
525 static const int size = 8;
526 char buf[size];
528 PR_snprintf(buf, size, "%d", mData);
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;
536 /***************************************************************************/
538 NS_IMPL_ISUPPORTS2(nsSupportsPRInt32Impl, nsISupportsPRInt32,
539 nsISupportsPrimitive)
541 nsSupportsPRInt32Impl::nsSupportsPRInt32Impl()
542 : mData(0)
546 NS_IMETHODIMP nsSupportsPRInt32Impl::GetType(PRUint16 *aType)
548 NS_ASSERTION(aType, "Bad pointer");
549 *aType = TYPE_PRINT32;
551 return NS_OK;
554 NS_IMETHODIMP nsSupportsPRInt32Impl::GetData(PRInt32 *aData)
556 NS_ASSERTION(aData, "Bad pointer");
557 *aData = mData;
558 return NS_OK;
561 NS_IMETHODIMP nsSupportsPRInt32Impl::SetData(PRInt32 aData)
563 mData = aData;
564 return NS_OK;
567 NS_IMETHODIMP nsSupportsPRInt32Impl::ToString(char **_retval)
569 NS_ASSERTION(_retval, "Bad pointer");
570 static const int size = 16;
571 char buf[size];
573 PR_snprintf(buf, size, "%ld", mData);
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;
581 /***************************************************************************/
583 NS_IMPL_ISUPPORTS2(nsSupportsPRInt64Impl, nsISupportsPRInt64,
584 nsISupportsPrimitive)
586 nsSupportsPRInt64Impl::nsSupportsPRInt64Impl()
587 : mData(LL_ZERO)
591 NS_IMETHODIMP nsSupportsPRInt64Impl::GetType(PRUint16 *aType)
593 NS_ASSERTION(aType, "Bad pointer");
594 *aType = TYPE_PRINT64;
596 return NS_OK;
599 NS_IMETHODIMP nsSupportsPRInt64Impl::GetData(PRInt64 *aData)
601 NS_ASSERTION(aData, "Bad pointer");
602 *aData = mData;
603 return NS_OK;
606 NS_IMETHODIMP nsSupportsPRInt64Impl::SetData(PRInt64 aData)
608 mData = aData;
609 return NS_OK;
612 NS_IMETHODIMP nsSupportsPRInt64Impl::ToString(char **_retval)
614 NS_ASSERTION(_retval, "Bad pointer");
615 static const int size = 32;
616 char buf[size];
618 PR_snprintf(buf, size, "%lld", mData);
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;
626 /***************************************************************************/
628 NS_IMPL_ISUPPORTS2(nsSupportsFloatImpl, nsISupportsFloat,
629 nsISupportsPrimitive)
631 nsSupportsFloatImpl::nsSupportsFloatImpl()
632 : mData(float(0.0))
636 NS_IMETHODIMP nsSupportsFloatImpl::GetType(PRUint16 *aType)
638 NS_ASSERTION(aType, "Bad pointer");
639 *aType = TYPE_FLOAT;
641 return NS_OK;
644 NS_IMETHODIMP nsSupportsFloatImpl::GetData(float *aData)
646 NS_ASSERTION(aData, "Bad pointer");
647 *aData = mData;
648 return NS_OK;
651 NS_IMETHODIMP nsSupportsFloatImpl::SetData(float aData)
653 mData = aData;
654 return NS_OK;
657 NS_IMETHODIMP nsSupportsFloatImpl::ToString(char **_retval)
659 NS_ASSERTION(_retval, "Bad pointer");
660 static const int size = 32;
661 char buf[size];
663 PR_snprintf(buf, size, "%f", (double) mData);
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;
671 /***************************************************************************/
673 NS_IMPL_ISUPPORTS2(nsSupportsDoubleImpl, nsISupportsDouble,
674 nsISupportsPrimitive)
676 nsSupportsDoubleImpl::nsSupportsDoubleImpl()
677 : mData(double(0.0))
681 NS_IMETHODIMP nsSupportsDoubleImpl::GetType(PRUint16 *aType)
683 NS_ASSERTION(aType, "Bad pointer");
684 *aType = TYPE_DOUBLE;
686 return NS_OK;
689 NS_IMETHODIMP nsSupportsDoubleImpl::GetData(double *aData)
691 NS_ASSERTION(aData, "Bad pointer");
692 *aData = mData;
693 return NS_OK;
696 NS_IMETHODIMP nsSupportsDoubleImpl::SetData(double aData)
698 mData = aData;
699 return NS_OK;
702 NS_IMETHODIMP nsSupportsDoubleImpl::ToString(char **_retval)
704 NS_ASSERTION(_retval, "Bad pointer");
705 static const int size = 32;
706 char buf[size];
708 PR_snprintf(buf, size, "%f", mData);
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;
716 /***************************************************************************/
719 NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsVoidImpl, nsISupportsVoid,
720 nsISupportsPrimitive)
722 nsSupportsVoidImpl::nsSupportsVoidImpl()
723 : mData(nsnull)
727 NS_IMETHODIMP nsSupportsVoidImpl::GetType(PRUint16 *aType)
729 NS_ASSERTION(aType, "Bad pointer");
730 *aType = TYPE_VOID;
732 return NS_OK;
735 NS_IMETHODIMP nsSupportsVoidImpl::GetData(void * *aData)
737 NS_ASSERTION(aData, "Bad pointer");
738 *aData = mData;
739 return NS_OK;
742 NS_IMETHODIMP nsSupportsVoidImpl::SetData(void * aData)
744 mData = aData;
745 return NS_OK;
748 NS_IMETHODIMP nsSupportsVoidImpl::ToString(char **_retval)
750 NS_ASSERTION(_retval, "Bad pointer");
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;
758 /***************************************************************************/
761 NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsInterfacePointerImpl,
762 nsISupportsInterfacePointer,
763 nsISupportsPrimitive)
765 nsSupportsInterfacePointerImpl::nsSupportsInterfacePointerImpl()
766 : mIID(nsnull)
770 nsSupportsInterfacePointerImpl::~nsSupportsInterfacePointerImpl()
772 if (mIID) {
773 nsMemory::Free(mIID);
777 NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetType(PRUint16 *aType)
779 NS_ASSERTION(aType, "Bad pointer");
780 *aType = TYPE_INTERFACE_POINTER;
782 return NS_OK;
785 NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetData(nsISupports **aData)
787 NS_ASSERTION(aData,"Bad pointer");
789 *aData = mData;
790 NS_IF_ADDREF(*aData);
792 return NS_OK;
795 NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetData(nsISupports * aData)
797 mData = aData;
799 return NS_OK;
802 NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetDataIID(nsID **aIID)
804 NS_ASSERTION(aIID,"Bad pointer");
806 if(mIID)
808 *aIID = (nsID*) nsMemory::Clone(mIID, sizeof(nsID));
809 return *aIID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
811 *aIID = nsnull;
812 return NS_OK;
815 NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetDataIID(const nsID *aIID)
817 if(mIID)
818 nsMemory::Free(mIID);
819 if(aIID)
820 mIID = (nsID*) nsMemory::Clone(aIID, sizeof(nsID));
821 else
822 mIID = nsnull;
824 return NS_OK;
827 NS_IMETHODIMP nsSupportsInterfacePointerImpl::ToString(char **_retval)
829 NS_ASSERTION(_retval, "Bad pointer");
831 static const char str[] = "[interface pointer]";
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;
840 /***************************************************************************/
842 NS_IMPL_ISUPPORTS2(nsSupportsDependentCString,nsISupportsCString,nsISupportsPrimitive)
844 nsSupportsDependentCString::nsSupportsDependentCString(const char* aStr)
845 : mData(aStr)
848 NS_IMETHODIMP
849 nsSupportsDependentCString::GetType(PRUint16 *aType)
851 NS_ENSURE_ARG_POINTER(aType);
853 *aType = TYPE_CSTRING;
854 return NS_OK;
857 NS_IMETHODIMP
858 nsSupportsDependentCString::GetData(nsACString& aData)
860 aData = mData;
861 return NS_OK;
864 NS_IMETHODIMP
865 nsSupportsDependentCString::ToString(char **_retval)
867 NS_ENSURE_ARG_POINTER(_retval);
869 *_retval = ToNewCString(mData);
870 if (!*_retval)
871 return NS_ERROR_OUT_OF_MEMORY;
873 return NS_OK;
876 NS_IMETHODIMP
877 nsSupportsDependentCString::SetData(const nsACString& aData)
879 return NS_ERROR_NOT_IMPLEMENTED;