From a746ac770d12f1f70536ed36bf5da1baf4a585af Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 11 Oct 2000 19:32:48 +0000 Subject: [PATCH] tabs to spaces --- src/libCom/cxxTemplates/resourceLib.h | 516 +++++++++++++------------- 1 file changed, 258 insertions(+), 258 deletions(-) diff --git a/src/libCom/cxxTemplates/resourceLib.h b/src/libCom/cxxTemplates/resourceLib.h index b66c78c37..a8981ef17 100644 --- a/src/libCom/cxxTemplates/resourceLib.h +++ b/src/libCom/cxxTemplates/resourceLib.h @@ -10,7 +10,7 @@ * Unsigned integer and string identifier classes are supplied here. * * Author Jeffrey O. Hill - * (string hash alg by Marty Kraimer and Peter K. Pearson) + * (string hash alg by Marty Kraimer and Peter K. Pearson) * * johill@lanl.gov * 505 665 1831 @@ -37,10 +37,10 @@ * Argonne National Laboratory * * - * NOTES: - * .01 Storage for identifier must persist until an item is deleted - * .02 class T must derive from class ID and tsSLNode - * + * NOTES: + * .01 Storage for identifier must persist until an item is deleted + * .02 class T must derive from class ID and tsSLNode + * */ #ifndef INCresourceLibh @@ -117,20 +117,20 @@ public: class epicsShareClass entryDidntRespondToDestroyVirtualFunction {}; class epicsShareClass sizeExceedsMaxIndexWidth {}; - resTable (unsigned nHashTableEntries); + resTable (unsigned nHashTableEntries); - virtual ~resTable(); + virtual ~resTable(); - void destroyAllEntries(); // destroy all entries + void destroyAllEntries(); // destroy all entries - // - // Call (pT->show) (level) for each entry - // where pT is a pointer to type T. Show + // + // Call (pT->show) (level) for each entry + // where pT is a pointer to type T. Show // returns "void". Show dumps increasing // diagnostics to std out with increasing // magnitude of the its level argument. - // - void show (unsigned level) const; + // + void show (unsigned level) const; // // add entry @@ -138,33 +138,33 @@ public: // returns -1 if the id already exits in the table // and zero if successful // - int add (T &res); + int add (T &res); - T *remove (const ID &idIn); // remove entry + T *remove (const ID &idIn); // remove entry - T *lookup (const ID &idIn) const; // locate entry + T *lookup (const ID &idIn) const; // locate entry #if defined(_MSC_VER) && _MSC_VER < 1100 - // - // required by MS vis c++ 5.0 (but not by 4.0) - // - typedef void (T::*pSetMFArg_t)(); -# define pSetMFArg(ARG) pSetMFArg_t ARG + // + // required by MS vis c++ 5.0 (but not by 4.0) + // + typedef void (T::*pSetMFArg_t)(); +# define pSetMFArg(ARG) pSetMFArg_t ARG #else - // - // required by gnu g++ 2.7.2 - // -# define pSetMFArg(ARG) void (T:: * ARG)() + // + // required by gnu g++ 2.7.2 + // +# define pSetMFArg(ARG) void (T:: * ARG)() #endif - // - // Call (pT->*pCB) () for each entry - // - // where pT is a pointer to type T and pCB is - // a pointer to a member function of T with - // no parameters that returns void - // - void traverse (pSetMFArg(pCB)) const; + // + // Call (pT->*pCB) () for each entry + // + // where pT is a pointer to type T and pCB is + // a pointer to a member function of T with + // no parameters that returns void + // + void traverse (pSetMFArg(pCB)) const; private: tsSLList *pTable; @@ -172,11 +172,11 @@ 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; + T *find (tsSLList &list, const ID &idIn) const; - T *findDelete (tsSLList &list, const ID &idIn); + T *findDelete (tsSLList &list, const ID &idIn); }; @@ -189,12 +189,12 @@ template class resTableIter { public: resTableIter (const resTable &tableIn); - T * next (); - T * operator () (); + T * next (); + T * operator () (); private: tsSLIter iter; unsigned index; - const resTable &table; + const resTable &table; }; // @@ -226,16 +226,16 @@ template class intId { public: - intId (const T &idIn); - bool operator == (const intId &idIn) const; - resTableIndex hash (unsigned nBitsIndex) const; - const T getId() const; + intId (const T &idIn); + bool operator == (const intId &idIn) const; + resTableIndex hash (unsigned nBitsIndex) const; + const T getId() const; static resTableIndex hashEngine (const T &id); static const unsigned maxIndexBitWidth (); static const unsigned minIndexBitWidth (); protected: - T id; + T id; }; // @@ -285,19 +285,19 @@ public: // class epicsShareClass dynamicMemoryAllocationFailed {}; enum allocationType {copyString, refString}; - stringId (const char * idIn, allocationType typeIn=copyString); + stringId (const char * idIn, allocationType typeIn=copyString); ~ stringId(); - resTableIndex hash (unsigned nBitsIndex) const; - bool operator == (const stringId &idIn) const; - const char * resourceName() const; // return the pointer to the string - void show (unsigned level) const; + resTableIndex hash (unsigned nBitsIndex) const; + bool operator == (const stringId &idIn) const; + const char * resourceName() const; // return the pointer to the string + void show (unsigned level) const; static const unsigned maxIndexBitWidth (); static const unsigned minIndexBitWidth (); private: - const char * pStr; - const allocationType allocType; - static const unsigned char fastHashPermutedIndexSpace[256]; + const char * pStr; + const allocationType allocType; + static const unsigned char fastHashPermutedIndexSpace[256]; }; ///////////////////////////////////////////////// @@ -309,19 +309,19 @@ private: // template resTable::resTable (unsigned nHashTableEntries) : - nInUse (0) + nInUse (0) { unsigned nbits, mask; - // - // count the number of bits in the hash index - // - for (nbits=0; nbits < sizeof (resTableIndex) * CHAR_BIT; nbits++) { - mask = (1< ID::maxIndexBitWidth () ) { throwWithLocation ( sizeExceedsMaxIndexWidth () ); @@ -334,15 +334,15 @@ resTable::resTable (unsigned nHashTableEntries) : if ( nbits < ID::minIndexBitWidth () ) { nbits = ID::minIndexBitWidth (); mask = (1<hashIdNBits = nbits; + this->hashIdNBits = nbits; this->hashIdMask = mask; - this->nInUse = 0u; - this->pTable = new tsSLList [1<pTable==0) { + this->nInUse = 0u; + this->pTable = new tsSLList [1<pTable==0) { throwWithLocation ( dynamicMemoryAllocationFailed () ); - } + } } // @@ -353,8 +353,8 @@ resTable::resTable (unsigned nHashTableEntries) : template inline T * resTable::remove (const ID &idIn) { - tsSLList &list = this->pTable[this->hash(idIn)]; - return this->findDelete (list, idIn); + tsSLList &list = this->pTable[this->hash(idIn)]; + return this->findDelete (list, idIn); } // @@ -365,8 +365,8 @@ inline T * resTable::remove (const ID &idIn) template inline T * resTable::lookup (const ID &idIn) const { - tsSLList &list = this->pTable[this->hash(idIn)]; - return this->find (list, idIn); + tsSLList &list = this->pTable[this->hash(idIn)]; + return this->find (list, idIn); } // @@ -375,7 +375,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; } // @@ -384,42 +384,42 @@ inline resTableIndex resTable::hash (const ID & idIn) const template void resTable::destroyAllEntries() { - tsSLList *pList = this->pTable; + tsSLList *pList = this->pTable; - while (pList<&this->pTable[this->hashIdMask+1]) { - T *pItem; - T *pNextItem; + while (pList<&this->pTable[this->hashIdMask+1]) { + T *pItem; + T *pNextItem; - { - tsSLIter iter(*pList); - pItem = iter(); - while (pItem) { - pNextItem = iter(); - pItem->destroy(); - pItem = pNextItem; - } - } + { + tsSLIter iter(*pList); + pItem = iter(); + while (pItem) { + pNextItem = iter(); + pItem->destroy(); + pItem = pNextItem; + } + } - // - // Check to see if a defective class is - // installed that does not remove itself - // from the resTable when it is destroyed. - // - { - tsSLIterRm iter(*pList); - while ( (pItem=iter()) ) { - fprintf (stderr, + // + // Check to see if a defective class is + // installed that does not remove itself + // from the resTable when it is destroyed. + // + { + tsSLIterRm iter(*pList); + while ( (pItem=iter()) ) { + fprintf (stderr, "Warning: Defective class still in resTable after it was destroyed\n"); - // - // remove defective class - // - iter.remove(); - this->nInUse--; - } - } + // + // remove defective class + // + iter.remove(); + this->nInUse--; + } + } - pList++; - } + pList++; + } } // @@ -428,48 +428,48 @@ void resTable::destroyAllEntries() template void resTable::show (unsigned level) const { - tsSLList *pList; - double X; - double XX; - double mean; - double stdDev; - unsigned maxEntries; + tsSLList *pList; + double X; + double XX; + double mean; + double stdDev; + unsigned maxEntries; - printf("resTable with %d resources installed\n", this->nInUse); + printf("resTable with %d resources installed\n", this->nInUse); - if (level >=1u) { - pList = this->pTable; - X = 0.0; - XX = 0.0; - maxEntries = 0u; - while (pList < &this->pTable[this->hashIdMask+1]) { - unsigned count; - tsSLIter iter(*pList); - T *pItem; + if (level >=1u) { + pList = this->pTable; + X = 0.0; + XX = 0.0; + maxEntries = 0u; + while (pList < &this->pTable[this->hashIdMask+1]) { + unsigned count; + tsSLIter iter(*pList); + T *pItem; - count = 0; - while ( (pItem = iter()) ) { - if (level >= 3u) { - pItem->show (level); - } - count++; - } - if (count>0u) { - X += count; - XX += count*count; - if (count>maxEntries) { - maxEntries = count; - } - } - pList++; - } - - mean = X/(this->hashIdMask+1); - stdDev = sqrt(XX/(this->hashIdMask+1) - mean*mean); - printf( - "entries/occupied resTable entry: mean = %f std dev = %f max = %d\n", - mean, stdDev, maxEntries); - } + count = 0; + while ( (pItem = iter()) ) { + if (level >= 3u) { + pItem->show (level); + } + count++; + } + if (count>0u) { + X += count; + XX += count*count; + if (count>maxEntries) { + maxEntries = count; + } + } + pList++; + } + + mean = X/(this->hashIdMask+1); + stdDev = sqrt(XX/(this->hashIdMask+1) - mean*mean); + printf( + "entries/occupied resTable entry: mean = %f std dev = %f max = %d\n", + mean, stdDev, maxEntries); + } } // @@ -478,18 +478,18 @@ void resTable::show (unsigned level) const template void resTable::traverse (pSetMFArg(pCB)) const { - tsSLList *pList; + tsSLList *pList; - pList = this->pTable; - while (pList < &this->pTable[this->hashIdMask+1]) { - tsSLIter iter(*pList); - T *pItem; + pList = this->pTable; + while (pList < &this->pTable[this->hashIdMask+1]) { + tsSLIter iter(*pList); + T *pItem; - while ( (pItem = iter()) ) { - (pItem->*pCB) (); - } - pList++; - } + while ( (pItem = iter()) ) { + (pItem->*pCB) (); + } + pList++; + } } // @@ -500,17 +500,17 @@ void resTable::traverse (pSetMFArg(pCB)) const template int resTable::add (T &res) { - // - // T must derive from ID - // - tsSLList &list = this->pTable[this->hash(res)]; + // + // T must derive from ID + // + tsSLList &list = this->pTable[this->hash(res)]; - if ( this->find (list, res) != 0 ) { - return -1; - } + if ( this->find (list, res) != 0 ) { + return -1; + } - list.add (res); - this->nInUse++; + list.add (res); + this->nInUse++; return 0; } @@ -526,17 +526,17 @@ int resTable::add (T &res) template T *resTable::find (tsSLList &list, const ID &idIn) const { - tsSLIter iter(list); - T *pItem; - ID *pId; + tsSLIter iter(list); + T *pItem; + ID *pId; - while ( (pItem = iter()) ) { - pId = pItem; - if (*pId == idIn) { - break; - } - } - return pItem; + while ( (pItem = iter()) ) { + pId = pItem; + if (*pId == idIn) { + break; + } + } + return pItem; } // @@ -552,19 +552,19 @@ T *resTable::find (tsSLList &list, const ID &idIn) const template T *resTable::findDelete (tsSLList &list, const ID &idIn) { - tsSLIterRm iter(list); - T *pItem; - ID *pId; + tsSLIterRm iter(list); + T *pItem; + ID *pId; - while ( (pItem = iter()) ) { - pId = pItem; - if (*pId == idIn) { - iter.remove(); - this->nInUse--; - break; - } - } - return pItem; + while ( (pItem = iter()) ) { + pId = pItem; + if (*pId == idIn) { + iter.remove(); + this->nInUse--; + break; + } + } + return pItem; } // @@ -573,13 +573,13 @@ T *resTable::findDelete (tsSLList &list, const ID &idIn) template resTable::~resTable() { - if (this->pTable) { - this->destroyAllEntries(); - if (this->nInUse != 0u) { + if (this->pTable) { + this->destroyAllEntries(); + if (this->nInUse != 0u) { throwWithLocation ( entryDidntRespondToDestroyVirtualFunction () ); - } - delete [] this->pTable; - } + } + delete [] this->pTable; + } } ////////////////////////////////////////////// @@ -650,7 +650,7 @@ inline void chronIntIdResTable::add (ITEM &item) { int status; do { - item.chronIntIdRes::setId (allocId++); + item.chronIntIdRes::setId (allocId++); status = this->resTable::add (item); } while (status); @@ -695,7 +695,7 @@ template inline bool intId::operator == (const intId &idIn) const { - return this->id == idIn.id; + return this->id == idIn.id; } // @@ -704,7 +704,7 @@ inline bool intId::operator == template inline const T intId::getId () const { - return this->id; + return this->id; } // @@ -734,28 +734,28 @@ inline const unsigned intId::maxIndexBitWidth template inline resTableIndex intId::hashEngine (const T &id) { - resTableIndex hashid = static_cast(id); + resTableIndex hashid = static_cast(id); - // + // // On most compilers the optimizer will unroll this loop so this // is actually a very small inline function // - // Experiments using the microsoft compiler show that this isnt - // slower than switching on the architecture size and unrolling the - // loop explicitly (that solution has resulted in portability - // problems in the past). - // + // Experiments using the microsoft compiler show that this isnt + // slower than switching on the architecture size and unrolling the + // loop explicitly (that solution has resulted in portability + // problems in the past). + // unsigned width = MAX_ID_WIDTH; do { width >>= 1u; - hashid ^= hashid>>width; + hashid ^= hashid>>width; } while (width>MIN_INDEX_WIDTH); - // - // the result here is always masked to the - // proper size after it is returned to the "resTable" class - // - return hashid; + // + // the result here is always masked to the + // proper size after it is returned to the "resTable" class + // + return hashid; } @@ -778,12 +778,12 @@ inline resTableIndex intId::hash (unsigned /* inline bool stringId::operator == (const stringId &idIn) const { - if (this->pStr!=NULL && idIn.pStr!=NULL) { - return strcmp(this->pStr,idIn.pStr)==0; - } - else { - return false; // not equal - } + if (this->pStr!=NULL && idIn.pStr!=NULL) { + return strcmp(this->pStr,idIn.pStr)==0; + } + else { + return false; // not equal + } } // @@ -791,7 +791,7 @@ inline bool stringId::operator == // inline const char * stringId::resourceName () const { - return this->pStr; + return this->pStr; } // @@ -822,22 +822,22 @@ inline const unsigned stringId::maxIndexBitWidth () // stringId::stringId() // stringId::stringId (const char * idIn, allocationType typeIn) : - allocType (typeIn) + allocType (typeIn) { - if (typeIn==copyString) { - unsigned nChars = strlen (idIn) + 1u; + if (typeIn==copyString) { + unsigned nChars = strlen (idIn) + 1u; - this->pStr = new char [nChars]; - if (this->pStr!=0) { - memcpy ((void *)this->pStr, idIn, nChars); - } - else { + this->pStr = new char [nChars]; + if (this->pStr!=0) { + memcpy ((void *)this->pStr, idIn, nChars); + } + else { throwWithLocation ( dynamicMemoryAllocationFailed () ); - } - } - else { - this->pStr = idIn; - } + } + } + else { + this->pStr = idIn; + } } // @@ -845,9 +845,9 @@ stringId::stringId (const char * idIn, allocationType typeIn) : // void stringId::show (unsigned level) const { - if (level>2u) { - printf ("resource id = %s\n", this->pStr); - } + if (level>2u) { + printf ("resource id = %s\n", this->pStr); + } } // @@ -858,27 +858,27 @@ void stringId::show (unsigned level) const // stringId::~stringId() { - if (this->allocType==copyString) { - if (this->pStr!=NULL) { - // - // the microsoft and solaris compilers will - // not allow a pointer to "const char" - // to be deleted - // - // the HP-UX compiler gives us a warning on - // each cast away of const, but in this case - // it cant be avoided. - // - // The DEC compiler complains that const isnt - // really significant in a cast if it is present. - // - // I hope that deleting a pointer to "char" - // is the same as deleting a pointer to - // "const char" on all compilers - // - delete [] const_cast(this->pStr); - } - } + if (this->allocType==copyString) { + if (this->pStr!=NULL) { + // + // the microsoft and solaris compilers will + // not allow a pointer to "const char" + // to be deleted + // + // the HP-UX compiler gives us a warning on + // each cast away of const, but in this case + // it cant be avoided. + // + // The DEC compiler complains that const isnt + // really significant in a cast if it is present. + // + // I hope that deleting a pointer to "char" + // is the same as deleting a pointer to + // "const char" on all compilers + // + delete [] const_cast(this->pStr); + } + } } // @@ -895,13 +895,13 @@ resTableIndex stringId::hash(unsigned nBitsIndex) const const unsigned char *pUStr = reinterpret_cast(this->pStr); - if (pUStr==NULL) { - return 0u; - } + if (pUStr==NULL) { + return 0u; + } - unsigned h0 = 0u; - unsigned h1 = 0u; - unsigned c; + unsigned h0 = 0u; + unsigned h1 = 0u; + unsigned c; while (true) { @@ -916,12 +916,12 @@ resTableIndex stringId::hash(unsigned nBitsIndex) const break; } h1 = fastHashPermutedIndexSpace[h1 ^ c]; - } + } h1 = h1 << (nBitsIndex-8u); h0 = h1 ^ h0; - return h0; + return h0; } //