Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

IfdStrKey Class Reference

#include <IfdStrKey.h>

Inheritance diagram for IfdStrKey:

IfdKey IfdKey List of all members.

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 IfdKeyclone (void) const
virtual IfdKeyclone (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)
IfdStrKeyoperator= (IfdStrKey &)
IfdStrKeyoperator= (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::ostreamoperator<< (std::ostream &o, const IfdKey &k)
std::ostreamoperator<< (std::ostream &o, const IfdKey &k)

Member Enumeration Documentation

anonymous enum [protected, inherited]
 

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

anonymous enum
 

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

anonymous enum [protected, inherited]
 

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

anonymous enum
 

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

enum IfdKey::keyKind [protected, inherited]
 

Enumeration values:
intKey 
strKey 
compositeKey 
typeKey 
odfTypeKey 
00088                 { intKey, strKey, compositeKey,
00089                    typeKey, odfTypeKey };

enum IfdKey::keyKind [protected, inherited]
 

Enumeration values:
intKey 
strKey 
compositeKey 
typeKey 
odfTypeKey 
00088                 { intKey, strKey, compositeKey,
00089                    typeKey, odfTypeKey };


Constructor & Destructor Documentation

IfdStrKey::IfdStrKey const char *  s  ) 
 

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  ) 
 

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]
 

00141                       {
00142 //****************************************************************************
00143   if (_onHeap) delete[] strVal;
00144   strVal=0;
00145 }

IfdStrKey::IfdStrKey const char *  s,
unsigned int  hashVal
[private]
 

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]
 

IfdStrKey::IfdStrKey const char *  s  ) 
 

IfdStrKey::IfdStrKey const std::string &  s  ) 
 

virtual IfdStrKey::~IfdStrKey  )  [virtual]
 

IfdStrKey::IfdStrKey const char *  s,
unsigned int  hashVal
[private]
 

IfdStrKey::IfdStrKey const IfdStrKey  )  [private]
 


Member Function Documentation

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

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

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

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

00056 { return strVal; }

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

00056 { return strVal; }

int IfdKey::cardinality void   )  const [inline, inherited]
 

int IfdKey::cardinality void   )  const [inline, inherited]
 

00166                               { 
00167 //*****************************************************************************
00168     return _myCardinality;
00169 }

virtual IfdKey* IfdStrKey::clone void   )  const [virtual]
 

Implements IfdKey.

IfdKey * IfdStrKey::clone void   )  const [virtual]
 

Implements IfdKey.

00149                            {
00150 //****************************************************************************
00151   return new IfdStrKey( strVal, _hashVal );
00152 }

IfdKey::keyKind IfdKey::getKeyKind void   )  const [inline, protected, inherited]
 

00098 { return _myKeyKind; }

IfdKey::keyKind IfdKey::getKeyKind void   )  const [inline, protected, inherited]
 

00098 { return _myKeyKind; }

virtual unsigned int IfdKey::hash void   )  const [inline, virtual, inherited]
 

00078         { return _hashVal;}

virtual unsigned int IfdKey::hash void   )  const [inline, virtual, inherited]
 

00078         { return _hashVal;}

unsigned int IfdKey::nHashBuckets void   )  [inline, static, inherited]
 

00083        { return _nHashBuckets; }

unsigned int IfdKey::nHashBuckets void   )  [inline, static, inherited]
 

00083        { return _nHashBuckets; }

int IfdKey::operator!= const IfdKey k  )  const [inline, inherited]
 

int IfdKey::operator!= const IfdKey k  )  const [inline, inherited]
 

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

virtual int IfdStrKey::operator< const IfdKey k  )  const [virtual]
 

int IfdStrKey::operator< const IfdKey k  )  const [virtual]
 

00177                                             {
00178 //****************************************************************************
00179   return ( strKey == k.getKeyKind() ) && (strcmp(strVal, k.strVal) < 0);
00180 }

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

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

virtual int IfdStrKey::operator== const IfdKey k  )  const [virtual]
 

Implements IfdKey.

int IfdStrKey::operator== const IfdKey k  )  const [virtual]
 

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   }

virtual void IfdStrKey::print std::ostream o  )  const [virtual]
 

Implements IfdKey.

void IfdStrKey::print std::ostream o  )  const [virtual]
 

Implements IfdKey.

00184                                   {
00185 //****************************************************************************
00186   o << "IfdStrKey(" << strVal << ")"; 
00187 }


Friends And Related Function Documentation

BdbOdfIfdTypeKeyIFace [friend, inherited]
 

IfdCompositeKey [friend, inherited]
 

IfdIntKey [friend, inherited]
 

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

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

IfdStrKey [friend, inherited]
 

IfdTypeKeyIFace [friend, inherited]
 

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

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


Member Data Documentation

unsigned int IfdKey::_hashVal [inherited]
 

int IfdKey::_myCardinality [protected, inherited]
 

keyKind IfdKey::_myKeyKind [protected, inherited]
 

bool IfdStrKey::_onHeap [private]
 

char IfdStrKey::_stringBuf [private]
 

int IfdKey::intVal [protected, inherited]
 

char* IfdKey::strVal [protected, inherited]
 

char* IfdKey::strVal [protected, inherited]
 

unsigned int IfdKey::uintVal [protected, inherited]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 16:18:10 2011 for BOSS6.5.5 by  doxygen 1.3.9.1