added auto cleanup of installed classes to destroy

This commit is contained in:
Jeff Hill
1996-12-06 22:26:36 +00:00
parent eff915d837
commit 4820f93b6a
3 changed files with 41 additions and 6 deletions

View File

@@ -30,6 +30,9 @@
*
* History
* $Log$
* Revision 1.1 1996/11/02 01:07:48 jhill
* installed
*
*
* NOTES:
* .01 Storage for identifier must persist until an item is deleted
@@ -82,9 +85,27 @@ void resTable<T,ID>::destroyAllEntries()
while (pList<&this->pTable[this->hashIdMask+1]) {
tsSLIter<T> iter(*pList);
T *pItem;
while ( (pItem = iter()) ) {
iter.remove();
T *pNextItem;
pItem = iter();
while (pItem) {
pNextItem = iter();
delete pItem;
pItem = pNextItem;
}
//
// Check to see if a defective class is
// installed that does not remove itself
// from the table when it is destroyed.
//
iter.reset();
while ( (pItem=iter()) ) {
fprintf(stderr,
"Warning: Defective class still in resTable<T,ID> after it was destroyed\n");
//
// remove defective class
//
iter.remove();
this->nInUse--;
}
pList++;

View File

@@ -29,6 +29,9 @@
*
* History
* $Log$
* Revision 1.6 1996/11/02 01:07:17 jhill
* many improvements
*
* Revision 1.5 1996/09/04 19:57:06 jhill
* string id resource now copies id
*
@@ -68,6 +71,10 @@ typedef unsigned resTableIndex;
//
// class T must derive class ID
//
// NOTE: Classes installed into this table should have
// a virtual destructor so that the delete in ~resTable() will
// work correctly.
//
template <class T, class ID>
class resTable {
public:
@@ -80,9 +87,9 @@ public:
~resTable()
{
assert (this->nInUse == 0u);
if (this->pTable) {
this->destroyAllEntries();
assert (this->nInUse == 0u);
delete [] this->pTable;
}
}

View File

@@ -29,6 +29,9 @@
*
* History
* $Log$
* Revision 1.6 1996/11/02 01:07:17 jhill
* many improvements
*
* Revision 1.5 1996/09/04 19:57:06 jhill
* string id resource now copies id
*
@@ -68,6 +71,10 @@ typedef unsigned resTableIndex;
//
// class T must derive class ID
//
// NOTE: Classes installed into this table should have
// a virtual destructor so that the delete in ~resTable() will
// work correctly.
//
template <class T, class ID>
class resTable {
public:
@@ -80,9 +87,9 @@ public:
~resTable()
{
assert (this->nInUse == 0u);
if (this->pTable) {
this->destroyAllEntries();
assert (this->nInUse == 0u);
delete [] this->pTable;
}
}