sbVariant.cpp File Reference
#include "sbVariant.h"
#include <nsStringAPI.h>
#include <prprf.h>
#include <prdtoa.h>
#include <math.h>
#include <nsAutoLock.h>
#include <nsCRT.h>
#include <sbMemoryUtils.h>
Include dependency graph for sbVariant.cpp:

Go to the source code of this file.

Macros

#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__APPENDDOUBLE_NUMBER(type_, member_)
 
#define CASE__SMPRINTF_NUMBER(type_, format_, cast_, member_)
 
#define DATA_SETTER_PROLOGUE(data_)   sbVariant::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 void Modified_cnvtf (char *buf, int bufsz, int prcsn, double fval)
 
static nsresult String2Double (const char *aString, double *retval)
 
static nsresult AString2Double (const nsAString &aString, double *retval)
 
static nsresult AUTF8String2Double (const nsACString &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_IMPL_THREADSAFE_ISUPPORTS2 (sbVariant, nsIVariant, nsIWritableVariant) sbVariant
 
 NS_IMETHODIMP_ (nsresult) sbVariant
 

Macro Definition Documentation

#define CASE__APPENDDOUBLE_NUMBER (   type_,
  member_ 
)
Value:
case nsIDataType :: type_ : \
{ \
char buf[40]; \
Modified_cnvtf(buf, sizeof(buf), 15, data.u. member_); \
outString.Assign(buf); \
}
return NS_OK
static void Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)
Definition: sbVariant.cpp:53
return
Definition: FeedWriter.js:850
observe data
Definition: FeedWriter.js:1329
#define CASE__APPENDFLOAT_NUMBER (   type_,
  member_ 
)
Value:
case nsIDataType :: type_ : \
{ \
char buf[40]; \
Modified_cnvtf(buf, sizeof(buf), 6, data.u. member_); \
outString.Assign(buf); \
}
return NS_OK
static void Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)
Definition: sbVariant.cpp:53
return
Definition: FeedWriter.js:850
observe data
Definition: FeedWriter.js:1329
#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; \
}
if(DEBUG_DATAREMOTES)
observe data
Definition: FeedWriter.js:1329
_getSelectedPageStyle s i
#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) \
NS_Free((char*)*p); \
break; \
}
if(DEBUG_DATAREMOTES)
observe data
Definition: FeedWriter.js:1329
_getSelectedPageStyle s i
#define CASE__NUMBER_INT32 (   type_,
  member_ 
)
Value:
case nsIDataType :: type_ : \
outData->u.mInt32Value = inData.u. member_ ; \
outData->mType = nsIDataType::VTYPE_INT32; \
return NS_OK
return
Definition: FeedWriter.js:850
#define CASE__NUMERIC_CONVERSION_DOUBLE_JUST_CAST (   Ctype_)
Value:
case nsIDataType::VTYPE_DOUBLE: \
*_retval = ( Ctype_ ) tempData.u.mDoubleValue; \
return rv;

Definition at line 630 of file sbVariant.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; \
}
return
Definition: FeedWriter.js:850
countRef value
Definition: FeedWriter.js:1423
if(DEBUG_DATAREMOTES)

Definition at line 635 of file sbVariant.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; \
}
return
Definition: FeedWriter.js:850
countRef value
Definition: FeedWriter.js:1423
if(DEBUG_DATAREMOTES)

Definition at line 645 of file sbVariant.cpp.

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

Definition at line 600 of file sbVariant.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; \
}
return
Definition: FeedWriter.js:850
countRef value
Definition: FeedWriter.js:1423
if(DEBUG_DATAREMOTES)

Definition at line 605 of file sbVariant.cpp.

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

Definition at line 615 of file sbVariant.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; \
}
return
Definition: FeedWriter.js:850
countRef value
Definition: FeedWriter.js:1423
if(DEBUG_DATAREMOTES)

Definition at line 620 of file sbVariant.cpp.

#define CASE__SET_FROM_VARIANT_TYPE (   type_,
  member_,
  name_ 
)
Value:
case nsIDataType :: type_ : \
#define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
Definition: sbVariant.cpp:1377
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER(member_, name_)
Definition: sbVariant.cpp:1371
#define CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_)
Definition: sbVariant.cpp:1368

Definition at line 1385 of file sbVariant.cpp.

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

Definition at line 1371 of file sbVariant.cpp.

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

Definition at line 1374 of file sbVariant.cpp.

#define CASE__SET_FROM_VARIANT_VTYPE_CAST (   type_,
  cast_,
  member_,
  name_ 
)
Value:
case nsIDataType :: type_ : \
#define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(type_)
Definition: sbVariant.cpp:1377
#define CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(type_)
Definition: sbVariant.cpp:1368
#define CASE__SET_FROM_VARIANT_VTYPE__GETTER_CAST(cast_, member_, name_)
Definition: sbVariant.cpp:1374

Definition at line 1391 of file sbVariant.cpp.

#define CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE (   type_)
Value:
if(NS_SUCCEEDED(rv)) \
{ \
data->mType = nsIDataType :: type_ ; \
} \
break; \
}
observe data
Definition: FeedWriter.js:1329

Definition at line 1377 of file sbVariant.cpp.

#define CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE (   type_)    { \

Definition at line 1368 of file sbVariant.cpp.

#define CASE__SMPRINTF_NUMBER (   type_,
  format_,
  cast_,
  member_ 
)
Value:
case nsIDataType :: type_ : \
ptr = PR_smprintf( format_ , (cast_) data.u. member_ ); \
break;
observe data
Definition: FeedWriter.js:1329
#define CASES__NUMERIC_CONVERSION_NORMAL (   Ctype_,
  min_,
  max_ 
)
Value:
#define CASE__NUMERIC_CONVERSION_INT32_MIN_MAX(Ctype_, min_, max_)
Definition: sbVariant.cpp:605
#define CASE__NUMERIC_CONVERSION_UINT32_MAX(Ctype_, max_)
Definition: sbVariant.cpp:620
#define CASE__NUMERIC_CONVERSION_DOUBLE_MIN_MAX_INT(Ctype_, min_, max_)
Definition: sbVariant.cpp:645

Definition at line 656 of file sbVariant.cpp.

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

Definition at line 1355 of file sbVariant.cpp.

#define DATA_SETTER_EPILOGUE (   data_,
  type_ 
)
Value:
data_->mType = nsIDataType :: type_; \
return NS_OK
return
Definition: FeedWriter.js:850

Definition at line 1351 of file sbVariant.cpp.

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

Definition at line 1348 of file sbVariant.cpp.

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

Definition at line 1360 of file sbVariant.cpp.

#define NUMERIC_CONVERSION_METHOD_BEGIN (   type_,
  Ctype_,
  name_ 
)
Value:
/* static */ nsresult \
sbVariant::ConvertTo##name_ (const nsDiscriminatedUnion& data, \
Ctype_ *_retval) \
{ \
TRIVIAL_DATA_CONVERTER(type_, data, m##name_##Value, _retval) \
nsDiscriminatedUnion 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)) \
switch(tempData.mType) \
{
switch(this._getFeedType())
Definition: FeedWriter.js:802
static nsresult ToManageableNumber(const nsDiscriminatedUnion &inData, nsDiscriminatedUnion *outData)
Definition: sbVariant.cpp:171
#define TRIVIAL_DATA_CONVERTER(type_, data_, member_, retval_)
Definition: sbVariant.cpp:575
static nsresult Initialize(nsDiscriminatedUnion *data)
Definition: sbVariant.cpp:1706
return
Definition: FeedWriter.js:850
if(DEBUG_DATAREMOTES)
observe data
Definition: FeedWriter.js:1329

Definition at line 581 of file sbVariant.cpp.

#define NUMERIC_CONVERSION_METHOD_END
Value:
default: \
NS_ERROR("bad type returned from ToManageableNumber"); \
return NS_ERROR_CANNOT_CONVERT_DATA; \
} \
}
return
Definition: FeedWriter.js:850

Definition at line 661 of file sbVariant.cpp.

#define NUMERIC_CONVERSION_METHOD_NORMAL (   type_,
  Ctype_,
  name_,
  min_,
  max_ 
)
Value:
NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_) \
#define CASES__NUMERIC_CONVERSION_NORMAL(Ctype_, min_, max_)
Definition: sbVariant.cpp:656
#define NUMERIC_CONVERSION_METHOD_BEGIN(type_, Ctype_, name_)
Definition: sbVariant.cpp:581
#define NUMERIC_CONVERSION_METHOD_END
Definition: sbVariant.cpp:661

Definition at line 668 of file sbVariant.cpp.

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

Definition at line 575 of file sbVariant.cpp.

Function Documentation

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

Definition at line 164 of file sbVariant.cpp.

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 149 of file sbVariant.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult AUTF8String2Double ( const nsACString &  aString,
double *  retval 
)
static

Definition at line 159 of file sbVariant.cpp.

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 348 of file sbVariant.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static void FreeArray ( nsDiscriminatedUnion data)
static

Definition at line 275 of file sbVariant.cpp.

Here is the caller graph for this function:

static void Modified_cnvtf ( char *  buf,
int  bufsz,
int  prcsn,
double  fval 
)
static

This is a copy of |PR_cnvtf| with a bug fixed. (The second argument of PR_dtoa is 2 rather than 1.)

XXX(darin): if this is the right thing, then why wasn't it fixed in NSPR?!?

Definition at line 53 of file sbVariant.cpp.

Here is the call graph for this function:

NS_IMETHODIMP_ ( nsresult  )

Definition at line 1954 of file sbVariant.cpp.

Here is the call graph for this function:

NS_IMPL_THREADSAFE_ISUPPORTS2 ( sbVariant  ,
nsIVariant  ,
nsIWritableVariant   
)

Definition at line 1786 of file sbVariant.cpp.

Here is the call graph for this function:

static nsresult String2Double ( const char *  aString,
double *  retval 
)
static

Definition at line 139 of file sbVariant.cpp.

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 790 of file sbVariant.cpp.

Here is the caller graph for this function:

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

Definition at line 171 of file sbVariant.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 861 of file sbVariant.cpp.

Here is the caller graph for this function: