From 4820f93b6aa07cbd5d7bb01cf51461e79a2bcafb Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Fri, 6 Dec 1996 22:26:36 +0000 Subject: [PATCH] added auto cleanup of installed classes to destroy --- src/cxxTemplates/resourceLib.cc | 25 +++++++++++++++++++++++-- src/cxxTemplates/resourceLib.h | 11 +++++++++-- src/libCom/cxxTemplates/resourceLib.h | 11 +++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/cxxTemplates/resourceLib.cc b/src/cxxTemplates/resourceLib.cc index c6d1228dc..797f93cf9 100644 --- a/src/cxxTemplates/resourceLib.cc +++ b/src/cxxTemplates/resourceLib.cc @@ -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::destroyAllEntries() while (pList<&this->pTable[this->hashIdMask+1]) { tsSLIter 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 after it was destroyed\n"); + // + // remove defective class + // + iter.remove(); this->nInUse--; } pList++; diff --git a/src/cxxTemplates/resourceLib.h b/src/cxxTemplates/resourceLib.h index 42f85249b..9c0f7641d 100644 --- a/src/cxxTemplates/resourceLib.h +++ b/src/cxxTemplates/resourceLib.h @@ -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 resTable { public: @@ -80,9 +87,9 @@ public: ~resTable() { - assert (this->nInUse == 0u); - if (this->pTable) { + this->destroyAllEntries(); + assert (this->nInUse == 0u); delete [] this->pTable; } } diff --git a/src/libCom/cxxTemplates/resourceLib.h b/src/libCom/cxxTemplates/resourceLib.h index 42f85249b..9c0f7641d 100644 --- a/src/libCom/cxxTemplates/resourceLib.h +++ b/src/libCom/cxxTemplates/resourceLib.h @@ -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 resTable { public: @@ -80,9 +87,9 @@ public: ~resTable() { - assert (this->nInUse == 0u); - if (this->pTable) { + this->destroyAllEntries(); + assert (this->nInUse == 0u); delete [] this->pTable; } }