diff --git a/src/cxxTemplates/resourceLib.h b/src/cxxTemplates/resourceLib.h index 00d0c1b53..27d442376 100644 --- a/src/cxxTemplates/resourceLib.h +++ b/src/cxxTemplates/resourceLib.h @@ -50,6 +50,7 @@ #include #include #include +#include #include "tsSLList.h" #include "shareLib.h" @@ -57,6 +58,8 @@ typedef size_t resTableIndex; static const unsigned indexWidth = sizeof(resTableIndex)*CHAR_BIT; +template class resTableIter; + // // class resTable // @@ -103,8 +106,16 @@ static const unsigned indexWidth = sizeof(resTableIndex)*CHAR_BIT; // template class resTable { + friend class resTableIter; public: + // + // exceptions thrown + // + class epicsShareClass dynamicMemoryAllocationFailed {}; + class epicsShareClass entryDidntRespondToDestroyVirtualFunction {}; + class epicsShareClass sizeExceedsMaxIndexWidth {}; + resTable (unsigned nHashTableEntries); virtual ~resTable(); @@ -160,7 +171,7 @@ private: unsigned hashIdNBits; unsigned nInUse; - resTableIndex hash(const ID & idIn) const; + resTableIndex hash (const ID & idIn) const; T *find (tsSLList &list, const ID &idIn) const; @@ -171,6 +182,23 @@ private: // Some ID classes that work with the above template // +// +// class resTableIter +// +// an iterator for the resource table class +// +template +class resTableIter { +public: + resTableIter (const resTable &tableIn); + T * next (); + T * operator () (); +private: + tsSLIter iter; + unsigned index; + const resTable *pTable; +}; + // // class intId // @@ -250,6 +278,10 @@ private: class epicsShareClass stringId { public: + // + // exceptions + // + class epicsShareClass dynamicMemoryAllocationFailed {}; enum allocationType {copyString, refString}; @@ -275,33 +307,6 @@ private: static const unsigned char fastHashPermutedIndexSpace[256]; }; -// -// exceptions thrown by this library -// -class epicsShareClass resLib_resourceWithThatNameIsAlreadyInstalled -{ -public: - resLib_resourceWithThatNameIsAlreadyInstalled (); -}; - -class epicsShareClass resLib_dynamicMemoryAllocationFailed -{ -public: - resLib_dynamicMemoryAllocationFailed (); -}; - -class epicsShareClass resLib_entryDidntRespondToDestroyVirtualFunction -{ -public: - resLib_entryDidntRespondToDestroyVirtualFunction (); -}; - -class epicsShareClass resLib_sizeExceedsMaxIndexWidth -{ -public: - resLib_sizeExceedsMaxIndexWidth (); -}; - ///////////////////////////////////////////////// // resTable member functions ///////////////////////////////////////////////// @@ -326,7 +331,11 @@ resTable::resTable (unsigned nHashTableEntries) : } if ( nbits > ID::maxIndexBitWidth ) { - throw resLib_sizeExceedsMaxIndexWidth (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw sizeExceedsMaxIndexWidth (); +# endif } // @@ -343,7 +352,11 @@ resTable::resTable (unsigned nHashTableEntries) : this->nInUse = 0u; this->pTable = new tsSLList [1<pTable==0) { - throw resLib_dynamicMemoryAllocationFailed (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw dynamicMemoryAllocationFailed (); +# endif } } @@ -377,8 +390,7 @@ inline T * resTable::lookup (const ID &idIn) const template inline resTableIndex resTable::hash (const ID & idIn) const { - return idIn.hash(this->hashIdNBits) - & this->hashIdMask; + return idIn.hash (this->hashIdNBits) & this->hashIdMask; } // @@ -579,12 +591,54 @@ resTable::~resTable() if (this->pTable) { this->destroyAllEntries(); if (this->nInUse != 0u) { - throw resLib_entryDidntRespondToDestroyVirtualFunction (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw entryDidntRespondToDestroyVirtualFunction (); +# endif } delete [] this->pTable; } } +////////////////////////////////////////////// +// resTableIter member functions +////////////////////////////////////////////// + +// +// resTableIter::resTableIter () +// +template +inline resTableIter::resTableIter (const resTable &tableIn) : + iter (tableIn.pTable[0]), index (1), pTable (&tableIn) {} + +// +// resTableIter::next () +// +template +inline T * resTableIter::next () +{ + T *pNext = this->iter.next(); + if (pNext) { + return pNext; + } + if ( this->index >= (1u<table.hashIdNBits) ) { + return 0; + } + ; + this->iter = tsSLIter (this->pTable->pTable[this->index++]); + return this->iter.next (); +} + +// +// resTableIter::operator () () +// +template +inline T * resTableIter::operator () () +{ + return this->next (); +} + ////////////////////////////////////////////// // chronIntIdResTable member functions ////////////////////////////////////////////// @@ -771,7 +825,11 @@ stringId::stringId (const char * idIn, allocationType typeIn) : memcpy ((void *)this->pStr, idIn, nChars); } else { - throw resLib_dynamicMemoryAllocationFailed (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw dynamicMemoryAllocationFailed (); +# endif } } else { @@ -904,21 +962,6 @@ const unsigned char stringId::fastHashPermutedIndexSpace[256] = { 134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47 }; -// -// instantiate exceptions -// -resLib_resourceWithThatNameIsAlreadyInstalled:: - resLib_resourceWithThatNameIsAlreadyInstalled () {} - -resLib_dynamicMemoryAllocationFailed:: - resLib_dynamicMemoryAllocationFailed () {} - -resLib_entryDidntRespondToDestroyVirtualFunction:: - resLib_entryDidntRespondToDestroyVirtualFunction () {} - -resLib_sizeExceedsMaxIndexWidth:: - resLib_sizeExceedsMaxIndexWidth () {} - #endif // if instantiateRecourceLib is defined #endif // INCresourceLibh diff --git a/src/cxxTemplates/tsBTree.h b/src/cxxTemplates/tsBTree.h index a6eb49041..938e7bdc4 100644 --- a/src/cxxTemplates/tsBTree.h +++ b/src/cxxTemplates/tsBTree.h @@ -1,4 +1,5 @@ +#include // // tsBTreeRMRet @@ -99,7 +100,11 @@ private: } } else { - throw invalid_btCmp (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalid_btCmp (); +# endif } } diff --git a/src/cxxTemplates/tsSLList.h b/src/cxxTemplates/tsSLList.h index 2d6955d9b..7b57b55bd 100644 --- a/src/cxxTemplates/tsSLList.h +++ b/src/cxxTemplates/tsSLList.h @@ -30,6 +30,8 @@ * */ +#include + // // the hp compiler complains about parameterized friend // class that has not been declared without this? @@ -49,7 +51,7 @@ friend class tsSLIter; friend class tsSLIterRm; public: - tsSLNode(); + tsSLNode (); void operator = (const tsSLNode &) const; @@ -97,7 +99,7 @@ public: private: T *pCurrent; - const tsSLList &list; + const tsSLList *pList; // ptr allows cpy op }; // @@ -124,7 +126,7 @@ public: private: T *pPrevious; T *pCurrent; - tsSLList &list; + tsSLList *pList; // ptr allows cpy op }; ////////////////////////////////////////// @@ -241,7 +243,7 @@ inline void tsSLList::push(T &item) // template inline tsSLIter::tsSLIter (const tsSLList &listIn) : - pCurrent (0), list (listIn) {} + pCurrent (0), pList (&listIn) {} // // tsSLIter::next () @@ -260,7 +262,7 @@ T * tsSLIter::next () this->pCurrent = pCurNode->pNext; } else { - const tsSLNode &first = this->list; + const tsSLNode &first = *this->pList; // // assume that we are starting (or restarting) at the // beginning of the list @@ -304,7 +306,7 @@ inline T * tsSLIter::operator () () // template inline tsSLIterRm::tsSLIterRm (tsSLList &listIn) : - pPrevious (0), pCurrent (0), list (listIn) {} + pPrevious (0), pCurrent (0), pList (&listIn) {} // @@ -325,7 +327,7 @@ T * tsSLIterRm::next () this->pCurrent = pCurNode->pNext; } else { - const tsSLNode &first = this->list; + const tsSLNode &first = *this->pList; // // assume that we are starting (or restarting) at the // beginning of the list @@ -363,20 +365,28 @@ template void tsSLIterRm::remove () { if (this->pCurrent==0) { - throw noCurrentItemInIterator (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw noCurrentItemInIterator (); +# endif } tsSLNode *pPrevNode; tsSLNode *pCurNode = this->pCurrent; if (this->pPrevious==0) { - pPrevNode = &this->list; + pPrevNode = this->pList; // // fail if it is an attempt to // delete twice without moving the iterator // if (pPrevNode->pNext != this->pCurrent) { - throw noCurrentItemInIterator (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw noCurrentItemInIterator (); +# endif } } else { diff --git a/src/libCom/cxxTemplates/resourceLib.h b/src/libCom/cxxTemplates/resourceLib.h index 00d0c1b53..27d442376 100644 --- a/src/libCom/cxxTemplates/resourceLib.h +++ b/src/libCom/cxxTemplates/resourceLib.h @@ -50,6 +50,7 @@ #include #include #include +#include #include "tsSLList.h" #include "shareLib.h" @@ -57,6 +58,8 @@ typedef size_t resTableIndex; static const unsigned indexWidth = sizeof(resTableIndex)*CHAR_BIT; +template class resTableIter; + // // class resTable // @@ -103,8 +106,16 @@ static const unsigned indexWidth = sizeof(resTableIndex)*CHAR_BIT; // template class resTable { + friend class resTableIter; public: + // + // exceptions thrown + // + class epicsShareClass dynamicMemoryAllocationFailed {}; + class epicsShareClass entryDidntRespondToDestroyVirtualFunction {}; + class epicsShareClass sizeExceedsMaxIndexWidth {}; + resTable (unsigned nHashTableEntries); virtual ~resTable(); @@ -160,7 +171,7 @@ private: unsigned hashIdNBits; unsigned nInUse; - resTableIndex hash(const ID & idIn) const; + resTableIndex hash (const ID & idIn) const; T *find (tsSLList &list, const ID &idIn) const; @@ -171,6 +182,23 @@ private: // Some ID classes that work with the above template // +// +// class resTableIter +// +// an iterator for the resource table class +// +template +class resTableIter { +public: + resTableIter (const resTable &tableIn); + T * next (); + T * operator () (); +private: + tsSLIter iter; + unsigned index; + const resTable *pTable; +}; + // // class intId // @@ -250,6 +278,10 @@ private: class epicsShareClass stringId { public: + // + // exceptions + // + class epicsShareClass dynamicMemoryAllocationFailed {}; enum allocationType {copyString, refString}; @@ -275,33 +307,6 @@ private: static const unsigned char fastHashPermutedIndexSpace[256]; }; -// -// exceptions thrown by this library -// -class epicsShareClass resLib_resourceWithThatNameIsAlreadyInstalled -{ -public: - resLib_resourceWithThatNameIsAlreadyInstalled (); -}; - -class epicsShareClass resLib_dynamicMemoryAllocationFailed -{ -public: - resLib_dynamicMemoryAllocationFailed (); -}; - -class epicsShareClass resLib_entryDidntRespondToDestroyVirtualFunction -{ -public: - resLib_entryDidntRespondToDestroyVirtualFunction (); -}; - -class epicsShareClass resLib_sizeExceedsMaxIndexWidth -{ -public: - resLib_sizeExceedsMaxIndexWidth (); -}; - ///////////////////////////////////////////////// // resTable member functions ///////////////////////////////////////////////// @@ -326,7 +331,11 @@ resTable::resTable (unsigned nHashTableEntries) : } if ( nbits > ID::maxIndexBitWidth ) { - throw resLib_sizeExceedsMaxIndexWidth (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw sizeExceedsMaxIndexWidth (); +# endif } // @@ -343,7 +352,11 @@ resTable::resTable (unsigned nHashTableEntries) : this->nInUse = 0u; this->pTable = new tsSLList [1<pTable==0) { - throw resLib_dynamicMemoryAllocationFailed (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw dynamicMemoryAllocationFailed (); +# endif } } @@ -377,8 +390,7 @@ inline T * resTable::lookup (const ID &idIn) const template inline resTableIndex resTable::hash (const ID & idIn) const { - return idIn.hash(this->hashIdNBits) - & this->hashIdMask; + return idIn.hash (this->hashIdNBits) & this->hashIdMask; } // @@ -579,12 +591,54 @@ resTable::~resTable() if (this->pTable) { this->destroyAllEntries(); if (this->nInUse != 0u) { - throw resLib_entryDidntRespondToDestroyVirtualFunction (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw entryDidntRespondToDestroyVirtualFunction (); +# endif } delete [] this->pTable; } } +////////////////////////////////////////////// +// resTableIter member functions +////////////////////////////////////////////// + +// +// resTableIter::resTableIter () +// +template +inline resTableIter::resTableIter (const resTable &tableIn) : + iter (tableIn.pTable[0]), index (1), pTable (&tableIn) {} + +// +// resTableIter::next () +// +template +inline T * resTableIter::next () +{ + T *pNext = this->iter.next(); + if (pNext) { + return pNext; + } + if ( this->index >= (1u<table.hashIdNBits) ) { + return 0; + } + ; + this->iter = tsSLIter (this->pTable->pTable[this->index++]); + return this->iter.next (); +} + +// +// resTableIter::operator () () +// +template +inline T * resTableIter::operator () () +{ + return this->next (); +} + ////////////////////////////////////////////// // chronIntIdResTable member functions ////////////////////////////////////////////// @@ -771,7 +825,11 @@ stringId::stringId (const char * idIn, allocationType typeIn) : memcpy ((void *)this->pStr, idIn, nChars); } else { - throw resLib_dynamicMemoryAllocationFailed (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw dynamicMemoryAllocationFailed (); +# endif } } else { @@ -904,21 +962,6 @@ const unsigned char stringId::fastHashPermutedIndexSpace[256] = { 134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47 }; -// -// instantiate exceptions -// -resLib_resourceWithThatNameIsAlreadyInstalled:: - resLib_resourceWithThatNameIsAlreadyInstalled () {} - -resLib_dynamicMemoryAllocationFailed:: - resLib_dynamicMemoryAllocationFailed () {} - -resLib_entryDidntRespondToDestroyVirtualFunction:: - resLib_entryDidntRespondToDestroyVirtualFunction () {} - -resLib_sizeExceedsMaxIndexWidth:: - resLib_sizeExceedsMaxIndexWidth () {} - #endif // if instantiateRecourceLib is defined #endif // INCresourceLibh diff --git a/src/libCom/cxxTemplates/tsBTree.h b/src/libCom/cxxTemplates/tsBTree.h index a6eb49041..938e7bdc4 100644 --- a/src/libCom/cxxTemplates/tsBTree.h +++ b/src/libCom/cxxTemplates/tsBTree.h @@ -1,4 +1,5 @@ +#include // // tsBTreeRMRet @@ -99,7 +100,11 @@ private: } } else { - throw invalid_btCmp (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalid_btCmp (); +# endif } } diff --git a/src/libCom/cxxTemplates/tsSLList.h b/src/libCom/cxxTemplates/tsSLList.h index 2d6955d9b..7b57b55bd 100644 --- a/src/libCom/cxxTemplates/tsSLList.h +++ b/src/libCom/cxxTemplates/tsSLList.h @@ -30,6 +30,8 @@ * */ +#include + // // the hp compiler complains about parameterized friend // class that has not been declared without this? @@ -49,7 +51,7 @@ friend class tsSLIter; friend class tsSLIterRm; public: - tsSLNode(); + tsSLNode (); void operator = (const tsSLNode &) const; @@ -97,7 +99,7 @@ public: private: T *pCurrent; - const tsSLList &list; + const tsSLList *pList; // ptr allows cpy op }; // @@ -124,7 +126,7 @@ public: private: T *pPrevious; T *pCurrent; - tsSLList &list; + tsSLList *pList; // ptr allows cpy op }; ////////////////////////////////////////// @@ -241,7 +243,7 @@ inline void tsSLList::push(T &item) // template inline tsSLIter::tsSLIter (const tsSLList &listIn) : - pCurrent (0), list (listIn) {} + pCurrent (0), pList (&listIn) {} // // tsSLIter::next () @@ -260,7 +262,7 @@ T * tsSLIter::next () this->pCurrent = pCurNode->pNext; } else { - const tsSLNode &first = this->list; + const tsSLNode &first = *this->pList; // // assume that we are starting (or restarting) at the // beginning of the list @@ -304,7 +306,7 @@ inline T * tsSLIter::operator () () // template inline tsSLIterRm::tsSLIterRm (tsSLList &listIn) : - pPrevious (0), pCurrent (0), list (listIn) {} + pPrevious (0), pCurrent (0), pList (&listIn) {} // @@ -325,7 +327,7 @@ T * tsSLIterRm::next () this->pCurrent = pCurNode->pNext; } else { - const tsSLNode &first = this->list; + const tsSLNode &first = *this->pList; // // assume that we are starting (or restarting) at the // beginning of the list @@ -363,20 +365,28 @@ template void tsSLIterRm::remove () { if (this->pCurrent==0) { - throw noCurrentItemInIterator (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw noCurrentItemInIterator (); +# endif } tsSLNode *pPrevNode; tsSLNode *pCurNode = this->pCurrent; if (this->pPrevious==0) { - pPrevNode = &this->list; + pPrevNode = this->pList; // // fail if it is an attempt to // delete twice without moving the iterator // if (pPrevNode->pNext != this->pCurrent) { - throw noCurrentItemInIterator (); +# ifdef noExceptionsFromCXX + assert (0); +# else + throw noCurrentItemInIterator (); +# endif } } else {