30 #include <nsAutoPtr.h>
58 const char *fmt = nsnull;
90 const char *fmt = nsnull;
117 NS_INTERFACE_TABLE_BEGIN
120 NS_INTERFACE_TABLE_END
123 sbNumberPropertyInfo::sbNumberPropertyInfo()
124 : mMinMaxValueLock(nsnull)
125 , mMinValue(LL_MININT)
126 , mMaxValue(LL_MAXINT)
127 , mMinFloatValue(DBL_MIN)
128 , mMaxFloatValue(DBL_MAX)
129 , mHasSetMinValue(PR_FALSE)
130 , mHasSetMaxValue(PR_FALSE)
133 mType = NS_LITERAL_STRING(
"number");
135 mMinMaxValueLock = PR_NewLock();
136 NS_ASSERTION(mMinMaxValueLock,
137 "sbNumberPropertyInfo::mMinMaxValueLock failed to create lock!");
139 mRadixLock = PR_NewLock();
140 NS_ASSERTION(mRadixLock,
141 "sbNumberPropertyInfo::mRadixLock failed to create lock!");
159 NS_ENSURE_SUCCESS(rv, rv);
162 NS_ENSURE_SUCCESS(rv, rv);
172 nsRefPtr<sbPropertyOperator> propOp;
174 rv = sbPropertyInfo::GetOPERATOR_EQUALS(op);
175 NS_ENSURE_SUCCESS(rv, rv);
177 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
179 NS_ENSURE_SUCCESS(rv, rv);
181 rv = sbPropertyInfo::GetOPERATOR_NOTEQUALS(op);
182 NS_ENSURE_SUCCESS(rv, rv);
184 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
186 NS_ENSURE_SUCCESS(rv, rv);
188 rv = sbPropertyInfo::GetOPERATOR_GREATER(op);
189 NS_ENSURE_SUCCESS(rv, rv);
191 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
193 NS_ENSURE_SUCCESS(rv, rv);
195 rv = sbPropertyInfo::GetOPERATOR_GREATEREQUAL(op);
196 NS_ENSURE_SUCCESS(rv, rv);
198 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
200 NS_ENSURE_SUCCESS(rv, rv);
202 rv = sbPropertyInfo::GetOPERATOR_LESS(op);
203 NS_ENSURE_SUCCESS(rv, rv);
205 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
207 NS_ENSURE_SUCCESS(rv, rv);
209 rv = sbPropertyInfo::GetOPERATOR_LESSEQUAL(op);
210 NS_ENSURE_SUCCESS(rv, rv);
212 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
214 NS_ENSURE_SUCCESS(rv, rv);
216 rv = sbPropertyInfo::GetOPERATOR_BETWEEN(op);
217 NS_ENSURE_SUCCESS(rv, rv);
219 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
221 NS_ENSURE_SUCCESS(rv, rv);
228 NS_ENSURE_ARG_POINTER(_retval);
231 if (aValue.IsVoid()) {
236 PRFloat64 floatValue = 0;
238 NS_ConvertUTF16toUTF8 narrow(aValue);
247 nsAutoString ext_fmt;
248 ext_fmt.AssignLiteral(fmt);
249 ext_fmt += NS_LITERAL_STRING(
"%16s");
250 const char remainder[17]=
"";
253 r = PR_sscanf(narrow.get(),
254 NS_LossyConvertUTF16toASCII(ext_fmt).get(),
259 r = PR_sscanf(narrow.get(),
260 NS_LossyConvertUTF16toASCII(ext_fmt).get(),
274 if (*remainder != 0) {
304 return NS_ERROR_NOT_IMPLEMENTED;
310 PRFloat64 floatValue = 0;
312 NS_ConvertUTF16toUTF8 narrow(aValue);
315 _retval.StripWhitespace();
322 if(PR_sscanf(narrow.get(), fmt, &
value) != 1) {
323 _retval = EmptyString();
324 return NS_ERROR_INVALID_ARG;
328 if(PR_sscanf(narrow.get(), fmt, &floatValue) != 1) {
329 _retval = EmptyString();
330 return NS_ERROR_INVALID_ARG;
336 PR_snprintf(out, 64, fmt, value);
339 PR_snprintf(out, 64, fmt, floatValue);
342 NS_ConvertUTF8toUTF16 wide(out);
343 _retval = EmptyString();
346 _retval.AssignLiteral(
"0x");
349 _retval.AssignLiteral(
"0");
352 _retval.Append(wide);
361 if (aValue.IsVoid()) {
366 PRFloat64 floatValue = 0;
368 NS_ConvertUTF16toUTF8 narrow(aValue);
370 _retval.StripWhitespace();
375 PRInt32 parsedCount = 0;
378 parsedCount = PR_sscanf(narrow.get(), fmt, &
value);
381 parsedCount = PR_sscanf(narrow.get(), fmt, &floatValue);
384 if(parsedCount != 1) {
385 _retval = EmptyString();
386 return NS_ERROR_INVALID_ARG;
390 PRUint32 outputLength = 0;
395 outputLength = PR_snprintf(out, 64, sortableFmt, value);
398 outputLength = PR_snprintf(out, 64, sortableFmt, floatValue);
401 if(outputLength == (PRUint32)-1) {
402 rv = NS_ERROR_FAILURE;
403 _retval = EmptyString();
406 NS_ConvertUTF8toUTF16 wide(out);
414 NS_IMETHODIMP sbNumberPropertyInfo::GetMinValue(PRInt64 *aMinValue)
416 NS_ENSURE_ARG_POINTER(aMinValue);
421 NS_IMETHODIMP sbNumberPropertyInfo::SetMinValue(PRInt64 aMinValue)
431 return NS_ERROR_ALREADY_INITIALIZED;
434 NS_IMETHODIMP sbNumberPropertyInfo::GetMaxValue(PRInt64 *aMaxValue)
436 NS_ENSURE_ARG_POINTER(aMaxValue);
441 NS_IMETHODIMP sbNumberPropertyInfo::SetMaxValue(PRInt64 aMaxValue)
451 return NS_ERROR_ALREADY_INITIALIZED;
454 NS_IMETHODIMP sbNumberPropertyInfo::GetMinFloatValue(PRFloat64 *aMinFloatValue)
456 NS_ENSURE_ARG_POINTER(aMinFloatValue);
461 NS_IMETHODIMP sbNumberPropertyInfo::SetMinFloatValue(PRFloat64 aMinFloatValue)
471 return NS_ERROR_ALREADY_INITIALIZED;
474 NS_IMETHODIMP sbNumberPropertyInfo::GetMaxFloatValue(PRFloat64 *aMaxFloatValue)
476 NS_ENSURE_ARG_POINTER(aMaxFloatValue);
481 NS_IMETHODIMP sbNumberPropertyInfo::SetMaxFloatValue(PRFloat64 aMaxFloatValue)
491 return NS_ERROR_ALREADY_INITIALIZED;
494 NS_IMETHODIMP sbNumberPropertyInfo::GetRadix(PRUint32 *aRadix)
496 NS_ENSURE_ARG_POINTER(aRadix);
502 NS_IMETHODIMP sbNumberPropertyInfo::SetRadix(PRUint32 aRadix)
504 NS_ENSURE_TRUE(
IsValidRadix(aRadix), NS_ERROR_INVALID_ARG);
const unsigned long RADIX_10
Signed decimal representation (eg. 14 decimal)
static PRBool IsValidRadix(PRUint32 aRadix)
static const char * gsFmtRadix16
NS_IMETHOD Sanitize(const nsAString &aValue, nsAString &_retval)
NS_IMETHOD Format(const nsAString &aValue, nsAString &_retval)
static const char * GetSortableFmtFromRadix(PRUint32 aRadix)
static const char * gsSortFmtFloat
The property information specific to numeric fields.
const unsigned long RADIX_8
Unsigned octal representation (eg. 16, or 14 decimal).
const unsigned long RADIX_16
Unsigned hex representation (eg. 0x0E, or 14 decimal)
PRLock * mMinMaxValueLock
NS_IMPL_RELEASE_INHERITED(sbNumberPropertyInfo, sbPropertyInfo)
NS_IMETHOD Validate(const nsAString &aValue, PRBool *_retval)
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
nsresult InitializeOperators()
static const char * gsSortFmtRadix10
static const char * gsFmtRadix10
static const char * gsSortFmtRadix8
NS_IMPL_ADDREF_INHERITED(sbNumberPropertyInfo, sbPropertyInfo)
nsCOMArray< sbIPropertyOperator > mOperators
NS_IMETHOD MakeSearchable(const nsAString &aValue, nsAString &_retval)
static const char * gsFmtRadix8
const unsigned long FLOAT
Signed floating point representation (eg. 14.89)
static const char * gsSortFmtRadix16
virtual ~sbNumberPropertyInfo()
static const char * GetFmtFromRadix(PRUint32 aRadix)
static const char * gsFmtFloat