/*! Generate a value given an integer, using formatting defined within this class. The formatting mainly applies if formatting as a string. For example, was is the number base? should a sign always be included? are leading zeros requried? The formatting could include properties related to other types. For example, generate an error if attempting to convert a negative integer to an unsigned integer. */ QVariant QCaIntegerFormatting::formatValue( const long &integerValue, generic::generic_types valueType ) { switch( valueType ) { case generic::DOUBLE : { QVariant dValue( (double)integerValue ); return dValue; } case generic::UNSIGNED_LONG : { qulonglong unsignedIntegerValue; ( integerValue < 0 ) ? unsignedIntegerValue=0 : unsignedIntegerValue=integerValue; QVariant ulValue( unsignedIntegerValue ); return ulValue; } case generic::STRING : { QString string = QString::number( integerValue, radix); QVariant sValue( string ); return sValue; } case generic::UNKNOWN : { } default : { //qDebug() << "QCaIntegerFormatting::formatValue() Unknown value 'Generic' type: " << valueType; QVariant unknown; return unknown; } } //qDebug() << "QCaIntegerFormatting::formatValue() Unknown value 'Generic' type: " << valueType; QVariant unknown; return unknown; }
bool UnixDb::put(const CssmData &key, const CssmData &value, int flags) { Data dKey(key); Data dValue(value); int rc = mDb->put(mDb, &dKey, &dValue, flags); secdebug("unixdb", "put(%p,[:%ld],[:%ld],flags=0x%x)=%d", mDb, key.length(), value.length(), flags, rc); checkError(rc); return !rc; }
/* Generate a value given a floating point number, using formatting defined within this class. The formatting mainly applies if formatting as a string. For example, was is the number base? should a sign always be included? are leading zeros requried? The formatting could include properties related to other types. For example, generate an error if attempting to convert a negative floating point number to an unsigned integer. */ QVariant QEFloatingFormatting::formatValue( const double &floatingValue, generic::generic_types valueType ) { switch( valueType ) { case generic::GENERIC_DOUBLE : case generic::GENERIC_FLOAT : { QVariant dValue( floatingValue ); return dValue; } case generic::GENERIC_LONG : { qlonglong integerValue; if( floatingValue < (double)LONG_MIN ) integerValue = LONG_MIN; else if( floatingValue > (double)LONG_MAX ) integerValue = LONG_MAX; else integerValue = (qlonglong)floatingValue; QVariant lValue( integerValue ); return lValue; } case generic::GENERIC_SHORT : { qlonglong integerValue; if( floatingValue < (double)SHRT_MIN ) integerValue = SHRT_MIN; else if( floatingValue > (double)SHRT_MAX ) integerValue = SHRT_MAX; else integerValue = (qlonglong)floatingValue; QVariant lValue( integerValue ); return lValue; } case generic::GENERIC_UNSIGNED_LONG : { qulonglong unsignedIntegerValue; if( floatingValue < 0 ) unsignedIntegerValue = 0; else if( floatingValue > (double)ULONG_MAX ) unsignedIntegerValue = ULONG_MAX; else unsignedIntegerValue = (qulonglong)floatingValue; QVariant ulValue( unsignedIntegerValue ); return ulValue; } case generic::GENERIC_UNSIGNED_SHORT : { qulonglong unsignedIntegerValue; if( floatingValue < 0 ) unsignedIntegerValue = 0; else if( floatingValue > (double)USHRT_MAX ) unsignedIntegerValue = USHRT_MAX; else unsignedIntegerValue = (qulonglong)floatingValue; QVariant ulValue( unsignedIntegerValue ); return ulValue; } case generic::GENERIC_UNSIGNED_CHAR : { qulonglong unsignedIntegerValue; if( floatingValue < 0 ) unsignedIntegerValue = 0; else if( floatingValue > (double)UCHAR_MAX ) unsignedIntegerValue = UCHAR_MAX; else unsignedIntegerValue = (qulonglong)floatingValue; QVariant ulValue( unsignedIntegerValue ); return ulValue; } case generic::GENERIC_STRING : { QString string = QString::number( floatingValue, getFormatChar(), precision ); QVariant sValue( string ); return sValue; } case generic::GENERIC_UNKNOWN : { } default : { //qDebug() << "QEFloatingFormatting::formatValue() Unknown value 'Generic' type: " << valueType; QVariant unknown; return unknown; } } //qDebug() << "QEFloatingFormatting::formatValue() Unknown value 'Generic' type: " << valueType; QVariant unknown; return unknown; }