#include <IfdStrKey.h>
Inheritance diagram for IfdStrKey:
Public Types | |
enum | { IFDKEY_BUFSIZE = 32 } |
enum | { IFDKEY_BUFSIZE = 32 } |
Public Member Functions | |
virtual void | add (const IfdKey &) |
virtual void | add (const IfdKey &) |
const char * | asString (void) const |
const char * | asString (void) const |
int | cardinality (void) const |
int | cardinality (void) const |
virtual IfdKey * | clone (void) const |
virtual IfdKey * | clone (void) const |
virtual unsigned int | hash (void) const |
virtual unsigned int | hash (void) const |
IfdStrKey (const std::string &s) | |
IfdStrKey (const char *s) | |
IfdStrKey (const std::string &s) | |
IfdStrKey (const char *s) | |
int | operator!= (const IfdKey &k) const |
int | operator!= (const IfdKey &k) const |
virtual int | operator< (const IfdKey &k) const |
virtual int | operator< (const IfdKey &k) const |
virtual int | operator== (const IfdKey &k) const |
virtual int | operator== (const IfdKey &k) const |
virtual void | print (std::ostream &o) const |
virtual void | print (std::ostream &o) const |
virtual | ~IfdStrKey () |
virtual | ~IfdStrKey () |
Static Public Member Functions | |
unsigned int | nHashBuckets (void) |
unsigned int | nHashBuckets (void) |
Public Attributes | |
unsigned int | _hashVal |
Protected Types | |
enum | { _nHashBuckets = 1031 } |
enum | { _nHashBuckets = 1031 } |
enum | keyKind { intKey, strKey, compositeKey, typeKey, odfTypeKey } |
enum | keyKind { intKey, strKey, compositeKey, typeKey, odfTypeKey } |
Protected Member Functions | |
IfdKey::keyKind | getKeyKind (void) const |
IfdKey::keyKind | getKeyKind (void) const |
Protected Attributes | |
int | _myCardinality |
keyKind | _myKeyKind |
int | intVal |
char * | strVal |
char * | strVal |
unsigned int | uintVal |
Private Member Functions | |
IfdStrKey (const IfdStrKey &) | |
IfdStrKey (const char *s, unsigned int hashVal) | |
IfdStrKey (const IfdStrKey &) | |
IfdStrKey (const char *s, unsigned int hashVal) | |
IfdStrKey & | operator= (IfdStrKey &) |
IfdStrKey & | operator= (IfdStrKey &) |
Private Attributes | |
bool | _onHeap |
char | _stringBuf [IFDKEY_BUFSIZE] |
Friends | |
class | BdbOdfIfdTypeKeyIFace |
class | IfdCompositeKey |
class | IfdIntKey |
unsigned | ifdKeyHash (const IfdDictKey &k) |
unsigned | ifdKeyHash (const IfdDictKey &k) |
class | IfdStrKey |
class | IfdTypeKeyIFace |
std::ostream & | operator<< (std::ostream &o, const IfdKey &k) |
std::ostream & | operator<< (std::ostream &o, const IfdKey &k) |
|
00086 { _nHashBuckets = 1031 }; // .33 msec/ev, not opt
|
|
00041 { IFDKEY_BUFSIZE=32 }; // See comments for _string
|
|
00086 { _nHashBuckets = 1031 }; // .33 msec/ev, not opt
|
|
00041 { IFDKEY_BUFSIZE=32 }; // See comments for _string
|
|
00088 { intKey, strKey, compositeKey, 00089 typeKey, odfTypeKey };
|
|
00088 { intKey, strKey, compositeKey, 00089 typeKey, odfTypeKey };
|
|
00031 : IfdKey( strKey ) 00032 00033 { 00034 00035 // NB: strncpy would be nice below, but we've already died in strlen 00036 // if thats an issue. 00037 00038 register size_t strSize = strlen(s)+1; 00039 00040 // If the space allocated in this instance of IfdStrKey is big enough 00041 // to hold the string, then put it there; otherwise do the slower operation 00042 // of allocating it in the heap. Either way, make strVal point at it 00043 // to avoid "if allocated" sort of logic later. 00044 00045 if ( strSize < IFDKEY_BUFSIZE ) { 00046 strcpy(_stringBuf, s); 00047 strVal = &_stringBuf[0]; 00048 _onHeap = false; 00049 } else { 00050 strVal = new char[ strSize ]; 00051 strcpy(strVal, s); 00052 _onHeap = true; 00053 } 00054 00055 enum { 00056 MaxChar = 64 // Limit computation. Don't need strlen() 00057 }; 00058 00059 _hashVal = 0; 00060 00061 size_t n = 0; 00062 while ( (s[n] != '\0') && (n < MaxChar) ) { 00063 _hashVal = ( (_hashVal<<8) + s[n] ) % _nHashBuckets; 00064 n++; 00065 } 00066 }
|
|
00073 : IfdKey( strKey ) 00074 00075 { 00076 using std::string; 00077 const char* s = str.c_str(); 00078 register size_t strSize = str.size()+1; 00079 00080 // register size_t strSize = strlen(s)+1; 00081 00082 // If the space allocated in this instance of IfdStrKey is big enough 00083 // to hold the string, then put it there; otherwise do the slower operation 00084 // of allocating it in the heap. Either way, make strVal point at it 00085 // to avoid "if allocated" sort of logic later. 00086 00087 if ( strSize < IFDKEY_BUFSIZE ) { 00088 strcpy(_stringBuf, s); 00089 strVal = &_stringBuf[0]; 00090 _onHeap = false; 00091 } else { 00092 strVal = new char[ strSize ]; 00093 strcpy(strVal, s); 00094 _onHeap = true; 00095 } 00096 00097 enum { 00098 MaxChar = 64 // Limit computation. Don't need strlen() 00099 }; 00100 00101 _hashVal = 0; 00102 00103 size_t n = 0; 00104 while ( (s[n] != '\0') && (n < MaxChar) ) { 00105 _hashVal = ( (_hashVal<<8) + s[n] ) % _nHashBuckets; 00106 n++; 00107 } 00108 }
|
|
00141 { 00142 //**************************************************************************** 00143 if (_onHeap) delete[] strVal; 00144 strVal=0; 00145 }
|
|
00118 : IfdKey( strKey ) 00119 { 00120 00121 // This code is cut/paste from the other constructor. This is harder 00122 // to maintain but in this case we very much need the speed gained by 00123 // saving a call. 00124 00125 register size_t strSize = strlen(s)+1; 00126 00127 if ( strSize < IFDKEY_BUFSIZE ) { 00128 strcpy(_stringBuf, s); 00129 strVal = &_stringBuf[0]; 00130 _onHeap = false; 00131 } else { 00132 strVal = new char[strlen(s)+1]; 00133 strcpy(strVal, s); 00134 _onHeap = true; 00135 } 00136 00137 _hashVal = hashVal; // Override the IfdKey base class init of this. 00138 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
00034 {
00035 // only makes sense for the composite class.
00036
00037 assert( 0 );
00038 }
|
|
00056 { return strVal; }
|
|
00056 { return strVal; }
|
|
|
|
00166 { 00167 //***************************************************************************** 00168 return _myCardinality; 00169 }
|
|
Implements IfdKey. |
|
Implements IfdKey. 00149 { 00150 //**************************************************************************** 00151 return new IfdStrKey( strVal, _hashVal ); 00152 }
|
|
00098 { return _myKeyKind; }
|
|
00098 { return _myKeyKind; }
|
|
00078 { return _hashVal;}
|
|
00078 { return _hashVal;}
|
|
00083 { return _nHashBuckets; }
|
|
00083 { return _nHashBuckets; }
|
|
|
|
00182 { 00183 //***************************************************************************** 00184 00185 return ! ( *this == k ); 00186 }
|
|
|
|
00177 { 00178 //**************************************************************************** 00179 return ( strKey == k.getKeyKind() ) && (strcmp(strVal, k.strVal) < 0); 00180 }
|
|
|
|
|
|
Implements IfdKey. |
|
Implements IfdKey. 00156 { 00157 //**************************************************************************** 00158 00159 00160 if ( (strKey == k.getKeyKind()) && (_hashVal == k._hashVal) ) { 00161 00162 // Then they might actually match! Check the strings. 00163 // We used to use strcmp, but this is faster by x2.2. 00164 char* s1 = strVal; 00165 char* s2 = k.strVal; 00166 while (*s1 == *s2++) { 00167 if ( *s1++ == '\0') return 1; //NB: == in while => *s2 == \0 too. 00168 } 00169 } 00170 00171 return 0; 00172 }
|
|
Implements IfdKey. |
|
Implements IfdKey. 00184 { 00185 //**************************************************************************** 00186 o << "IfdStrKey(" << strVal << ")"; 00187 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|