Back to index

lightning-sunbird  0.9+nobinonly
nsSupportsPrimitives.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Dan Rosen <dr@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsSupportsPrimitives.h"
00040 #include "nsCRT.h"
00041 #include "nsMemory.h"
00042 #include "prprf.h"
00043 #include "nsIInterfaceInfoManager.h"
00044 #include "nsDependentString.h"
00045 #include "nsReadableUtils.h"
00046 #include "nsPromiseFlatString.h"
00047 
00048 /***************************************************************************/
00049 
00050 NS_IMPL_ISUPPORTS2(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive)
00051 
00052 nsSupportsIDImpl::nsSupportsIDImpl()
00053     : mData(nsnull)
00054 {
00055 }
00056 
00057 NS_IMETHODIMP nsSupportsIDImpl::GetType(PRUint16 *aType)
00058 {
00059     NS_ASSERTION(aType, "Bad pointer");
00060     *aType = TYPE_ID;
00061 
00062     return NS_OK;
00063 }
00064 
00065 NS_IMETHODIMP nsSupportsIDImpl::GetData(nsID **aData)
00066 {
00067     NS_ASSERTION(aData, "Bad pointer");
00068     if(mData)
00069     {
00070         *aData = (nsID*) nsMemory::Clone(mData, sizeof(nsID));
00071         return *aData ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00072     }
00073     *aData = nsnull;
00074     return NS_OK;
00075 }
00076 
00077 NS_IMETHODIMP nsSupportsIDImpl::SetData(const nsID *aData)
00078 {
00079     if(mData)
00080       nsMemory::Free(mData);
00081     if(aData)
00082         mData = (nsID*) nsMemory::Clone(aData, sizeof(nsID));
00083     else
00084         mData = nsnull;
00085     return NS_OK;
00086 }
00087 
00088 NS_IMETHODIMP nsSupportsIDImpl::ToString(char **_retval)
00089 {
00090     char* result;
00091     NS_ASSERTION(_retval, "Bad pointer");
00092     if(mData)
00093     {
00094         result = mData->ToString();
00095     }
00096     else
00097     {
00098         static const char nullStr[] = "null";
00099         result = (char*) nsMemory::Clone(nullStr, sizeof(nullStr));
00100     }
00101 
00102     *_retval = result;
00103     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00104 }  
00105 
00106 /*****************************************************************************
00107  * nsSupportsCStringImpl
00108  *****************************************************************************/
00109 
00110 NS_IMPL_ISUPPORTS2(nsSupportsCStringImpl, nsISupportsCString,
00111                    nsISupportsPrimitive)
00112 
00113 NS_IMETHODIMP nsSupportsCStringImpl::GetType(PRUint16 *aType)
00114 {
00115     NS_ASSERTION(aType, "Bad pointer");
00116 
00117     *aType = TYPE_CSTRING;
00118     return NS_OK;
00119 }
00120 
00121 NS_IMETHODIMP nsSupportsCStringImpl::GetData(nsACString& aData)
00122 {
00123     aData = mData;
00124     return NS_OK;
00125 }
00126 
00127 NS_IMETHODIMP nsSupportsCStringImpl::ToString(char **_retval)
00128 {
00129     *_retval = ToNewCString(mData);
00130 
00131     if (!*_retval)
00132         return NS_ERROR_OUT_OF_MEMORY;
00133     
00134     return NS_OK;
00135 }
00136 
00137 NS_IMETHODIMP nsSupportsCStringImpl::SetData(const nsACString& aData)
00138 {
00139     mData = aData;
00140     return NS_OK;
00141 }
00142 
00143 /*****************************************************************************
00144  * nsSupportsStringImpl
00145  *****************************************************************************/
00146 
00147 NS_IMPL_ISUPPORTS2(nsSupportsStringImpl, nsISupportsString,
00148                    nsISupportsPrimitive)
00149 
00150 NS_IMETHODIMP nsSupportsStringImpl::GetType(PRUint16 *aType)
00151 {
00152     NS_ASSERTION(aType, "Bad pointer");
00153 
00154     *aType = TYPE_STRING;
00155     return NS_OK;
00156 }
00157 
00158 NS_IMETHODIMP nsSupportsStringImpl::GetData(nsAString& aData)
00159 {
00160     aData = mData;
00161     return NS_OK;
00162 }
00163 
00164 NS_IMETHODIMP nsSupportsStringImpl::ToString(PRUnichar **_retval)
00165 {
00166     *_retval = ToNewUnicode(mData);
00167     
00168     if (!*_retval)
00169         return NS_ERROR_OUT_OF_MEMORY;
00170     
00171     return NS_OK;
00172 }
00173 
00174 NS_IMETHODIMP nsSupportsStringImpl::SetData(const nsAString& aData)
00175 {
00176     mData = aData;
00177     return NS_OK;
00178 }
00179 
00180 /***************************************************************************/
00181 
00182 NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsPRBoolImpl, nsISupportsPRBool,
00183                               nsISupportsPrimitive)
00184 
00185 nsSupportsPRBoolImpl::nsSupportsPRBoolImpl()
00186     : mData(PR_FALSE)
00187 {
00188 }
00189 
00190 NS_IMETHODIMP nsSupportsPRBoolImpl::GetType(PRUint16 *aType)
00191 {
00192     NS_ASSERTION(aType, "Bad pointer");
00193     *aType = TYPE_PRBOOL;
00194 
00195     return NS_OK;
00196 }
00197 
00198 NS_IMETHODIMP nsSupportsPRBoolImpl::GetData(PRBool *aData)
00199 {
00200     NS_ASSERTION(aData, "Bad pointer");
00201     *aData = mData;
00202     return NS_OK;
00203 }
00204 
00205 NS_IMETHODIMP nsSupportsPRBoolImpl::SetData(PRBool aData)
00206 {
00207     mData = aData;
00208     return NS_OK;
00209 }
00210 
00211 NS_IMETHODIMP nsSupportsPRBoolImpl::ToString(char **_retval)
00212 {
00213     NS_ASSERTION(_retval, "Bad pointer");
00214     const char * str = mData ? "true" : "false";
00215     char* result = (char*) nsMemory::Clone(str,
00216                                 (strlen(str)+1)*sizeof(char));
00217     *_retval = result;
00218     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00219 }  
00220 
00221 /***************************************************************************/
00222 
00223 NS_IMPL_ISUPPORTS2(nsSupportsPRUint8Impl, nsISupportsPRUint8,
00224                    nsISupportsPrimitive)
00225 
00226 nsSupportsPRUint8Impl::nsSupportsPRUint8Impl()
00227     : mData(0)
00228 {
00229 }
00230 
00231 NS_IMETHODIMP nsSupportsPRUint8Impl::GetType(PRUint16 *aType)
00232 {
00233     NS_ASSERTION(aType, "Bad pointer");
00234     *aType = TYPE_PRUINT8;
00235 
00236     return NS_OK;
00237 }
00238 
00239 NS_IMETHODIMP nsSupportsPRUint8Impl::GetData(PRUint8 *aData)
00240 {
00241     NS_ASSERTION(aData, "Bad pointer");
00242     *aData = mData;
00243     return NS_OK;
00244 }
00245 
00246 NS_IMETHODIMP nsSupportsPRUint8Impl::SetData(PRUint8 aData)
00247 {
00248     mData = aData;
00249     return NS_OK;
00250 }
00251 
00252 NS_IMETHODIMP nsSupportsPRUint8Impl::ToString(char **_retval)
00253 {
00254     NS_ASSERTION(_retval, "Bad pointer");
00255     static const int size = 8;
00256     char buf[size];
00257 
00258     PR_snprintf(buf, size, "%u", (PRUint16) mData);
00259 
00260     char* result = (char*) nsMemory::Clone(buf,
00261                                 (strlen(buf)+1)*sizeof(char));
00262     *_retval = result;
00263     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00264 }  
00265 
00266 /***************************************************************************/
00267 
00268 NS_IMPL_ISUPPORTS2(nsSupportsPRUint16Impl, nsISupportsPRUint16,
00269                    nsISupportsPrimitive)
00270 
00271 nsSupportsPRUint16Impl::nsSupportsPRUint16Impl()
00272     : mData(0)
00273 {
00274 }
00275 
00276 NS_IMETHODIMP nsSupportsPRUint16Impl::GetType(PRUint16 *aType)
00277 {
00278     NS_ASSERTION(aType, "Bad pointer");
00279     *aType = TYPE_PRUINT16;
00280 
00281     return NS_OK;
00282 }
00283 
00284 NS_IMETHODIMP nsSupportsPRUint16Impl::GetData(PRUint16 *aData)
00285 {
00286     NS_ASSERTION(aData, "Bad pointer");
00287     *aData = mData;
00288     return NS_OK;
00289 }
00290 
00291 NS_IMETHODIMP nsSupportsPRUint16Impl::SetData(PRUint16 aData)
00292 {
00293     mData = aData;
00294     return NS_OK;
00295 }
00296 
00297 NS_IMETHODIMP nsSupportsPRUint16Impl::ToString(char **_retval)
00298 {
00299     NS_ASSERTION(_retval, "Bad pointer");
00300     static const int size = 8;
00301     char buf[size];
00302 
00303     PR_snprintf(buf, size, "%u", (int) mData);
00304 
00305     char* result = (char*) nsMemory::Clone(buf,
00306                                 (strlen(buf)+1)*sizeof(char));
00307     *_retval = result;
00308     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00309 }  
00310 
00311 /***************************************************************************/
00312 
00313 NS_IMPL_ISUPPORTS2(nsSupportsPRUint32Impl, nsISupportsPRUint32,
00314                    nsISupportsPrimitive)
00315 
00316 nsSupportsPRUint32Impl::nsSupportsPRUint32Impl()
00317     : mData(0)
00318 {
00319 }
00320 
00321 NS_IMETHODIMP nsSupportsPRUint32Impl::GetType(PRUint16 *aType)
00322 {
00323     NS_ASSERTION(aType, "Bad pointer");
00324     *aType = TYPE_PRUINT32;
00325 
00326     return NS_OK;
00327 }
00328 
00329 NS_IMETHODIMP nsSupportsPRUint32Impl::GetData(PRUint32 *aData)
00330 {
00331     NS_ASSERTION(aData, "Bad pointer");
00332     *aData = mData;
00333     return NS_OK;
00334 }
00335 
00336 NS_IMETHODIMP nsSupportsPRUint32Impl::SetData(PRUint32 aData)
00337 {
00338     mData = aData;
00339     return NS_OK;
00340 }
00341 
00342 NS_IMETHODIMP nsSupportsPRUint32Impl::ToString(char **_retval)
00343 {
00344     NS_ASSERTION(_retval, "Bad pointer");
00345     static const int size = 16;
00346     char buf[size];
00347 
00348     PR_snprintf(buf, size, "%lu", mData);
00349 
00350     char* result = (char*) nsMemory::Clone(buf,
00351                                 (strlen(buf)+1)*sizeof(char));
00352     *_retval = result;
00353     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00354 }  
00355 
00356 /***************************************************************************/
00357 
00358 NS_IMPL_ISUPPORTS2(nsSupportsPRUint64Impl, nsISupportsPRUint64,
00359                    nsISupportsPrimitive)
00360 
00361 nsSupportsPRUint64Impl::nsSupportsPRUint64Impl()
00362     : mData(LL_ZERO)
00363 {
00364 }
00365 
00366 NS_IMETHODIMP nsSupportsPRUint64Impl::GetType(PRUint16 *aType)
00367 {
00368     NS_ASSERTION(aType, "Bad pointer");
00369     *aType = TYPE_PRUINT64;
00370 
00371     return NS_OK;
00372 }
00373 
00374 NS_IMETHODIMP nsSupportsPRUint64Impl::GetData(PRUint64 *aData)
00375 {
00376     NS_ASSERTION(aData, "Bad pointer");
00377     *aData = mData;
00378     return NS_OK;
00379 }
00380 
00381 NS_IMETHODIMP nsSupportsPRUint64Impl::SetData(PRUint64 aData)
00382 {
00383     mData = aData;
00384     return NS_OK;
00385 }
00386 
00387 NS_IMETHODIMP nsSupportsPRUint64Impl::ToString(char **_retval)
00388 {
00389     NS_ASSERTION(_retval, "Bad pointer");
00390     static const int size = 32;
00391     char buf[size];
00392 
00393     PR_snprintf(buf, size, "%llu", mData);
00394 
00395     char* result = (char*) nsMemory::Clone(buf,
00396                                 (strlen(buf)+1)*sizeof(char));
00397     *_retval = result;
00398     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00399 }  
00400 
00401 /***************************************************************************/
00402 
00403 NS_IMPL_ISUPPORTS2(nsSupportsPRTimeImpl, nsISupportsPRTime,
00404                    nsISupportsPrimitive)
00405 
00406 nsSupportsPRTimeImpl::nsSupportsPRTimeImpl()
00407     : mData(LL_ZERO)
00408 {
00409 }
00410 
00411 NS_IMETHODIMP nsSupportsPRTimeImpl::GetType(PRUint16 *aType)
00412 {
00413     NS_ASSERTION(aType, "Bad pointer");
00414     *aType = TYPE_PRTIME;
00415 
00416     return NS_OK;
00417 }
00418 
00419 NS_IMETHODIMP nsSupportsPRTimeImpl::GetData(PRTime *aData)
00420 {
00421     NS_ASSERTION(aData, "Bad pointer");
00422     *aData = mData;
00423     return NS_OK;
00424 }
00425 
00426 NS_IMETHODIMP nsSupportsPRTimeImpl::SetData(PRTime aData)
00427 {
00428     mData = aData;
00429     return NS_OK;
00430 }
00431 
00432 NS_IMETHODIMP nsSupportsPRTimeImpl::ToString(char **_retval)
00433 {
00434     NS_ASSERTION(_retval, "Bad pointer");
00435     static const int size = 32;
00436     char buf[size];
00437 
00438     PR_snprintf(buf, size, "%llu", mData);
00439 
00440     char* result = (char*) nsMemory::Clone(buf,
00441                                 (strlen(buf)+1)*sizeof(char));
00442     *_retval = result;
00443     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00444 }  
00445 
00446 /***************************************************************************/
00447 
00448 NS_IMPL_ISUPPORTS2(nsSupportsCharImpl, nsISupportsChar,
00449                    nsISupportsPrimitive)
00450 
00451 nsSupportsCharImpl::nsSupportsCharImpl()
00452     : mData(0)
00453 {
00454 }
00455 
00456 NS_IMETHODIMP nsSupportsCharImpl::GetType(PRUint16 *aType)
00457 {
00458     NS_ASSERTION(aType, "Bad pointer");
00459     *aType = TYPE_CHAR;
00460 
00461     return NS_OK;
00462 }
00463 
00464 NS_IMETHODIMP nsSupportsCharImpl::GetData(char *aData)
00465 {
00466     NS_ASSERTION(aData, "Bad pointer");
00467     *aData = mData;
00468     return NS_OK;
00469 }
00470 
00471 NS_IMETHODIMP nsSupportsCharImpl::SetData(char aData)
00472 {
00473     mData = aData;
00474     return NS_OK;
00475 }
00476 
00477 NS_IMETHODIMP nsSupportsCharImpl::ToString(char **_retval)
00478 {
00479     char* result;
00480     NS_ASSERTION(_retval, "Bad pointer");
00481 
00482     if(nsnull != (result = (char*) nsMemory::Alloc(2*sizeof(char))))
00483     {
00484         result[0] = mData;
00485         result[1] = '\0';
00486     }
00487     *_retval = result;
00488     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00489 }  
00490 
00491 /***************************************************************************/
00492 
00493 NS_IMPL_ISUPPORTS2(nsSupportsPRInt16Impl, nsISupportsPRInt16,
00494                    nsISupportsPrimitive)
00495 
00496 nsSupportsPRInt16Impl::nsSupportsPRInt16Impl()
00497     : mData(0)
00498 {
00499 }
00500 
00501 NS_IMETHODIMP nsSupportsPRInt16Impl::GetType(PRUint16 *aType)
00502 {
00503     NS_ASSERTION(aType, "Bad pointer");
00504     *aType = TYPE_PRINT16;
00505 
00506     return NS_OK;
00507 }
00508 
00509 NS_IMETHODIMP nsSupportsPRInt16Impl::GetData(PRInt16 *aData)
00510 {
00511     NS_ASSERTION(aData, "Bad pointer");
00512     *aData = mData;
00513     return NS_OK;
00514 }
00515 
00516 NS_IMETHODIMP nsSupportsPRInt16Impl::SetData(PRInt16 aData)
00517 {
00518     mData = aData;
00519     return NS_OK;
00520 }
00521 
00522 NS_IMETHODIMP nsSupportsPRInt16Impl::ToString(char **_retval)
00523 {
00524     NS_ASSERTION(_retval, "Bad pointer");
00525     static const int size = 8;
00526     char buf[size];
00527 
00528     PR_snprintf(buf, size, "%d", mData);
00529 
00530     char* result = (char*) nsMemory::Clone(buf,
00531                                 (strlen(buf)+1)*sizeof(char));
00532     *_retval = result;
00533     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00534 }  
00535 
00536 /***************************************************************************/
00537 
00538 NS_IMPL_ISUPPORTS2(nsSupportsPRInt32Impl, nsISupportsPRInt32,
00539                    nsISupportsPrimitive)
00540 
00541 nsSupportsPRInt32Impl::nsSupportsPRInt32Impl()
00542     : mData(0)
00543 {
00544 }
00545 
00546 NS_IMETHODIMP nsSupportsPRInt32Impl::GetType(PRUint16 *aType)
00547 {
00548     NS_ASSERTION(aType, "Bad pointer");
00549     *aType = TYPE_PRINT32;
00550 
00551     return NS_OK;
00552 }
00553 
00554 NS_IMETHODIMP nsSupportsPRInt32Impl::GetData(PRInt32 *aData)
00555 {
00556     NS_ASSERTION(aData, "Bad pointer");
00557     *aData = mData;
00558     return NS_OK;
00559 }
00560 
00561 NS_IMETHODIMP nsSupportsPRInt32Impl::SetData(PRInt32 aData)
00562 {
00563     mData = aData;
00564     return NS_OK;
00565 }
00566 
00567 NS_IMETHODIMP nsSupportsPRInt32Impl::ToString(char **_retval)
00568 {
00569     NS_ASSERTION(_retval, "Bad pointer");
00570     static const int size = 16;
00571     char buf[size];
00572 
00573     PR_snprintf(buf, size, "%ld", mData);
00574 
00575     char* result = (char*) nsMemory::Clone(buf,
00576                                 (strlen(buf)+1)*sizeof(char));
00577     *_retval = result;
00578     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00579 }  
00580 
00581 /***************************************************************************/
00582 
00583 NS_IMPL_ISUPPORTS2(nsSupportsPRInt64Impl, nsISupportsPRInt64,
00584                    nsISupportsPrimitive)
00585 
00586 nsSupportsPRInt64Impl::nsSupportsPRInt64Impl()
00587     : mData(LL_ZERO)
00588 {
00589 }
00590 
00591 NS_IMETHODIMP nsSupportsPRInt64Impl::GetType(PRUint16 *aType)
00592 {
00593     NS_ASSERTION(aType, "Bad pointer");
00594     *aType = TYPE_PRINT64;
00595 
00596     return NS_OK;
00597 }
00598 
00599 NS_IMETHODIMP nsSupportsPRInt64Impl::GetData(PRInt64 *aData)
00600 {
00601     NS_ASSERTION(aData, "Bad pointer");
00602     *aData = mData;
00603     return NS_OK;
00604 }
00605 
00606 NS_IMETHODIMP nsSupportsPRInt64Impl::SetData(PRInt64 aData)
00607 {
00608     mData = aData;
00609     return NS_OK;
00610 }
00611 
00612 NS_IMETHODIMP nsSupportsPRInt64Impl::ToString(char **_retval)
00613 {
00614     NS_ASSERTION(_retval, "Bad pointer");
00615     static const int size = 32;
00616     char buf[size];
00617 
00618     PR_snprintf(buf, size, "%lld", mData);
00619 
00620     char* result = (char*) nsMemory::Clone(buf,
00621                                 (strlen(buf)+1)*sizeof(char));
00622     *_retval = result;
00623     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00624 }  
00625 
00626 /***************************************************************************/
00627 
00628 NS_IMPL_ISUPPORTS2(nsSupportsFloatImpl, nsISupportsFloat,
00629                    nsISupportsPrimitive)
00630 
00631 nsSupportsFloatImpl::nsSupportsFloatImpl()
00632     : mData(float(0.0))
00633 {
00634 }
00635 
00636 NS_IMETHODIMP nsSupportsFloatImpl::GetType(PRUint16 *aType)
00637 {
00638     NS_ASSERTION(aType, "Bad pointer");
00639     *aType = TYPE_FLOAT;
00640 
00641     return NS_OK;
00642 }
00643 
00644 NS_IMETHODIMP nsSupportsFloatImpl::GetData(float *aData)
00645 {
00646     NS_ASSERTION(aData, "Bad pointer");
00647     *aData = mData;
00648     return NS_OK;
00649 }
00650 
00651 NS_IMETHODIMP nsSupportsFloatImpl::SetData(float aData)
00652 {
00653     mData = aData;
00654     return NS_OK;
00655 }
00656 
00657 NS_IMETHODIMP nsSupportsFloatImpl::ToString(char **_retval)
00658 {
00659     NS_ASSERTION(_retval, "Bad pointer");
00660     static const int size = 32;
00661     char buf[size];
00662 
00663     PR_snprintf(buf, size, "%f", (double) mData);
00664 
00665     char* result = (char*) nsMemory::Clone(buf,
00666                                 (strlen(buf)+1)*sizeof(char));
00667     *_retval = result;
00668     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00669 }  
00670 
00671 /***************************************************************************/
00672 
00673 NS_IMPL_ISUPPORTS2(nsSupportsDoubleImpl, nsISupportsDouble,
00674                    nsISupportsPrimitive)
00675 
00676 nsSupportsDoubleImpl::nsSupportsDoubleImpl()
00677     : mData(double(0.0))
00678 {
00679 }
00680 
00681 NS_IMETHODIMP nsSupportsDoubleImpl::GetType(PRUint16 *aType)
00682 {
00683     NS_ASSERTION(aType, "Bad pointer");
00684     *aType = TYPE_DOUBLE;
00685 
00686     return NS_OK;
00687 }
00688 
00689 NS_IMETHODIMP nsSupportsDoubleImpl::GetData(double *aData)
00690 {
00691     NS_ASSERTION(aData, "Bad pointer");
00692     *aData = mData;
00693     return NS_OK;
00694 }
00695 
00696 NS_IMETHODIMP nsSupportsDoubleImpl::SetData(double aData)
00697 {
00698     mData = aData;
00699     return NS_OK;
00700 }
00701 
00702 NS_IMETHODIMP nsSupportsDoubleImpl::ToString(char **_retval)
00703 {
00704     NS_ASSERTION(_retval, "Bad pointer");
00705     static const int size = 32;
00706     char buf[size];
00707 
00708     PR_snprintf(buf, size, "%f", mData);
00709 
00710     char* result = (char*) nsMemory::Clone(buf,
00711                                 (strlen(buf)+1)*sizeof(char));
00712     *_retval = result;
00713     return  result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00714 }  
00715 
00716 /***************************************************************************/
00717 
00718 
00719 NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsVoidImpl, nsISupportsVoid,
00720                               nsISupportsPrimitive)
00721 
00722 nsSupportsVoidImpl::nsSupportsVoidImpl()
00723     : mData(nsnull)
00724 {
00725 }
00726 
00727 NS_IMETHODIMP nsSupportsVoidImpl::GetType(PRUint16 *aType)
00728 {
00729     NS_ASSERTION(aType, "Bad pointer");
00730     *aType = TYPE_VOID;
00731 
00732     return NS_OK;
00733 }
00734 
00735 NS_IMETHODIMP nsSupportsVoidImpl::GetData(void * *aData)
00736 {
00737     NS_ASSERTION(aData, "Bad pointer");
00738     *aData = mData;
00739     return NS_OK;
00740 }
00741 
00742 NS_IMETHODIMP nsSupportsVoidImpl::SetData(void * aData)
00743 {
00744     mData = aData;
00745     return NS_OK;
00746 }
00747 
00748 NS_IMETHODIMP nsSupportsVoidImpl::ToString(char **_retval)
00749 {
00750     NS_ASSERTION(_retval, "Bad pointer");
00751 
00752     static const char str[] = "[raw data]";
00753     char* result = (char*) nsMemory::Clone(str, sizeof(str));
00754     *_retval = result;
00755     return  result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00756 }  
00757 
00758 /***************************************************************************/
00759 
00760 
00761 NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsInterfacePointerImpl,
00762                               nsISupportsInterfacePointer,
00763                               nsISupportsPrimitive)
00764 
00765 nsSupportsInterfacePointerImpl::nsSupportsInterfacePointerImpl()
00766     : mIID(nsnull)
00767 {
00768 }
00769 
00770 nsSupportsInterfacePointerImpl::~nsSupportsInterfacePointerImpl()
00771 {
00772     if (mIID) {
00773         nsMemory::Free(mIID);
00774     }
00775 }
00776 
00777 NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetType(PRUint16 *aType)
00778 {
00779     NS_ASSERTION(aType, "Bad pointer");
00780     *aType = TYPE_INTERFACE_POINTER;
00781 
00782     return NS_OK;
00783 }
00784 
00785 NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetData(nsISupports **aData)
00786 {
00787     NS_ASSERTION(aData,"Bad pointer");
00788 
00789     *aData = mData;
00790     NS_IF_ADDREF(*aData);
00791 
00792     return NS_OK;
00793 }
00794 
00795 NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetData(nsISupports * aData)
00796 {
00797     mData = aData;
00798 
00799     return NS_OK;
00800 }
00801 
00802 NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetDataIID(nsID **aIID)
00803 {
00804     NS_ASSERTION(aIID,"Bad pointer");
00805 
00806     if(mIID)
00807     {
00808         *aIID = (nsID*) nsMemory::Clone(mIID, sizeof(nsID));
00809         return *aIID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00810     }
00811     *aIID = nsnull;
00812     return NS_OK;
00813 }
00814 
00815 NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetDataIID(const nsID *aIID)
00816 {
00817     if(mIID)
00818         nsMemory::Free(mIID);
00819     if(aIID)
00820         mIID = (nsID*) nsMemory::Clone(aIID, sizeof(nsID));
00821     else
00822         mIID = nsnull;
00823 
00824     return NS_OK;
00825 }
00826 
00827 NS_IMETHODIMP nsSupportsInterfacePointerImpl::ToString(char **_retval)
00828 {
00829     NS_ASSERTION(_retval, "Bad pointer");
00830 
00831     static const char str[] = "[interface pointer]";
00832 
00833     // jband sez: think about asking nsIInterfaceInfoManager whether
00834     // the interface has a known human-readable name
00835     char* result = (char*) nsMemory::Clone(str, sizeof(str));
00836     *_retval = result;
00837     return  result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00838 }
00839 
00840 /***************************************************************************/
00841 
00842 NS_IMPL_ISUPPORTS2(nsSupportsDependentCString,nsISupportsCString,nsISupportsPrimitive)
00843 
00844 nsSupportsDependentCString::nsSupportsDependentCString(const char* aStr)
00845     : mData(aStr)
00846 { }
00847 
00848 NS_IMETHODIMP
00849 nsSupportsDependentCString::GetType(PRUint16 *aType)
00850 {
00851     NS_ENSURE_ARG_POINTER(aType);
00852 
00853     *aType = TYPE_CSTRING;
00854     return NS_OK;
00855 }
00856 
00857 NS_IMETHODIMP
00858 nsSupportsDependentCString::GetData(nsACString& aData)
00859 {
00860     aData = mData;
00861     return NS_OK;
00862 }
00863 
00864 NS_IMETHODIMP
00865 nsSupportsDependentCString::ToString(char **_retval)
00866 {
00867     NS_ENSURE_ARG_POINTER(_retval);
00868 
00869     *_retval = ToNewCString(mData);
00870     if (!*_retval)
00871         return NS_ERROR_OUT_OF_MEMORY;
00872     
00873     return NS_OK;
00874 }
00875 
00876 NS_IMETHODIMP
00877 nsSupportsDependentCString::SetData(const nsACString& aData)
00878 {
00879     return NS_ERROR_NOT_IMPLEMENTED;
00880 }