Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #ifndef _RawHashTable_h_
00032 #define _RawHashTable_h_
00033 
00034 #include "libts.h"
00035 
00036 #include "ink_apidefs.h"
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 typedef enum
00045 {
00046   RawHashTable_KeyType_String = InkHashTableKeyType_String,
00047   RawHashTable_KeyType_Word = InkHashTableKeyType_Word
00048 } RawHashTable_KeyType;
00049 
00050 typedef InkHashTableKey RawHashTable_Key;
00051 typedef InkHashTableValue RawHashTable_Value;
00052 typedef InkHashTableEntry RawHashTable_Binding;
00053 typedef InkHashTableIteratorState RawHashTable_IteratorState;
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 class RawHashTable
00062 {
00063 private:
00064   InkHashTable * ht;
00065   RawHashTable_KeyType key_type;
00066   bool deallocate_values_on_destruct;
00067 
00068 public:
00069     inkcoreapi RawHashTable(RawHashTable_KeyType key_type, bool deallocate_values_on_destruct = false);
00070     virtual ~ RawHashTable();
00071 
00072   
00073   
00074   
00075 
00076   bool getValue(RawHashTable_Key key, RawHashTable_Value * value_ptr);
00077   void setValue(RawHashTable_Key key, RawHashTable_Value value_ptr);
00078   bool isBound(RawHashTable_Key key);
00079   bool unbindKey(RawHashTable_Key key);
00080   void replaceString(char *key, char *string);
00081 
00082   
00083   
00084   
00085 
00086   RawHashTable_Binding *getCurrentBinding(RawHashTable_Key key);
00087   RawHashTable_Binding *getOrCreateBinding(RawHashTable_Key key, bool * was_new = NULL);
00088 
00089   void setBindingValue(RawHashTable_Binding * binding, RawHashTable_Value value);
00090   RawHashTable_Key getKeyFromBinding(RawHashTable_Binding * binding);
00091   RawHashTable_Value getValueFromBinding(RawHashTable_Binding * binding);
00092 
00093   
00094   
00095   
00096 
00097   RawHashTable_Binding *firstBinding(RawHashTable_IteratorState * state_ptr);
00098   RawHashTable_Binding *nextBinding(RawHashTable_IteratorState * state_ptr);
00099 };
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 inline bool
00114 RawHashTable::getValue(RawHashTable_Key key, RawHashTable_Value * value_ptr)
00115 {
00116   int is_bound;
00117 
00118   is_bound = ink_hash_table_lookup(ht, (InkHashTableKey) key, (InkHashTableValue *) value_ptr);
00119   return (is_bound ? true : false);
00120 }
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 inline void
00133 RawHashTable::setValue(RawHashTable_Key key, RawHashTable_Value value)
00134 {
00135   ink_hash_table_insert(ht, (InkHashTableKey) key, (InkHashTableValue) value);
00136 }
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 inline bool
00149 RawHashTable::isBound(RawHashTable_Key key)
00150 {
00151   int status = ink_hash_table_isbound(ht, (InkHashTableKey) key);
00152   return (status ? true : false);
00153 }
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 inline bool
00165 RawHashTable::unbindKey(RawHashTable_Key key)
00166 {
00167   int status;
00168 
00169   status = ink_hash_table_delete(ht, (InkHashTableKey) key);
00170   return (status ? true : false);
00171 }
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 inline void
00181 RawHashTable::replaceString(char *key, char *string)
00182 {
00183 
00184 
00185 
00186 
00187 
00188   ink_hash_table_replace_string(ht, key, string);
00189 }
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 inline RawHashTable_Binding *
00198 RawHashTable::getCurrentBinding(RawHashTable_Key key)
00199 {
00200   InkHashTableEntry *he_ptr;
00201 
00202   he_ptr = ink_hash_table_lookup_entry(ht, (InkHashTableKey) key);
00203   return ((RawHashTable_Binding *) he_ptr);
00204 }
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 inline RawHashTable_Binding *
00217 RawHashTable::getOrCreateBinding(RawHashTable_Key key, bool * was_new)
00218 {
00219   int _was_new;
00220   InkHashTableEntry *he_ptr;
00221 
00222   he_ptr = ink_hash_table_get_entry(ht, (InkHashTableKey) key, &_was_new);
00223   *was_new = (_was_new ? true : false);
00224   return ((RawHashTable_Binding *) he_ptr);
00225 }
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 inline void
00238 RawHashTable::setBindingValue(RawHashTable_Binding * binding, RawHashTable_Value value)
00239 {
00240   ink_hash_table_set_entry(ht, (InkHashTableEntry *) binding, (InkHashTableValue) value);
00241 }
00242 
00243 
00244 
00245 
00246 
00247 inline RawHashTable_Key
00248 RawHashTable::getKeyFromBinding(RawHashTable_Binding * binding)
00249 {
00250   InkHashTableKey ht_key;
00251 
00252   ht_key = ink_hash_table_entry_key(ht, (InkHashTableEntry *) binding);
00253   return ((RawHashTable_Key) ht_key);
00254 }
00255 
00256 
00257 
00258 
00259 
00260 inline RawHashTable_Value
00261 RawHashTable::getValueFromBinding(RawHashTable_Binding * binding)
00262 {
00263   InkHashTableValue ht_value;
00264 
00265   ht_value = ink_hash_table_entry_value(ht, (InkHashTableEntry *) binding);
00266   return ((RawHashTable_Value) ht_value);
00267 }
00268 
00269 
00270 
00271 
00272 
00273 
00274 
00275 inline RawHashTable_Binding *
00276 RawHashTable::firstBinding(RawHashTable_IteratorState * state_ptr)
00277 {
00278   InkHashTableEntry *he_ptr;
00279 
00280   he_ptr = ink_hash_table_iterator_first(ht, (InkHashTableIteratorState *) state_ptr);
00281   return ((RawHashTable_Binding *) he_ptr);
00282 }
00283 
00284 inline
00285 RawHashTable::RawHashTable(RawHashTable_KeyType akey_type, bool adeallocate_values_on_destruct)
00286 {
00287   RawHashTable::key_type = akey_type;
00288   RawHashTable::deallocate_values_on_destruct = adeallocate_values_on_destruct;
00289   ht = ink_hash_table_create((InkHashTableKeyType) key_type);
00290 }
00291 
00292 inline
00293 RawHashTable::~
00294 RawHashTable()
00295 {
00296   if (deallocate_values_on_destruct)
00297     ink_hash_table_destroy_and_free_values(ht);
00298   else
00299     ink_hash_table_destroy(ht);
00300 }
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 inline RawHashTable_Binding *
00309 RawHashTable::nextBinding(RawHashTable_IteratorState * state_ptr)
00310 {
00311   InkHashTableEntry *he_ptr;
00312 
00313   he_ptr = ink_hash_table_iterator_next(ht, (InkHashTableIteratorState *) state_ptr);
00314   return ((RawHashTable_Binding *) he_ptr);
00315 }
00316 
00317 
00318 
00319 
00320 
00321 
00322 
00323 class RawHashTableIter
00324 {
00325 public:
00326   RawHashTableIter(RawHashTable & ht);
00327   ~RawHashTableIter();
00328 
00329   RawHashTable_Value & operator ++();   
00330   RawHashTable_Value & operator () () const;    
00331   operator  const void *() const;       
00332 
00333     RawHashTable_Value & value() const; 
00334   const char *key() const;      
00335 
00336 
00337 private:
00338     RawHashTable & m_ht;
00339   RawHashTable_Binding *m_currentBinding;
00340   RawHashTable_IteratorState m_hashIterState;
00341 };
00342 
00343 
00344 
00345 
00346 
00347 
00348 
00349 inline RawHashTable_Value &
00350 RawHashTableIter::operator () ()
00351 const
00352 {
00353   return (m_currentBinding->clientData);
00354 }
00355 
00356 inline RawHashTable_Value &
00357 RawHashTableIter::operator ++()
00358 {
00359   m_currentBinding = m_ht.nextBinding(&m_hashIterState);
00360   return (m_currentBinding->clientData);
00361 }
00362 
00363 inline
00364 RawHashTableIter::operator  const void *()
00365 const
00366 {
00367   return ((m_currentBinding != 0) ? this : 0);
00368 }
00369 
00370 inline
00371   RawHashTable_Value &
00372 RawHashTableIter::value() const
00373 {
00374   return (m_currentBinding->clientData);
00375 }
00376 
00377 inline const char *
00378 RawHashTableIter::key() const
00379 {
00380   return (m_currentBinding->key.string);
00381 }
00382 
00383 inline
00384 RawHashTableIter::RawHashTableIter(RawHashTable & ht)
00385   :
00386 m_ht(ht),
00387 m_currentBinding(0)
00388 {
00389   m_currentBinding = m_ht.firstBinding(&m_hashIterState);
00390   return;
00391 }
00392 
00393 inline
00394 RawHashTableIter::~
00395 RawHashTableIter()
00396 {
00397   return;
00398 }
00399 
00400 #endif