#include <IfdStrKey.h>
Inheritance diagram for IfdStrKey:
Public Types | |
IFDKEY_BUFSIZE = 32 | |
enum | { IFDKEY_BUFSIZE = 32 } |
Public Member Functions | |
IfdStrKey (const char *s) | |
IfdStrKey (const std::string &s) | |
virtual | ~IfdStrKey () |
virtual int | operator== (const IfdKey &k) const |
virtual int | operator< (const IfdKey &k) const |
virtual IfdKey * | clone (void) const |
const char * | asString (void) const |
virtual void | print (std::ostream &o) const |
int | operator!= (const IfdKey &k) const |
virtual void | add (const IfdKey &) |
int | cardinality (void) const |
virtual unsigned int | hash (void) const |
Static Public Member Functions | |
static unsigned int | nHashBuckets (void) |
Public Attributes | |
unsigned int | _hashVal |
Protected Types | |
_nHashBuckets = 1031 | |
intKey | |
strKey | |
compositeKey | |
typeKey | |
odfTypeKey | |
enum | { _nHashBuckets = 1031 } |
enum | keyKind { intKey, strKey, compositeKey, typeKey, odfTypeKey } |
Protected Member Functions | |
IfdKey::keyKind | getKeyKind (void) const |
Protected Attributes | |
keyKind | _myKeyKind |
int | _myCardinality |
union { | |
int intVal | |
unsigned int uintVal | |
char * strVal | |
}; | |
Private Member Functions | |
IfdStrKey (const char *s, unsigned int hashVal) | |
IfdStrKey (const IfdStrKey &) | |
IfdStrKey & | operator= (IfdStrKey &) |
Private Attributes | |
char | _stringBuf [IFDKEY_BUFSIZE] |
bool | _onHeap |
Friends | |
class | IfdIntKey |
class | IfdStrKey |
class | IfdTypeKeyIFace |
class | IfdCompositeKey |
class | BdbOdfIfdTypeKeyIFace |
std::ostream & | operator<< (std::ostream &o, const IfdKey &k) |
unsigned | ifdKeyHash (const IfdDictKey &k) |
Definition at line 39 of file IfdStrKey.h.
anonymous enum [protected, inherited] |
anonymous enum |
enum IfdKey::keyKind [protected, inherited] |
Definition at line 88 of file IfdKey.h.
00088 { intKey, strKey, compositeKey, 00089 typeKey, odfTypeKey };
IfdStrKey::IfdStrKey | ( | const char * | s | ) |
Definition at line 28 of file IfdStrKey.cxx.
References IfdKey::_hashVal, IfdKey::_nHashBuckets, _onHeap, _stringBuf, IFDKEY_BUFSIZE, and IfdKey::strVal.
Referenced by clone().
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 }
IfdStrKey::IfdStrKey | ( | const std::string & | s | ) |
Definition at line 70 of file IfdStrKey.cxx.
References IfdKey::_hashVal, IfdKey::_nHashBuckets, _onHeap, _stringBuf, IFDKEY_BUFSIZE, s, deljobs::string, and IfdKey::strVal.
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 }
IfdStrKey::~IfdStrKey | ( | ) | [virtual] |
Definition at line 141 of file IfdStrKey.cxx.
References _onHeap, and IfdKey::strVal.
00141 { 00142 //**************************************************************************** 00143 if (_onHeap) delete[] strVal; 00144 strVal=0; 00145 }
IfdStrKey::IfdStrKey | ( | const char * | s, | |
unsigned int | hashVal | |||
) | [private] |
Definition at line 112 of file IfdStrKey.cxx.
References IfdKey::_hashVal, _onHeap, _stringBuf, IFDKEY_BUFSIZE, and IfdKey::strVal.
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 }
IfdStrKey::IfdStrKey | ( | const IfdStrKey & | ) | [private] |
void IfdKey::add | ( | const IfdKey & | ) | [virtual, inherited] |
const char* IfdStrKey::asString | ( | void | ) | const [inline] |
int IfdKey::cardinality | ( | void | ) | const [inline, inherited] |
Definition at line 166 of file IfdKey.h.
References IfdKey::_myCardinality.
00166 { 00167 //***************************************************************************** 00168 return _myCardinality; 00169 }
IfdKey * IfdStrKey::clone | ( | void | ) | const [virtual] |
Implements IfdKey.
Definition at line 149 of file IfdStrKey.cxx.
References IfdKey::_hashVal, IfdStrKey(), and IfdKey::strVal.
00149 { 00150 //**************************************************************************** 00151 return new IfdStrKey( strVal, _hashVal ); 00152 }
IfdKey::keyKind IfdKey::getKeyKind | ( | void | ) | const [inline, protected, inherited] |
Definition at line 98 of file IfdKey.h.
References IfdKey::_myKeyKind.
Referenced by operator<(), operator==(), and IfdIntKey::operator==().
00098 { return _myKeyKind; }
virtual unsigned int IfdKey::hash | ( | void | ) | const [inline, virtual, inherited] |
static unsigned int IfdKey::nHashBuckets | ( | void | ) | [inline, static, inherited] |
Definition at line 82 of file IfdKey.h.
References IfdKey::_nHashBuckets.
00083 { return _nHashBuckets; }
int IfdKey::operator!= | ( | const IfdKey & | k | ) | const [inline, inherited] |
int IfdStrKey::operator< | ( | const IfdKey & | k | ) | const [virtual] |
Definition at line 177 of file IfdStrKey.cxx.
References IfdKey::getKeyKind(), IfdKey::strKey, and IfdKey::strVal.
00177 { 00178 //**************************************************************************** 00179 return ( strKey == k.getKeyKind() ) && (strcmp(strVal, k.strVal) < 0); 00180 }
int IfdStrKey::operator== | ( | const IfdKey & | k | ) | const [virtual] |
Implements IfdKey.
Definition at line 156 of file IfdStrKey.cxx.
References IfdKey::_hashVal, IfdKey::getKeyKind(), IfdKey::strKey, and IfdKey::strVal.
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 }
virtual void IfdStrKey::print | ( | std::ostream & | o | ) | const [virtual] |
Implements IfdKey.
unsigned ifdKeyHash | ( | const IfdDictKey & | k | ) | [friend, inherited] |
std::ostream& operator<< | ( | std::ostream & | o, | |
const IfdKey & | k | |||
) | [friend, inherited] |
union { ... } [protected, inherited] |
unsigned int IfdKey::_hashVal [inherited] |
Definition at line 80 of file IfdKey.h.
Referenced by clone(), IfdKey::hash(), IfdIntKey::IfdIntKey(), IfdStrKey(), and operator==().
int IfdKey::_myCardinality [protected, inherited] |
keyKind IfdKey::_myKeyKind [protected, inherited] |
bool IfdStrKey::_onHeap [private] |
char IfdStrKey::_stringBuf[IFDKEY_BUFSIZE] [private] |
int IfdKey::intVal [protected, inherited] |
Definition at line 126 of file IfdKey.h.
Referenced by IfdIntKey::clone(), IfdIntKey::IfdIntKey(), IfdIntKey::operator==(), and IfdIntKey::print().
char* IfdKey::strVal [protected, inherited] |
Definition at line 128 of file IfdKey.h.
Referenced by asString(), clone(), IfdStrKey(), operator<(), operator==(), and ~IfdStrKey().
unsigned int IfdKey::uintVal [protected, inherited] |