Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

hash.h

Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 *   Copyright (C) 1997-2000, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 *******************************************************************************
00006 *   Date        Name        Description
00007 *   03/28/00    aliu        Creation.
00008 *******************************************************************************
00009 */
00010 
00011 #ifndef HASH_H
00012 #define HASH_H
00013 
00014 #include "uhash.h"
00015 #include "unicode/unistr.h"
00016 
00024 class Hashtable {
00025     UHashtable* hash;
00026 
00027 public:
00028     Hashtable(UErrorCode& status);
00029 
00034     Hashtable();
00035 
00040     ~Hashtable();
00041 
00042     UObjectDeleter setValueDeleter(UObjectDeleter fn);
00043 
00044     int32_t count() const;
00045 
00046     void* put(const UnicodeString& key, void* value, UErrorCode& status);
00047 
00048     void* get(const UnicodeString& key) const;
00049     
00050     void* remove(const UnicodeString& key);
00051 
00052     const UHashElement* nextElement(int32_t& pos) const;
00053 };
00054 
00055 /*********************************************************************
00056  * Implementation
00057  ********************************************************************/
00058 
00059 inline Hashtable::Hashtable(UErrorCode& status) : hash(0) {
00060     if (U_FAILURE(status)) {
00061         return;
00062     }
00063     hash = uhash_open(uhash_hashUnicodeString,
00064                       uhash_compareUnicodeString, &status);
00065     if (U_SUCCESS(status)) {
00066         uhash_setKeyDeleter(hash, uhash_deleteUnicodeString);
00067     }
00068 }
00069 
00070 inline Hashtable::Hashtable() : hash(0) {
00071     UErrorCode status = U_ZERO_ERROR;
00072     hash = uhash_open(uhash_hashUnicodeString,
00073                       uhash_compareUnicodeString, &status);
00074     if (U_SUCCESS(status)) {
00075         uhash_setKeyDeleter(hash, uhash_deleteUnicodeString);
00076     }
00077 }
00078 
00079 inline Hashtable::~Hashtable() {
00080     if (hash != 0) {
00081         uhash_close(hash);
00082         hash = 0;
00083     }
00084 }
00085 
00086 inline UObjectDeleter Hashtable::setValueDeleter(UObjectDeleter fn) {
00087     return uhash_setValueDeleter(hash, fn);
00088 }
00089 
00090 inline int32_t Hashtable::count() const {
00091     return uhash_count(hash);
00092 }
00093 
00094 inline void* Hashtable::put(const UnicodeString& key, void* value, UErrorCode& status) {
00095     return uhash_put(hash, new UnicodeString(key), value, &status);
00096 }
00097 
00098 inline void* Hashtable::get(const UnicodeString& key) const {
00099     return uhash_get(hash, &key);
00100 }
00101 
00102 inline void* Hashtable::remove(const UnicodeString& key) {
00103     return uhash_remove(hash, &key);
00104 }
00105 
00106 inline const UHashElement* Hashtable::nextElement(int32_t& pos) const {
00107     return uhash_nextElement(hash, &pos);
00108 }
00109 
00110 #endif

Generated at Tue Dec 5 17:55:28 2000 for ICU by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000