Not part of regular build, a=leaf. Added the option to destroy objects
contained in the list, this feature checks for duplicates in the list before deleting. git-svn-id: svn://10.0.0.236/trunk@78251 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
* Keith Visco, kvisco@ziplink.net
|
||||
* -- original author.
|
||||
*
|
||||
* $Id: ArrayList.cpp,v 1.1 2000-03-02 09:19:32 kvisco%ziplink.net Exp $
|
||||
* $Id: ArrayList.cpp,v 1.2 2000-09-06 07:05:31 kvisco%ziplink.net Exp $
|
||||
*/
|
||||
|
||||
#include "ArrayList.h"
|
||||
@@ -116,6 +116,38 @@ void ArrayList::clear() {
|
||||
elementCount = 0;
|
||||
} //-- clear
|
||||
|
||||
/**
|
||||
* Removes all elements from the list
|
||||
* @param deleteObjects allows specifying whether or not to delete the TxObjects
|
||||
* that are currently in the list.
|
||||
* <BR />
|
||||
* Note: If object deletion is enabled this method will check for duplicate references
|
||||
* in the list to prevent possible seg faults and will therefore run slower than an algorithm
|
||||
* that doesn't check for duplicates.
|
||||
**/
|
||||
void ArrayList::clear(MBool deleteObjects) {
|
||||
|
||||
|
||||
if (deleteObjects) {
|
||||
for (int i = 0; i < elementCount; i++) {
|
||||
if (elements[i]) {
|
||||
TxObject* tmp = elements[i];
|
||||
elements[i] = 0;
|
||||
//-- check for duplicates to avoid attempting to free memory that
|
||||
//-- has already been freed
|
||||
int idx = i+1;
|
||||
for ( ; idx < elementCount; idx++) {
|
||||
if (elements[idx] == tmp) elements[idx] = 0;
|
||||
}
|
||||
delete tmp;
|
||||
}
|
||||
}
|
||||
elementCount = 0;
|
||||
}
|
||||
else clear();
|
||||
|
||||
} //-- clear(MBool);
|
||||
|
||||
/**
|
||||
* Returns true if the specified TxObject is contained in the list.
|
||||
* @param object the TxObject to search for
|
||||
|
||||
Reference in New Issue
Block a user