nsValueArray needs a ReplaceValueAt()
r=bsmedberg sr=alecf
This commit is contained in:
cst%yecc.com 2006-06-06 13:26:26 +00:00
Родитель 60d9d2a397
Коммит 6b66156a30
2 изменённых файлов: 34 добавлений и 1 удалений

Просмотреть файл

@ -199,7 +199,7 @@ PRBool nsValueArray::InsertValueAt(nsValueArrayValue aValue, nsValueArrayIndex a
NS_ASSERTION(*((PRUint32*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!");
break;
default:
NS_ASSERTION(0, "surely you've been warned prior to this!");
NS_ERROR("surely you've been warned prior to this!");
break;
}
@ -213,6 +213,37 @@ PRBool nsValueArray::InsertValueAt(nsValueArrayValue aValue, nsValueArrayIndex a
return retval;
}
//
// Replace the item at aIndex with aValue
// No validity checking other than index is done.
//
PRBool nsValueArray::ReplaceValueAt(nsValueArrayValue aValue, nsValueArrayIndex aIndex) {
NS_ENSURE_TRUE(aIndex < Count(), PR_FALSE);
//
// Do the assignment.
//
switch (mBytesPerValue) {
case sizeof(PRUint8):
*((PRUint8*)&mValueArray[aIndex * mBytesPerValue]) = (PRUint8)aValue;
NS_ASSERTION(*((PRUint8*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!");
break;
case sizeof(PRUint16):
*((PRUint16*)&mValueArray[aIndex * mBytesPerValue]) = (PRUint16)aValue;
NS_ASSERTION(*((PRUint16*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!");
break;
case sizeof(PRUint32):
*((PRUint32*)&mValueArray[aIndex * mBytesPerValue]) = (PRUint32)aValue;
NS_ASSERTION(*((PRUint32*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!");
break;
default:
NS_ERROR("surely you've been warned prior to this!");
break;
}
return PR_TRUE;
}
//
// Remove the index from the value array.
// The array does not shrink until Compact() is invoked.

Просмотреть файл

@ -110,6 +110,8 @@ class NS_COM nsValueArray {
PRBool InsertValueAt(nsValueArrayValue aValue, nsValueArrayIndex aIndex);
PRBool ReplaceValueAt(nsValueArrayValue aValue, nsValueArrayIndex aIndex);
PRBool RemoveValueAt(nsValueArrayIndex aIndex);
//