Path: blob/master/thirdparty/icu4c/common/charstrmap.h
9903 views
// © 2020 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html23// charstrmap.h4// created: 2020sep01 Frank Yung-Fong Tang56#ifndef __CHARSTRMAP_H__7#define __CHARSTRMAP_H__89#include <utility>10#include "unicode/utypes.h"11#include "unicode/uobject.h"12#include "uhash.h"1314U_NAMESPACE_BEGIN1516/**17* Map of const char * keys & values.18* Stores pointers as is: Does not own/copy/adopt/release strings.19*/20class CharStringMap final : public UMemory {21public:22/** Constructs an unusable non-map. */23CharStringMap() : map(nullptr) {}24CharStringMap(int32_t size, UErrorCode &errorCode) {25map = uhash_openSize(uhash_hashChars, uhash_compareChars, uhash_compareChars,26size, &errorCode);27}28CharStringMap(CharStringMap &&other) noexcept : map(other.map) {29other.map = nullptr;30}31CharStringMap(const CharStringMap &other) = delete;32~CharStringMap() {33uhash_close(map);34}3536CharStringMap &operator=(CharStringMap &&other) noexcept {37map = other.map;38other.map = nullptr;39return *this;40}41CharStringMap &operator=(const CharStringMap &other) = delete;4243const char *get(const char *key) const { return static_cast<const char *>(uhash_get(map, key)); }44void put(const char *key, const char *value, UErrorCode &errorCode) {45uhash_put(map, const_cast<char *>(key), const_cast<char *>(value), &errorCode);46}4748private:49UHashtable *map;50};5152U_NAMESPACE_END5354#endif // __CHARSTRMAP_H__555657