CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
IfdStrKey Class Reference

#include <IfdStrKey.h>

+ Inheritance diagram for IfdStrKey:

Public Types

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
 
- Public Member Functions inherited from IfdKey
virtual ~IfdKey ()
 
int operator!= (const IfdKey &k) const
 
virtual void add (const IfdKey &)
 
int cardinality (void) const
 
virtual unsigned int hash (void) const
 

Additional Inherited Members

- Static Public Member Functions inherited from IfdKey
static unsigned int nHashBuckets (void)
 
- Public Attributes inherited from IfdKey
unsigned int _hashVal
 
- Protected Types inherited from IfdKey
enum  { _nHashBuckets = 1031 }
 
enum  keyKind {
  intKey , strKey , compositeKey , typeKey ,
  odfTypeKey
}
 
- Protected Member Functions inherited from IfdKey
 IfdKey (keyKind kind)
 
IfdKey::keyKind getKeyKind (void) const
 
- Protected Attributes inherited from IfdKey
keyKind _myKeyKind
 
int _myCardinality
 
union { 
 
   int   intVal 
 
   unsigned int   uintVal 
 
   char *   strVal 
 
};  
 

Detailed Description

Definition at line 39 of file IfdStrKey.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
IFDKEY_BUFSIZE 

Definition at line 41 of file IfdStrKey.h.

41{ IFDKEY_BUFSIZE=32 }; // See comments for _string
@ IFDKEY_BUFSIZE
Definition IfdStrKey.h:41

Constructor & Destructor Documentation

◆ IfdStrKey() [1/2]

IfdStrKey::IfdStrKey ( const char * s)

Definition at line 28 of file IfdStrKey.cxx.

31 : IfdKey( strKey )
32
33{
34
35 // NB: strncpy would be nice below, but we've already died in strlen
36 // if thats an issue.
37
38 register size_t strSize = strlen(s)+1;
39
40 // If the space allocated in this instance of IfdStrKey is big enough
41 // to hold the string, then put it there; otherwise do the slower operation
42 // of allocating it in the heap. Either way, make strVal point at it
43 // to avoid "if allocated" sort of logic later.
44
45 if ( strSize < IFDKEY_BUFSIZE ) {
46 strcpy(_stringBuf, s);
47 strVal = &_stringBuf[0];
48 _onHeap = false;
49 } else {
50 strVal = new char[ strSize ];
51 strcpy(strVal, s);
52 _onHeap = true;
53 }
54
55 enum {
56 MaxChar = 64 // Limit computation. Don't need strlen()
57 };
58
59 _hashVal = 0;
60
61 size_t n = 0;
62 while ( (s[n] != '\0') && (n < MaxChar) ) {
63 _hashVal = ( (_hashVal<<8) + s[n] ) % _nHashBuckets;
64 n++;
65 }
66}
const Int_t n
XmlRpcServer s
IfdKey(keyKind kind)
Definition IfdKey.cxx:23
unsigned int _hashVal
Definition IfdKey.h:80
@ _nHashBuckets
Definition IfdKey.h:86
@ strKey
Definition IfdKey.h:88
char * strVal
Definition IfdKey.h:128

◆ IfdStrKey() [2/2]

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

Definition at line 70 of file IfdStrKey.cxx.

73 : IfdKey( strKey )
74
75{
76 using std::string;
77 const char* s = str.c_str();
78 register size_t strSize = str.size()+1;
79
80 // register size_t strSize = strlen(s)+1;
81
82 // If the space allocated in this instance of IfdStrKey is big enough
83 // to hold the string, then put it there; otherwise do the slower operation
84 // of allocating it in the heap. Either way, make strVal point at it
85 // to avoid "if allocated" sort of logic later.
86
87 if ( strSize < IFDKEY_BUFSIZE ) {
88 strcpy(_stringBuf, s);
89 strVal = &_stringBuf[0];
90 _onHeap = false;
91 } else {
92 strVal = new char[ strSize ];
93 strcpy(strVal, s);
94 _onHeap = true;
95 }
96
97 enum {
98 MaxChar = 64 // Limit computation. Don't need strlen()
99 };
100
101 _hashVal = 0;
102
103 size_t n = 0;
104 while ( (s[n] != '\0') && (n < MaxChar) ) {
105 _hashVal = ( (_hashVal<<8) + s[n] ) % _nHashBuckets;
106 n++;
107 }
108}

◆ ~IfdStrKey()

IfdStrKey::~IfdStrKey ( )
virtual

Definition at line 141 of file IfdStrKey.cxx.

141 {
142//****************************************************************************
143 if (_onHeap) delete[] strVal;
144 strVal=0;
145}

Member Function Documentation

◆ asString()

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

Definition at line 56 of file IfdStrKey.h.

56{ return strVal; }

◆ clone()

IfdKey * IfdStrKey::clone ( void ) const
virtual

Implements IfdKey.

Definition at line 149 of file IfdStrKey.cxx.

149 {
150//****************************************************************************
151 return new IfdStrKey( strVal, _hashVal );
152}
friend class IfdStrKey
Definition IfdKey.h:133

◆ operator<()

int IfdStrKey::operator< ( const IfdKey & k) const
virtual

Definition at line 176 of file IfdStrKey.cxx.

177 {
178//****************************************************************************
179 return ( strKey == k.getKeyKind() ) && (strcmp(strVal, k.strVal) < 0);
180}
IfdKey::keyKind getKeyKind(void) const
Definition IfdKey.h:98

◆ operator==()

int IfdStrKey::operator== ( const IfdKey & k) const
virtual

Implements IfdKey.

Definition at line 156 of file IfdStrKey.cxx.

156 {
157//****************************************************************************
158
159
160 if ( (strKey == k.getKeyKind()) && (_hashVal == k._hashVal) ) {
161
162 // Then they might actually match! Check the strings.
163 // We used to use strcmp, but this is faster by x2.2.
164 char* s1 = strVal;
165 char* s2 = k.strVal;
166 while (*s1 == *s2++) {
167 if ( *s1++ == '\0') return 1; //NB: == in while => *s2 == \0 too.
168 }
169 }
170
171 return 0;
172 }

◆ print()

void IfdStrKey::print ( std::ostream & o) const
virtual

Implements IfdKey.

Definition at line 184 of file IfdStrKey.cxx.

184 {
185//****************************************************************************
186 o << "IfdStrKey(" << strVal << ")";
187}

The documentation for this class was generated from the following files: