Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsVariant.cpp File Reference
#include "nsVariant.h"
#include "nsString.h"
#include "prprf.h"
#include "prdtoa.h"
#include <math.h>
#include "nsCRT.h"

Go to the source code of this file.

Defines

#define CASE__NUMBER_INT32(type_, member_)
#define CASE__FREE_ARRAY_PTR(type_, ctype_)
#define CASE__FREE_ARRAY_IFACE(type_, ctype_)
#define TRIVIAL_DATA_CONVERTER(type_, data_, member_, retval_)
#define NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_)
#define CASE__NUMERIC_CONVERSION_INT32_JUST_CAST(Ctype_)
#define CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_)
#define CASE__NUMERIC_CONVERSION_UINT32_JUST_CAST(Ctype_)
#define CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_)
#define CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST(Ctype_)
#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX(Ctype_, min_, max_)
#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_)
#define CASES__NUMERIC_CONVERSION_NORMAL(Ctype_, min_, max_)
#define NUMERIC_CONVERSION_METHOD_END
#define NUMERIC_CONVERSION_METHOD_NORMAL(type_, Ctype_, name_, min_, max_)
#define CASE__APPENDFLOAT_NUMBER(type_, member_)
#define CASE__SMPRINTF_NUMBER(type_, format_, cast_, member_)
#define DATA_SETTER_PROLOGUE(data_)   nsVariant::Cleanup(data_);
#define DATA_SETTER_EPILOGUE(data_, type_)
#define DATA_SETTER(data_, type_, member_, value_)
#define DATA_SETTER_WITH_CAST(data_, type_, member_, cast_, value_)
#define CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_)   { \
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_)   rv = aValue->GetAs##name_ (&(data->u. member_ ));
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_)   rv = aValue->GetAs##name_ ( cast_ &(data->u. member_ ));
#define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
#define CASE__SET_FROM_VARIANT_TYPE(type_, member_, name_)
#define CASE__SET_FROM_VARIANT_VTYPE_CAST(type_, cast_, member_, name_)

Functions

static nsresult String2Double (const char *aString, double *retval)
static nsresult AString2Double (const nsAString &aString, double *retval)
static nsresult AUTF8String2Double (const nsAUTF8String &aString, double *retval)
static nsresult ACString2Double (const nsACString &aString, double *retval)
static nsresult ToManageableNumber (const nsDiscriminatedUnion &inData, nsDiscriminatedUnion *outData)
static void FreeArray (nsDiscriminatedUnion *data)
static nsresult CloneArray (PRUint16 inType, const nsIID *inIID, PRUint32 inCount, void *inValue, PRUint16 *outType, nsIID *outIID, PRUint32 *outCount, void **outValue)
static PRBool String2ID (const nsDiscriminatedUnion &data, nsID *pid)
static nsresult ToString (const nsDiscriminatedUnion &data, nsACString &outString)
 NS_IMETHODIMP_ (nsresult) nsVariant

Define Documentation

#define CASE__APPENDFLOAT_NUMBER (   type_,
  member_ 
)
Value:
case nsIDataType :: type_ :                                         \
    {                                                                   \
        nsCAutoString str;                                              \
        str.AppendFloat(data.u. member_);                               \
        outString.Assign(str);                                          \
        return NS_OK;                                                   \
    }
#define CASE__FREE_ARRAY_IFACE (   type_,
  ctype_ 
)
Value:
case nsIDataType:: type_ :                                            \
        {                                                                     \
            ctype_ ** p = (ctype_ **) data->u.array.mArrayValue;              \
            for(PRUint32 i = data->u.array.mArrayCount; i > 0; p++, i--)      \
                if(*p)                                                        \
                    (*p)->Release();                                          \
            break;                                                            \
        }
#define CASE__FREE_ARRAY_PTR (   type_,
  ctype_ 
)
Value:
case nsIDataType:: type_ :                                            \
        {                                                                     \
            ctype_ ** p = (ctype_ **) data->u.array.mArrayValue;              \
            for(PRUint32 i = data->u.array.mArrayCount; i > 0; p++, i--)      \
                if(*p)                                                        \
                    nsMemory::Free((char*)*p);                                \
            break;                                                            \
        }
#define CASE__NUMBER_INT32 (   type_,
  member_ 
)
Value:
case nsIDataType :: type_ :                                               \
        outData->u.mInt32Value = inData.u. member_ ;                          \
        outData->mType = nsIDataType::VTYPE_INT32;                            \
        return NS_OK;
Value:
case nsIDataType::VTYPE_DOUBLE:                                           \
        *_retval = ( Ctype_ ) tempData.u.mDoubleValue;                        \
        return rv;

Definition at line 543 of file nsVariant.cpp.

#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX (   Ctype_,
  min_,
  max_ 
)
Value:
case nsIDataType::VTYPE_DOUBLE:                                           \
    {                                                                         \
        double value = tempData.u.mDoubleValue;                               \
        if(value < min_ || value > max_)                                      \
            return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;                         \
        *_retval = ( Ctype_ ) value;                                          \
        return rv;                                                            \
    }

Definition at line 548 of file nsVariant.cpp.

#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT (   Ctype_,
  min_,
  max_ 
)
Value:
case nsIDataType::VTYPE_DOUBLE:                                           \
    {                                                                         \
        double value = tempData.u.mDoubleValue;                               \
        if(value < min_ || value > max_)                                      \
            return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;                         \
        *_retval = ( Ctype_ ) value;                                          \
        return (0.0 == fmod(value,1.0)) ?                                     \
            rv : NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;                       \
    }

Definition at line 558 of file nsVariant.cpp.

Value:
case nsIDataType::VTYPE_INT32:                                            \
        *_retval = ( Ctype_ ) tempData.u.mInt32Value;                         \
        return rv;

Definition at line 513 of file nsVariant.cpp.

#define CASE__NUMERIC_CONVERSION_INT32_MIN_MAX (   Ctype_,
  min_,
  max_ 
)
Value:
case nsIDataType::VTYPE_INT32:                                            \
    {                                                                         \
        PRInt32 value = tempData.u.mInt32Value;                               \
        if(value < min_ || value > max_)                                      \
            return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;                         \
        *_retval = ( Ctype_ ) value;                                          \
        return rv;                                                            \
    }

Definition at line 518 of file nsVariant.cpp.

Value:
case nsIDataType::VTYPE_UINT32:                                           \
        *_retval = ( Ctype_ ) tempData.u.mUint32Value;                        \
        return rv;

Definition at line 528 of file nsVariant.cpp.

#define CASE__NUMERIC_CONVERSION_UINT32_MAX (   Ctype_,
  max_ 
)
Value:
case nsIDataType::VTYPE_UINT32:                                           \
    {                                                                         \
        PRUint32 value = tempData.u.mUint32Value;                             \
        if(value > max_)                                                      \
            return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;                         \
        *_retval = ( Ctype_ ) value;                                          \
        return rv;                                                            \
    }

Definition at line 533 of file nsVariant.cpp.

#define CASE__SET_FROM_VARIANT_TYPE (   type_,
  member_,
  name_ 
)
Value:
case nsIDataType :: type_ :                                               \
        CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_)                          \
        CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_)                  \
        CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)

Definition at line 1284 of file nsVariant.cpp.

#define CASE__SET_FROM_VARIANT_VTYPE__GETTER (   member_,
  name_ 
)    rv = aValue->GetAs##name_ (&(data->u. member_ ));

Definition at line 1270 of file nsVariant.cpp.

#define CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST (   cast_,
  member_,
  name_ 
)    rv = aValue->GetAs##name_ ( cast_ &(data->u. member_ ));

Definition at line 1273 of file nsVariant.cpp.

#define CASE__SET_FROM_VARIANT_VTYPE_CAST (   type_,
  cast_,
  member_,
  name_ 
)
Value:
case nsIDataType :: type_ :                                               \
        CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_)                          \
        CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_)      \
        CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)

Definition at line 1290 of file nsVariant.cpp.

Value:
if(NS_SUCCEEDED(rv))                                                  \
        {                                                                     \
            data->mType  = nsIDataType :: type_ ;                             \
        }                                                                     \
        break;                                                                \
    }

Definition at line 1276 of file nsVariant.cpp.

Definition at line 1267 of file nsVariant.cpp.

#define CASE__SMPRINTF_NUMBER (   type_,
  format_,
  cast_,
  member_ 
)
Value:
case nsIDataType :: type_ :                                               \
        ptr = PR_smprintf( format_ , (cast_) data.u. member_ );               \
        break;
#define CASES__NUMERIC_CONVERSION_NORMAL (   Ctype_,
  min_,
  max_ 
)
Value:
CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_)                \
    CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_)                         \
    CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_)

Definition at line 569 of file nsVariant.cpp.

#define DATA_SETTER (   data_,
  type_,
  member_,
  value_ 
)
Value:
DATA_SETTER_PROLOGUE(data_)                                               \
    data_->u.member_ = value_;                                                \
    DATA_SETTER_EPILOGUE(data_, type_)

Definition at line 1254 of file nsVariant.cpp.

#define DATA_SETTER_EPILOGUE (   data_,
  type_ 
)
Value:
data_->mType = nsIDataType :: type_;                                      \
    return NS_OK;

Definition at line 1250 of file nsVariant.cpp.

#define DATA_SETTER_PROLOGUE (   data_)    nsVariant::Cleanup(data_);

Definition at line 1247 of file nsVariant.cpp.

#define DATA_SETTER_WITH_CAST (   data_,
  type_,
  member_,
  cast_,
  value_ 
)
Value:
DATA_SETTER_PROLOGUE(data_)                                               \
    data_->u.member_ = cast_ value_;                                          \
    DATA_SETTER_EPILOGUE(data_, type_)

Definition at line 1259 of file nsVariant.cpp.

#define NUMERIC_CONVERSION_METHOD_BEGIN (   type_,
  Ctype_,
  name_ 
)
Value:
/* static */ nsresult                                                         \
nsVariant::ConvertTo##name_ (const nsDiscriminatedUnion& data,                \
                             Ctype_ *_retval)                                 \
{                                                                             \
    TRIVIAL_DATA_CONVERTER(type_, data, m##name_##Value, _retval)             \
    nsDiscriminatedUnion tempData;                                            \
    nsVariant::Initialize(&tempData);                                         \
    nsresult rv = ToManageableNumber(data, &tempData);                        \
    /*                                                                     */ \
    /* NOTE: rv may indicate a success code that we want to preserve       */ \
    /* For the final return. So all the return cases below should return   */ \
    /* this rv when indicating success.                                    */ \
    /*                                                                     */ \
    if(NS_FAILED(rv))                                                         \
        return rv;                                                            \
    switch(tempData.mType)                                                    \
    {

Definition at line 494 of file nsVariant.cpp.

Value:
default:                                                                  \
        NS_ERROR("bad type returned from ToManageableNumber");                \
        return NS_ERROR_CANNOT_CONVERT_DATA;                                  \
    }                                                                         \
}

Definition at line 574 of file nsVariant.cpp.

#define NUMERIC_CONVERSION_METHOD_NORMAL (   type_,
  Ctype_,
  name_,
  min_,
  max_ 
)
Value:
NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_)                     \
        CASES__NUMERIC_CONVERSION_NORMAL(Ctype_, min_, max_)                  \
    NUMERIC_CONVERSION_METHOD_END

Definition at line 581 of file nsVariant.cpp.

#define TRIVIAL_DATA_CONVERTER (   type_,
  data_,
  member_,
  retval_ 
)
Value:
if(data_.mType == nsIDataType :: type_) {                                 \
        *retval_ = data_.u.member_;                                           \
        return NS_OK;                                                         \
    }

Definition at line 488 of file nsVariant.cpp.


Function Documentation

static nsresult ACString2Double ( const nsACString &  aString,
double *  retval 
) [static]

Definition at line 77 of file nsVariant.cpp.

{
    return String2Double(PromiseFlatCString(aString).get(), retval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult AString2Double ( const nsAString &  aString,
double *  retval 
) [static]

Definition at line 62 of file nsVariant.cpp.

{
    char* pChars = ToNewCString(aString);
    if(!pChars)
        return NS_ERROR_OUT_OF_MEMORY;
    nsresult rv = String2Double(pChars, retval);
    nsMemory::Free(pChars);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult AUTF8String2Double ( const nsAUTF8String aString,
double *  retval 
) [static]

Definition at line 72 of file nsVariant.cpp.

{
    return String2Double(PromiseFlatUTF8String(aString).get(), retval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult CloneArray ( PRUint16  inType,
const nsIID inIID,
PRUint32  inCount,
void inValue,
PRUint16 outType,
nsIID outIID,
PRUint32 outCount,
void **  outValue 
) [static]

Definition at line 261 of file nsVariant.cpp.

{
    NS_ASSERTION(inCount, "bad param");
    NS_ASSERTION(inValue, "bad param");
    NS_ASSERTION(outType, "bad param");
    NS_ASSERTION(outCount, "bad param");
    NS_ASSERTION(outValue, "bad param");

    PRUint32 allocatedValueCount = 0;
    nsresult rv = NS_OK;
    PRUint32 i;

    // First we figure out the size of the elements for the new u.array.

    size_t elementSize;
    size_t allocSize;

    switch(inType)
    {
        case nsIDataType::VTYPE_INT8:
            elementSize = sizeof(PRInt8);
            break;
        case nsIDataType::VTYPE_INT16:
            elementSize = sizeof(PRInt16);
            break;
        case nsIDataType::VTYPE_INT32:
            elementSize = sizeof(PRInt32);
            break;
        case nsIDataType::VTYPE_INT64:
            elementSize = sizeof(PRInt64);
            break;
        case nsIDataType::VTYPE_UINT8:
            elementSize = sizeof(PRUint8);
            break;
        case nsIDataType::VTYPE_UINT16:
            elementSize = sizeof(PRUint16);
            break;
        case nsIDataType::VTYPE_UINT32:
            elementSize = sizeof(PRUint32);
            break;
        case nsIDataType::VTYPE_UINT64:
            elementSize = sizeof(PRUint64);
            break;
        case nsIDataType::VTYPE_FLOAT:
            elementSize = sizeof(float);
            break;
        case nsIDataType::VTYPE_DOUBLE:
            elementSize = sizeof(double);
            break;
        case nsIDataType::VTYPE_BOOL:
            elementSize = sizeof(PRBool);
            break;
        case nsIDataType::VTYPE_CHAR:
            elementSize = sizeof(char);
            break;
        case nsIDataType::VTYPE_WCHAR:
            elementSize = sizeof(PRUnichar);
            break;

        // XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
        case nsIDataType::VTYPE_ID:
        case nsIDataType::VTYPE_CHAR_STR:
        case nsIDataType::VTYPE_WCHAR_STR:
        case nsIDataType::VTYPE_INTERFACE:
        case nsIDataType::VTYPE_INTERFACE_IS:
            elementSize = sizeof(void*);
            break;

        // The rest are illegal.
        case nsIDataType::VTYPE_ASTRING:
        case nsIDataType::VTYPE_DOMSTRING:
        case nsIDataType::VTYPE_UTF8STRING:
        case nsIDataType::VTYPE_CSTRING:
        case nsIDataType::VTYPE_STRING_SIZE_IS:
        case nsIDataType::VTYPE_WSTRING_SIZE_IS:
        case nsIDataType::VTYPE_VOID:
        case nsIDataType::VTYPE_ARRAY:
        case nsIDataType::VTYPE_EMPTY_ARRAY:
        case nsIDataType::VTYPE_EMPTY:
        default:
            NS_ERROR("bad type in array!");
            return NS_ERROR_CANNOT_CONVERT_DATA;
    }


    // Alloc the u.array.

    allocSize = inCount * elementSize;
    *outValue = nsMemory::Alloc(allocSize);
    if(!*outValue)
        return NS_ERROR_OUT_OF_MEMORY;

    // Clone the elements.

    switch(inType)
    {
        case nsIDataType::VTYPE_INT8:
        case nsIDataType::VTYPE_INT16:
        case nsIDataType::VTYPE_INT32:
        case nsIDataType::VTYPE_INT64:
        case nsIDataType::VTYPE_UINT8:
        case nsIDataType::VTYPE_UINT16:
        case nsIDataType::VTYPE_UINT32:
        case nsIDataType::VTYPE_UINT64:
        case nsIDataType::VTYPE_FLOAT:
        case nsIDataType::VTYPE_DOUBLE:
        case nsIDataType::VTYPE_BOOL:
        case nsIDataType::VTYPE_CHAR:
        case nsIDataType::VTYPE_WCHAR:
            memcpy(*outValue, inValue, allocSize);
            break;

        case nsIDataType::VTYPE_INTERFACE_IS:
            if(outIID)
                *outIID = *inIID;
            // fall through...
        case nsIDataType::VTYPE_INTERFACE:
        {
            memcpy(*outValue, inValue, allocSize);

            nsISupports** p = (nsISupports**) *outValue;
            for(i = inCount; i > 0; p++, i--)
                if(*p)
                    (*p)->AddRef();
            break;
        }

        // XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
        case nsIDataType::VTYPE_ID:
        {
            nsID** inp  = (nsID**) inValue;
            nsID** outp = (nsID**) *outValue;
            for(i = inCount; i > 0; i--)
            {
                nsID* idp = *(inp++);
                if(idp)
                {
                    if(nsnull == (*(outp++) = (nsID*)
                       nsMemory::Clone((char*)idp, sizeof(nsID))))
                        goto bad;
                }
                else
                    *(outp++) = nsnull;
                allocatedValueCount++;
            }
            break;
        }

        case nsIDataType::VTYPE_CHAR_STR:
        {
            char** inp  = (char**) inValue;
            char** outp = (char**) *outValue;
            for(i = inCount; i > 0; i--)
            {
                char* str = *(inp++);
                if(str)
                {
                    if(nsnull == (*(outp++) = (char*)
                       nsMemory::Clone(str, (strlen(str)+1)*sizeof(char))))
                        goto bad;
                }
                else
                    *(outp++) = nsnull;
                allocatedValueCount++;
            }
            break;
        }

        case nsIDataType::VTYPE_WCHAR_STR:
        {
            PRUnichar** inp  = (PRUnichar**) inValue;
            PRUnichar** outp = (PRUnichar**) *outValue;
            for(i = inCount; i > 0; i--)
            {
                PRUnichar* str = *(inp++);
                if(str)
                {
                    if(nsnull == (*(outp++) = (PRUnichar*)
                       nsMemory::Clone(str,
                        (nsCRT::strlen(str)+1)*sizeof(PRUnichar))))
                        goto bad;
                }
                else
                    *(outp++) = nsnull;
                allocatedValueCount++;
            }
            break;
        }

        // The rest are illegal.
        case nsIDataType::VTYPE_VOID:
        case nsIDataType::VTYPE_ARRAY:
        case nsIDataType::VTYPE_EMPTY_ARRAY:
        case nsIDataType::VTYPE_EMPTY:
        case nsIDataType::VTYPE_ASTRING:
        case nsIDataType::VTYPE_DOMSTRING:
        case nsIDataType::VTYPE_UTF8STRING:
        case nsIDataType::VTYPE_CSTRING:
        case nsIDataType::VTYPE_STRING_SIZE_IS:
        case nsIDataType::VTYPE_WSTRING_SIZE_IS:
        default:
            NS_ERROR("bad type in array!");
            return NS_ERROR_CANNOT_CONVERT_DATA;
    }

    *outType = inType;
    *outCount = inCount;
    return NS_OK;

bad:
    if(*outValue)
    {
        char** p = (char**) *outValue;
        for(i = allocatedValueCount; i > 0; p++, i--)
            if(*p)
                nsMemory::Free(*p);
        nsMemory::Free((char*)*outValue);
        *outValue = nsnull;
    }
    return rv;
}

Here is the call graph for this function:

static void FreeArray ( nsDiscriminatedUnion data) [static]

Definition at line 188 of file nsVariant.cpp.

{
    NS_ASSERTION(data->mType == nsIDataType::VTYPE_ARRAY, "bad FreeArray call");
    NS_ASSERTION(data->u.array.mArrayValue, "bad array");
    NS_ASSERTION(data->u.array.mArrayCount, "bad array count");

#define CASE__FREE_ARRAY_PTR(type_, ctype_)                                   \
        case nsIDataType:: type_ :                                            \
        {                                                                     \
            ctype_ ** p = (ctype_ **) data->u.array.mArrayValue;              \
            for(PRUint32 i = data->u.array.mArrayCount; i > 0; p++, i--)      \
                if(*p)                                                        \
                    nsMemory::Free((char*)*p);                                \
            break;                                                            \
        }

#define CASE__FREE_ARRAY_IFACE(type_, ctype_)                                 \
        case nsIDataType:: type_ :                                            \
        {                                                                     \
            ctype_ ** p = (ctype_ **) data->u.array.mArrayValue;              \
            for(PRUint32 i = data->u.array.mArrayCount; i > 0; p++, i--)      \
                if(*p)                                                        \
                    (*p)->Release();                                          \
            break;                                                            \
        }

    switch(data->u.array.mArrayType)
    {
        case nsIDataType::VTYPE_INT8:
        case nsIDataType::VTYPE_INT16:
        case nsIDataType::VTYPE_INT32:
        case nsIDataType::VTYPE_INT64:
        case nsIDataType::VTYPE_UINT8:
        case nsIDataType::VTYPE_UINT16:
        case nsIDataType::VTYPE_UINT32:
        case nsIDataType::VTYPE_UINT64:
        case nsIDataType::VTYPE_FLOAT:
        case nsIDataType::VTYPE_DOUBLE:
        case nsIDataType::VTYPE_BOOL:
        case nsIDataType::VTYPE_CHAR:
        case nsIDataType::VTYPE_WCHAR:
            break;

        // XXX We ASSUME that "array of nsID" means "array of pointers to nsID".
        CASE__FREE_ARRAY_PTR(VTYPE_ID, nsID)
        CASE__FREE_ARRAY_PTR(VTYPE_CHAR_STR, char)
        CASE__FREE_ARRAY_PTR(VTYPE_WCHAR_STR, PRUnichar)
        CASE__FREE_ARRAY_IFACE(VTYPE_INTERFACE, nsISupports)
        CASE__FREE_ARRAY_IFACE(VTYPE_INTERFACE_IS, nsISupports)

        // The rest are illegal.
        case nsIDataType::VTYPE_VOID:
        case nsIDataType::VTYPE_ASTRING:
        case nsIDataType::VTYPE_DOMSTRING:
        case nsIDataType::VTYPE_UTF8STRING:
        case nsIDataType::VTYPE_CSTRING:
        case nsIDataType::VTYPE_WSTRING_SIZE_IS:
        case nsIDataType::VTYPE_STRING_SIZE_IS:
        case nsIDataType::VTYPE_ARRAY:
        case nsIDataType::VTYPE_EMPTY_ARRAY:
        case nsIDataType::VTYPE_EMPTY:
        default:
            NS_ERROR("bad type in array!");
            break;
    }

    // Free the array memory.
    nsMemory::Free((char*)data->u.array.mArrayValue);

#undef CASE__FREE_ARRAY_PTR
#undef CASE__FREE_ARRAY_IFACE
}

Definition at line 1810 of file nsVariant.cpp.

{
    return nsVariant::ConvertToID(mData, retval);
}
static nsresult String2Double ( const char *  aString,
double *  retval 
) [static]

Definition at line 52 of file nsVariant.cpp.

{
    char* next;
    double value = PR_strtod(aString, &next);
    if(next == aString)
        return NS_ERROR_CANNOT_CONVERT_DATA;
    *retval = value;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool String2ID ( const nsDiscriminatedUnion data,
nsID pid 
) [static]

Definition at line 703 of file nsVariant.cpp.

{
    nsAutoString tempString;
    nsAString* pString;

    switch(data.mType)
    {
        case nsIDataType::VTYPE_CHAR_STR:
        case nsIDataType::VTYPE_STRING_SIZE_IS:
            return pid->Parse(data.u.str.mStringValue);
        case nsIDataType::VTYPE_CSTRING:
            return pid->Parse(PromiseFlatCString(*data.u.mCStringValue).get());
        case nsIDataType::VTYPE_UTF8STRING:
            return pid->Parse(PromiseFlatUTF8String(*data.u.mUTF8StringValue).get());
        case nsIDataType::VTYPE_ASTRING:
        case nsIDataType::VTYPE_DOMSTRING:
            pString = data.u.mAStringValue;
            break;
        case nsIDataType::VTYPE_WCHAR_STR:
        case nsIDataType::VTYPE_WSTRING_SIZE_IS:
            tempString.Assign(data.u.wstr.mWStringValue);
            pString = &tempString;
            break;
        default:
            NS_ERROR("bad type in call to String2ID");
            return PR_FALSE;
    }

    char* pChars = ToNewCString(*pString);
    if(!pChars)
        return PR_FALSE;
    PRBool result = pid->Parse(pChars);
    nsMemory::Free(pChars);
    return result;
}

Here is the call graph for this function:

static nsresult ToManageableNumber ( const nsDiscriminatedUnion inData,
nsDiscriminatedUnion outData 
) [static]

Definition at line 84 of file nsVariant.cpp.

{
    nsresult rv;

    switch(inData.mType)
    {
    // This group results in a PRInt32...

#define CASE__NUMBER_INT32(type_, member_)                                    \
    case nsIDataType :: type_ :                                               \
        outData->u.mInt32Value = inData.u. member_ ;                          \
        outData->mType = nsIDataType::VTYPE_INT32;                            \
        return NS_OK;

    CASE__NUMBER_INT32(VTYPE_INT8,   mInt8Value)
    CASE__NUMBER_INT32(VTYPE_INT16,  mInt16Value)
    CASE__NUMBER_INT32(VTYPE_INT32,  mInt32Value)
    CASE__NUMBER_INT32(VTYPE_UINT8,  mUint8Value)
    CASE__NUMBER_INT32(VTYPE_UINT16, mUint16Value)
    CASE__NUMBER_INT32(VTYPE_BOOL,   mBoolValue)
    CASE__NUMBER_INT32(VTYPE_CHAR,   mCharValue)
    CASE__NUMBER_INT32(VTYPE_WCHAR,  mWCharValue)

#undef CASE__NUMBER_INT32

    // This group results in a PRUint32...

    case nsIDataType::VTYPE_UINT32:
        outData->u.mInt32Value = inData.u.mUint32Value;
        outData->mType = nsIDataType::VTYPE_INT32;
        return NS_OK;

    // This group results in a double...

    case nsIDataType::VTYPE_INT64:
    case nsIDataType::VTYPE_UINT64:
        // XXX Need boundary checking here.
        // We may need to return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA
        LL_L2D(outData->u.mDoubleValue, inData.u.mInt64Value);
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;
    case nsIDataType::VTYPE_FLOAT:
        outData->u.mDoubleValue = inData.u.mFloatValue;
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;
    case nsIDataType::VTYPE_DOUBLE:
        outData->u.mDoubleValue = inData.u.mDoubleValue;
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;
    case nsIDataType::VTYPE_CHAR_STR:
    case nsIDataType::VTYPE_STRING_SIZE_IS:
        rv = String2Double(inData.u.str.mStringValue, &outData->u.mDoubleValue);
        if(NS_FAILED(rv))
            return rv;
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;
    case nsIDataType::VTYPE_DOMSTRING:
    case nsIDataType::VTYPE_ASTRING:
        rv = AString2Double(*inData.u.mAStringValue, &outData->u.mDoubleValue);
        if(NS_FAILED(rv))
            return rv;
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;
    case nsIDataType::VTYPE_UTF8STRING:
        rv = AUTF8String2Double(*inData.u.mUTF8StringValue,
                                &outData->u.mDoubleValue);
        if(NS_FAILED(rv))
            return rv;
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;
    case nsIDataType::VTYPE_CSTRING:
        rv = ACString2Double(*inData.u.mCStringValue,
                             &outData->u.mDoubleValue);
        if(NS_FAILED(rv))
            return rv;
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;
    case nsIDataType::VTYPE_WCHAR_STR:
    case nsIDataType::VTYPE_WSTRING_SIZE_IS:
        rv = AString2Double(nsDependentString(inData.u.wstr.mWStringValue),
                            &outData->u.mDoubleValue);
        if(NS_FAILED(rv))
            return rv;
        outData->mType = nsIDataType::VTYPE_DOUBLE;
        return NS_OK;

    // This group fails...

    case nsIDataType::VTYPE_VOID:
    case nsIDataType::VTYPE_ID:
    case nsIDataType::VTYPE_INTERFACE:
    case nsIDataType::VTYPE_INTERFACE_IS:
    case nsIDataType::VTYPE_ARRAY:
    case nsIDataType::VTYPE_EMPTY_ARRAY:
    case nsIDataType::VTYPE_EMPTY:
    default:
        return NS_ERROR_CANNOT_CONVERT_DATA;
    }
}

Here is the call graph for this function:

static nsresult ToString ( const nsDiscriminatedUnion data,
nsACString &  outString 
) [static]

Definition at line 774 of file nsVariant.cpp.

{
    char* ptr;

    switch(data.mType)
    {
    // all the stuff we don't handle...
    case nsIDataType::VTYPE_ASTRING:
    case nsIDataType::VTYPE_DOMSTRING:
    case nsIDataType::VTYPE_UTF8STRING:
    case nsIDataType::VTYPE_CSTRING:
    case nsIDataType::VTYPE_CHAR_STR:
    case nsIDataType::VTYPE_WCHAR_STR:
    case nsIDataType::VTYPE_STRING_SIZE_IS:
    case nsIDataType::VTYPE_WSTRING_SIZE_IS:
    case nsIDataType::VTYPE_WCHAR:
        NS_ERROR("ToString being called for a string type - screwy logic!");
        // fall through...

    // XXX We might want stringified versions of these... ???

    case nsIDataType::VTYPE_VOID:
    case nsIDataType::VTYPE_EMPTY:
        outString.Truncate();
        outString.SetIsVoid(true);
        return NS_OK;

    case nsIDataType::VTYPE_EMPTY_ARRAY:
    case nsIDataType::VTYPE_ARRAY:
    case nsIDataType::VTYPE_INTERFACE:
    case nsIDataType::VTYPE_INTERFACE_IS:
    default:
        return NS_ERROR_CANNOT_CONVERT_DATA;

    // nsID has its own text formater.

    case nsIDataType::VTYPE_ID:
        ptr = data.u.mIDValue.ToString();
        if(!ptr)
            return NS_ERROR_OUT_OF_MEMORY;
        outString.Assign(ptr);
        nsMemory::Free(ptr);
        return NS_OK;

    // Can't use PR_smprintf for floats, since it's locale-dependent
#define CASE__APPENDFLOAT_NUMBER(type_, member_)                        \
    case nsIDataType :: type_ :                                         \
    {                                                                   \
        nsCAutoString str;                                              \
        str.AppendFloat(data.u. member_);                               \
        outString.Assign(str);                                          \
        return NS_OK;                                                   \
    }

    CASE__APPENDFLOAT_NUMBER(VTYPE_FLOAT,  mFloatValue)
    CASE__APPENDFLOAT_NUMBER(VTYPE_DOUBLE, mDoubleValue)

#undef CASE__APPENDFLOAT_NUMBER

    // the rest can be PR_smprintf'd and use common code.

#define CASE__SMPRINTF_NUMBER(type_, format_, cast_, member_)                 \
    case nsIDataType :: type_ :                                               \
        ptr = PR_smprintf( format_ , (cast_) data.u. member_ );               \
        break;

    CASE__SMPRINTF_NUMBER(VTYPE_INT8,   "%d",   int,      mInt8Value)
    CASE__SMPRINTF_NUMBER(VTYPE_INT16,  "%d",   int,      mInt16Value)
    CASE__SMPRINTF_NUMBER(VTYPE_INT32,  "%d",   int,      mInt32Value)
    CASE__SMPRINTF_NUMBER(VTYPE_INT64,  "%lld", PRInt64,  mInt64Value)

    CASE__SMPRINTF_NUMBER(VTYPE_UINT8,  "%u",   unsigned, mUint8Value)
    CASE__SMPRINTF_NUMBER(VTYPE_UINT16, "%u",   unsigned, mUint16Value)
    CASE__SMPRINTF_NUMBER(VTYPE_UINT32, "%u",   unsigned, mUint32Value)
    CASE__SMPRINTF_NUMBER(VTYPE_UINT64, "%llu", PRInt64,  mUint64Value)

    // XXX Would we rather print "true" / "false" ?
    CASE__SMPRINTF_NUMBER(VTYPE_BOOL,   "%d",   int,      mBoolValue)

    CASE__SMPRINTF_NUMBER(VTYPE_CHAR,   "%c",   char,     mCharValue)

#undef CASE__SMPRINTF_NUMBER
    }

    if(!ptr)
        return NS_ERROR_OUT_OF_MEMORY;
    outString.Assign(ptr);
    PR_smprintf_free(ptr);
    return NS_OK;
}