IfdStrKey Class Reference

#include <IfdStrKey.h>

Inheritance diagram for IfdStrKey:

IfdKey List of all members.

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 IfdKeyclone (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 &)
IfdStrKeyoperator= (IfdStrKey &)

Private Attributes

char _stringBuf [IFDKEY_BUFSIZE]
bool _onHeap

Friends

class IfdIntKey
class IfdStrKey
class IfdTypeKeyIFace
class IfdCompositeKey
class BdbOdfIfdTypeKeyIFace
std::ostreamoperator<< (std::ostream &o, const IfdKey &k)
unsigned ifdKeyHash (const IfdDictKey &k)

Detailed Description

Definition at line 39 of file IfdStrKey.h.


Member Enumeration Documentation

anonymous enum [protected, inherited]

Enumerator:
_nHashBuckets 

Definition at line 86 of file IfdKey.h.

00086 { _nHashBuckets = 1031 }; // .33 msec/ev, not opt

anonymous enum

Enumerator:
IFDKEY_BUFSIZE 

Definition at line 41 of file IfdStrKey.h.

00041 { IFDKEY_BUFSIZE=32 };  // See comments for _string

enum IfdKey::keyKind [protected, inherited]

Enumerator:
intKey 
strKey 
compositeKey 
typeKey 
odfTypeKey 

Definition at line 88 of file IfdKey.h.


Constructor & Destructor Documentation

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]


Member Function Documentation

void IfdKey::add ( const IfdKey  )  [virtual, inherited]

Definition at line 34 of file IfdKey.cxx.

00034                            {
00035   // only makes sense for the composite class.
00036 
00037   assert( 0 );
00038 }

const char* IfdStrKey::asString ( void   )  const [inline]

Definition at line 56 of file IfdStrKey.h.

References IfdKey::strVal.

00056 { return strVal; }

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]

Definition at line 77 of file IfdKey.h.

References IfdKey::_hashVal.

00078         { return _hashVal;}

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]

Definition at line 182 of file IfdKey.h.

00182                                             {
00183 //*****************************************************************************
00184 
00185     return ! ( *this == k );
00186 }

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 }

IfdStrKey& IfdStrKey::operator= ( IfdStrKey  )  [private]

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.


Friends And Related Function Documentation

friend class BdbOdfIfdTypeKeyIFace [friend, inherited]

Definition at line 136 of file IfdKey.h.

friend class IfdCompositeKey [friend, inherited]

Definition at line 135 of file IfdKey.h.

friend class IfdIntKey [friend, inherited]

Definition at line 132 of file IfdKey.h.

unsigned ifdKeyHash ( const IfdDictKey &  k  )  [friend, inherited]

friend class IfdStrKey [friend, inherited]

Definition at line 133 of file IfdKey.h.

friend class IfdTypeKeyIFace [friend, inherited]

Definition at line 134 of file IfdKey.h.

std::ostream& operator<< ( std::ostream o,
const IfdKey k 
) [friend, inherited]


Member Data Documentation

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]

Definition at line 122 of file IfdKey.h.

Referenced by IfdKey::cardinality().

keyKind IfdKey::_myKeyKind [protected, inherited]

Definition at line 116 of file IfdKey.h.

Referenced by IfdKey::getKeyKind().

bool IfdStrKey::_onHeap [private]

Definition at line 82 of file IfdStrKey.h.

Referenced by IfdStrKey(), and ~IfdStrKey().

char IfdStrKey::_stringBuf[IFDKEY_BUFSIZE] [private]

Definition at line 81 of file IfdStrKey.h.

Referenced by IfdStrKey().

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]

Definition at line 127 of file IfdKey.h.


Generated on Tue Nov 29 23:19:43 2016 for BOSS_7.0.2 by  doxygen 1.4.7