/src/icu/source/common/charstrmap.h
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | // © 2020 and later: Unicode, Inc. and others.  | 
2  |  | // License & terms of use: http://www.unicode.org/copyright.html  | 
3  |  |  | 
4  |  | // charstrmap.h  | 
5  |  | // created: 2020sep01 Frank Yung-Fong Tang  | 
6  |  |  | 
7  |  | #ifndef __CHARSTRMAP_H__  | 
8  |  | #define __CHARSTRMAP_H__  | 
9  |  |  | 
10  |  | #include <utility>  | 
11  |  | #include "unicode/utypes.h"  | 
12  |  | #include "unicode/uobject.h"  | 
13  |  | #include "uhash.h"  | 
14  |  |  | 
15  |  | U_NAMESPACE_BEGIN  | 
16  |  |  | 
17  |  | /**  | 
18  |  |  * Map of const char * keys & values.  | 
19  |  |  * Stores pointers as is: Does not own/copy/adopt/release strings.  | 
20  |  |  */  | 
21  |  | class CharStringMap final : public UMemory { | 
22  |  | public:  | 
23  |  |     /** Constructs an unusable non-map. */  | 
24  | 0  |     CharStringMap() : map(nullptr) {} | 
25  | 0  |     CharStringMap(int32_t size, UErrorCode &errorCode) { | 
26  | 0  |         map = uhash_openSize(uhash_hashChars, uhash_compareChars, uhash_compareChars,  | 
27  | 0  |                              size, &errorCode);  | 
28  | 0  |     }  | 
29  | 0  |     CharStringMap(CharStringMap &&other) U_NOEXCEPT : map(other.map) { | 
30  | 0  |         other.map = nullptr;  | 
31  | 0  |     }  | 
32  |  |     CharStringMap(const CharStringMap &other) = delete;  | 
33  | 0  |     ~CharStringMap() { | 
34  | 0  |         uhash_close(map);  | 
35  | 0  |     }  | 
36  |  |  | 
37  | 0  |     CharStringMap &operator=(CharStringMap &&other) U_NOEXCEPT { | 
38  | 0  |         map = other.map;  | 
39  | 0  |         other.map = nullptr;  | 
40  | 0  |         return *this;  | 
41  | 0  |     }  | 
42  |  |     CharStringMap &operator=(const CharStringMap &other) = delete;  | 
43  |  |  | 
44  | 0  |     const char *get(const char *key) const { return static_cast<const char *>(uhash_get(map, key)); } | 
45  | 0  |     void put(const char *key, const char *value, UErrorCode &errorCode) { | 
46  | 0  |         uhash_put(map, const_cast<char *>(key), const_cast<char *>(value), &errorCode);  | 
47  | 0  |     }  | 
48  |  |  | 
49  |  | private:  | 
50  |  |     UHashtable *map;  | 
51  |  | };  | 
52  |  |  | 
53  |  | U_NAMESPACE_END  | 
54  |  |  | 
55  |  | #endif  //  __CHARSTRMAP_H__  |