diff --git a/src/cxxTemplates/resourceLib.h b/src/cxxTemplates/resourceLib.h index 54d3a4a38..72161fac1 100644 --- a/src/cxxTemplates/resourceLib.h +++ b/src/cxxTemplates/resourceLib.h @@ -108,10 +108,10 @@ public: // // exceptions thrown by this class // - class resourceWithThatNameIsAlreadyInstalled {}; - class dynamicMemoryAllocationFailed {}; - class entryDidntRespondToDestroyVirtualFunction {}; - class sizeExceedsMaxIndexWidth {}; + class resourceWithThatNameIsAlreadyInstalled {}; + class dynamicMemoryAllocationFailed {}; + class entryDidntRespondToDestroyVirtualFunction {}; + class sizeExceedsMaxIndexWidth {}; resTable (unsigned nHashTableEntries); @@ -250,39 +250,25 @@ private: void setId (unsigned newId); }; - // -// class stringIdentifier +// class stringId // // character string identifier // -// 1< -class stringIdentifier { +class stringId { public: class dynamicMemoryAllocationFailed {}; // exception enum allocationType {copyString, refString}; - stringIdentifier (const char * idIn, allocationType typeIn=copyString); - ~ stringIdentifier(); + stringId (const char * idIn, allocationType typeIn=copyString); + + ~ stringId(); resTableIndex hash (unsigned nBitsIndex) const; - bool operator == (const stringIdentifier &idIn) const; + bool operator == (const stringId &idIn) const; const char * resourceName() const; // return the pointer to the string @@ -296,15 +282,8 @@ private: const char * pStr; const allocationType allocType; static const unsigned char fastHashPermutedIndexSpace[256]; - static const unsigned fastHashMaxIndexBitWidth; - static const unsigned fastHashMinIndexBitWidth; }; -// -// class stringId -// -typedef stringIdentifier <16,8> stringId; - ///////////////////////////////////////////////// // resTable member functions ///////////////////////////////////////////////// @@ -733,14 +712,37 @@ inline resTableIndex intId::hash (unsigned /* } //////////////////////////////////////////////////// -// stringIdentifier member functions +// stringId member functions //////////////////////////////////////////////////// // -// stringIdentifier::stringIdentifier() +// stringId::operator == () // -template -stringIdentifier::stringIdentifier (const char *idIn, allocationType typeIn) : +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 + } +} + +// +// stringId::resourceName () +// +inline const char * stringId::resourceName () const +{ + return this->pStr; +} + +#ifdef instantiateRecourceLib + +// +// stringId::stringId() +// +stringId::stringId (const char * idIn, allocationType typeIn) : allocType (typeIn) { if (typeIn==copyString) { @@ -760,53 +762,26 @@ stringIdentifier::stringIdentifier (const char } // -// stringIdentifier::operator == () +// const unsigned stringId::minIndexBitWidth // -template -inline bool stringIdentifier::operator == - (const stringIdentifier &idIn) const -{ - if (this->pStr!=NULL && idIn.pStr!=NULL) { - return strcmp(this->pStr,idIn.pStr)==0; - } - else { - return false; // not equal - } -} - -// -// stringIdentifier::resourceName () -// -template -inline const char * stringIdentifier::resourceName () const -{ - return this->pStr; -} - -// -// const unsigned stringIdentifier::minIndexBitWidth -// -// this limit is based lon limitations in the hash +// this limit is based on limitations in the hash // function below // -template -const unsigned stringIdentifier::minIndexBitWidth = 8; +const unsigned stringId::minIndexBitWidth = 8; // -// const unsigned stringIdentifier::maxIndexBitWidth +// const unsigned stringId::maxIndexBitWidth // // see comments related to this limit in the hash // function below // -template -const unsigned stringIdentifier::maxIndexBitWidth = 16; +const unsigned stringId::maxIndexBitWidth = 16; // -// stringIdentifier::show () +// stringId::show () // -template -void stringIdentifier::show (unsigned level) const +void stringId::show (unsigned level) const { if (level>2u) { printf ("resource id = %s\n", this->pStr); @@ -814,13 +789,12 @@ void stringIdentifier::show (unsigned level) c } // -// stringIdentifier::~stringIdentifier() +// stringId::~stringId() // // // this needs to be instanciated only once (normally in libCom) // -template -stringIdentifier::~stringIdentifier() +stringId::~stringId() { if (this->allocType==copyString) { if (this->pStr!=NULL) { @@ -846,16 +820,15 @@ stringIdentifier::~stringIdentifier() } // -// stringIdentifier::hash() +// stringId::hash() // // This hash algorithm is a modification of the algorithm described in // Fast Hashing of Variable Length Text Strings, Peter K. Pearson, // Communications of the ACM, June 1990. The initial modifications -// were designed by Marty Kraimer. Some minor additional optimizations +// were designed by Marty Kraimer. Some additional minor optimizations // by Jeff Hill. // -template -resTableIndex stringIdentifier::hash(unsigned nBitsIndex) const +resTableIndex stringId::hash(unsigned nBitsIndex) const { const unsigned char *pUStr = reinterpret_cast(this->pStr); @@ -883,30 +856,7 @@ resTableIndex stringIdentifier::hash(unsigned h1 = fastHashPermutedIndexSpace[h1 ^ c]; } - // - // slight optimization when table size known at compile time - // - if (this->minIndexBitWidth==this->maxIndexBitWidth && this->maxIndexBitWidth>8u) { - h1 = h1 << (this->maxIndexBitWidth-8u); - } - // - // otherwize table size known only at run time - // - else if (nBitsIndex>8u) { - h1 = h1 << (nBitsIndex-8u); - } - - // - // !!!! does not work well for more than 65k hash table entries !!!! - // (because some indexes in the table will not be produced) - // - assert (this->maxIndexBitWidth<=fastHashMaxIndexBitWidth); // compile time evaluated - - // - // !!!! poor distribution results with less than 256 hash table entries !!!! - // - assert (this->minIndexBitWidth>=fastHashMinIndexBitWidth); // compile time evaluated - + h1 = h1 << (nBitsIndex-8u); h0 = h1 ^ h0; return h0; @@ -918,15 +868,7 @@ resTableIndex stringIdentifier::hash(unsigned // Communications of the ACM, June 1990 // The modifications were designed by Marty Kraimer // - -template -const unsigned stringIdentifier::fastHashMaxIndexBitWidth = 16; - -template -const unsigned stringIdentifier::fastHashMinIndexBitWidth = 8; - -template -const unsigned char stringIdentifier::fastHashPermutedIndexSpace[256] = { +const unsigned char stringId::fastHashPermutedIndexSpace[256] = { 39,159,180,252, 71, 6, 13,164,232, 35,226,155, 98,120,154, 69, 157, 24,137, 29,147, 78,121, 85,112, 8,248,130, 55,117,190,160, 176,131,228, 64,211,106, 38, 27,140, 30, 88,210,227,104, 84, 77, @@ -945,5 +887,7 @@ const unsigned char stringIdentifier::fastHash 134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47 }; +#endif // if instantiateRecourceLib is defined + #endif // INCresourceLibh diff --git a/src/libCom/cxxTemplates/resourceLib.h b/src/libCom/cxxTemplates/resourceLib.h index 54d3a4a38..72161fac1 100644 --- a/src/libCom/cxxTemplates/resourceLib.h +++ b/src/libCom/cxxTemplates/resourceLib.h @@ -108,10 +108,10 @@ public: // // exceptions thrown by this class // - class resourceWithThatNameIsAlreadyInstalled {}; - class dynamicMemoryAllocationFailed {}; - class entryDidntRespondToDestroyVirtualFunction {}; - class sizeExceedsMaxIndexWidth {}; + class resourceWithThatNameIsAlreadyInstalled {}; + class dynamicMemoryAllocationFailed {}; + class entryDidntRespondToDestroyVirtualFunction {}; + class sizeExceedsMaxIndexWidth {}; resTable (unsigned nHashTableEntries); @@ -250,39 +250,25 @@ private: void setId (unsigned newId); }; - // -// class stringIdentifier +// class stringId // // character string identifier // -// 1< -class stringIdentifier { +class stringId { public: class dynamicMemoryAllocationFailed {}; // exception enum allocationType {copyString, refString}; - stringIdentifier (const char * idIn, allocationType typeIn=copyString); - ~ stringIdentifier(); + stringId (const char * idIn, allocationType typeIn=copyString); + + ~ stringId(); resTableIndex hash (unsigned nBitsIndex) const; - bool operator == (const stringIdentifier &idIn) const; + bool operator == (const stringId &idIn) const; const char * resourceName() const; // return the pointer to the string @@ -296,15 +282,8 @@ private: const char * pStr; const allocationType allocType; static const unsigned char fastHashPermutedIndexSpace[256]; - static const unsigned fastHashMaxIndexBitWidth; - static const unsigned fastHashMinIndexBitWidth; }; -// -// class stringId -// -typedef stringIdentifier <16,8> stringId; - ///////////////////////////////////////////////// // resTable member functions ///////////////////////////////////////////////// @@ -733,14 +712,37 @@ inline resTableIndex intId::hash (unsigned /* } //////////////////////////////////////////////////// -// stringIdentifier member functions +// stringId member functions //////////////////////////////////////////////////// // -// stringIdentifier::stringIdentifier() +// stringId::operator == () // -template -stringIdentifier::stringIdentifier (const char *idIn, allocationType typeIn) : +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 + } +} + +// +// stringId::resourceName () +// +inline const char * stringId::resourceName () const +{ + return this->pStr; +} + +#ifdef instantiateRecourceLib + +// +// stringId::stringId() +// +stringId::stringId (const char * idIn, allocationType typeIn) : allocType (typeIn) { if (typeIn==copyString) { @@ -760,53 +762,26 @@ stringIdentifier::stringIdentifier (const char } // -// stringIdentifier::operator == () +// const unsigned stringId::minIndexBitWidth // -template -inline bool stringIdentifier::operator == - (const stringIdentifier &idIn) const -{ - if (this->pStr!=NULL && idIn.pStr!=NULL) { - return strcmp(this->pStr,idIn.pStr)==0; - } - else { - return false; // not equal - } -} - -// -// stringIdentifier::resourceName () -// -template -inline const char * stringIdentifier::resourceName () const -{ - return this->pStr; -} - -// -// const unsigned stringIdentifier::minIndexBitWidth -// -// this limit is based lon limitations in the hash +// this limit is based on limitations in the hash // function below // -template -const unsigned stringIdentifier::minIndexBitWidth = 8; +const unsigned stringId::minIndexBitWidth = 8; // -// const unsigned stringIdentifier::maxIndexBitWidth +// const unsigned stringId::maxIndexBitWidth // // see comments related to this limit in the hash // function below // -template -const unsigned stringIdentifier::maxIndexBitWidth = 16; +const unsigned stringId::maxIndexBitWidth = 16; // -// stringIdentifier::show () +// stringId::show () // -template -void stringIdentifier::show (unsigned level) const +void stringId::show (unsigned level) const { if (level>2u) { printf ("resource id = %s\n", this->pStr); @@ -814,13 +789,12 @@ void stringIdentifier::show (unsigned level) c } // -// stringIdentifier::~stringIdentifier() +// stringId::~stringId() // // // this needs to be instanciated only once (normally in libCom) // -template -stringIdentifier::~stringIdentifier() +stringId::~stringId() { if (this->allocType==copyString) { if (this->pStr!=NULL) { @@ -846,16 +820,15 @@ stringIdentifier::~stringIdentifier() } // -// stringIdentifier::hash() +// stringId::hash() // // This hash algorithm is a modification of the algorithm described in // Fast Hashing of Variable Length Text Strings, Peter K. Pearson, // Communications of the ACM, June 1990. The initial modifications -// were designed by Marty Kraimer. Some minor additional optimizations +// were designed by Marty Kraimer. Some additional minor optimizations // by Jeff Hill. // -template -resTableIndex stringIdentifier::hash(unsigned nBitsIndex) const +resTableIndex stringId::hash(unsigned nBitsIndex) const { const unsigned char *pUStr = reinterpret_cast(this->pStr); @@ -883,30 +856,7 @@ resTableIndex stringIdentifier::hash(unsigned h1 = fastHashPermutedIndexSpace[h1 ^ c]; } - // - // slight optimization when table size known at compile time - // - if (this->minIndexBitWidth==this->maxIndexBitWidth && this->maxIndexBitWidth>8u) { - h1 = h1 << (this->maxIndexBitWidth-8u); - } - // - // otherwize table size known only at run time - // - else if (nBitsIndex>8u) { - h1 = h1 << (nBitsIndex-8u); - } - - // - // !!!! does not work well for more than 65k hash table entries !!!! - // (because some indexes in the table will not be produced) - // - assert (this->maxIndexBitWidth<=fastHashMaxIndexBitWidth); // compile time evaluated - - // - // !!!! poor distribution results with less than 256 hash table entries !!!! - // - assert (this->minIndexBitWidth>=fastHashMinIndexBitWidth); // compile time evaluated - + h1 = h1 << (nBitsIndex-8u); h0 = h1 ^ h0; return h0; @@ -918,15 +868,7 @@ resTableIndex stringIdentifier::hash(unsigned // Communications of the ACM, June 1990 // The modifications were designed by Marty Kraimer // - -template -const unsigned stringIdentifier::fastHashMaxIndexBitWidth = 16; - -template -const unsigned stringIdentifier::fastHashMinIndexBitWidth = 8; - -template -const unsigned char stringIdentifier::fastHashPermutedIndexSpace[256] = { +const unsigned char stringId::fastHashPermutedIndexSpace[256] = { 39,159,180,252, 71, 6, 13,164,232, 35,226,155, 98,120,154, 69, 157, 24,137, 29,147, 78,121, 85,112, 8,248,130, 55,117,190,160, 176,131,228, 64,211,106, 38, 27,140, 30, 88,210,227,104, 84, 77, @@ -945,5 +887,7 @@ const unsigned char stringIdentifier::fastHash 134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47 }; +#endif // if instantiateRecourceLib is defined + #endif // INCresourceLibh diff --git a/src/libCom/fdManager.cc b/src/libCom/fdManager.cc index db00a2c7d..8dc9175fe 100644 --- a/src/libCom/fdManager.cc +++ b/src/libCom/fdManager.cc @@ -48,6 +48,7 @@ #include #include +#define instantiateRecourceLib #define epicsExportSharedSymbols #include "osiTimer.h" #include "osiSleep.h" diff --git a/src/libCom/fdmgr/fdManager.cpp b/src/libCom/fdmgr/fdManager.cpp index db00a2c7d..8dc9175fe 100644 --- a/src/libCom/fdmgr/fdManager.cpp +++ b/src/libCom/fdmgr/fdManager.cpp @@ -48,6 +48,7 @@ #include #include +#define instantiateRecourceLib #define epicsExportSharedSymbols #include "osiTimer.h" #include "osiSleep.h"