Bug 1825336 - Make toolkit/components/url-classifier/ buildable outside of a unified...
[gecko.git] / xpcom / ds / nsTHashMap.h
blob8357d2ae7bcdc55d92739e1894cea80799878097
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef XPCOM_DS_NSTHASHMAP_H_
8 #define XPCOM_DS_NSTHASHMAP_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/UniquePtr.h"
13 #include "nsBaseHashtable.h"
14 #include "nsCOMPtr.h"
15 #include "nsHashKeys.h"
16 #include "nsHashtablesFwd.h"
17 #include <type_traits>
19 namespace mozilla::detail {
20 template <class KeyType>
21 struct nsKeyClass<
22 KeyType, std::enable_if_t<sizeof(KeyType) &&
23 std::is_base_of_v<PLDHashEntryHdr, KeyType>>> {
24 using type = KeyType;
27 template <typename KeyType>
28 struct nsKeyClass<KeyType*> {
29 using type = nsPtrHashKey<KeyType>;
32 template <>
33 struct nsKeyClass<nsCString> {
34 using type = nsCStringHashKey;
37 // This uses the case-sensitive hash key class, if you want the
38 // case-insensitive hash key, use nsStringCaseInsensitiveHashKey explicitly.
39 template <>
40 struct nsKeyClass<nsString> {
41 using type = nsStringHashKey;
44 template <typename KeyType>
45 struct nsKeyClass<KeyType, std::enable_if_t<std::is_integral_v<KeyType> ||
46 std::is_enum_v<KeyType>>> {
47 using type = nsIntegralHashKey<KeyType>;
50 template <>
51 struct nsKeyClass<nsCOMPtr<nsISupports>> {
52 using type = nsISupportsHashKey;
55 template <typename T>
56 struct nsKeyClass<RefPtr<T>> {
57 using type = nsRefPtrHashKey<T>;
60 template <>
61 struct nsKeyClass<nsID> {
62 using type = nsIDHashKey;
65 } // namespace mozilla::detail
67 // The actual definition of nsTHashMap is in nsHashtablesFwd.h, since it is a
68 // type alias.
70 #endif // XPCOM_DS_NSTHASHMAP_H_