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"
15 #include "nsHashKeys.h"
16 #include "nsAtomHashKeys.h"
17 #include "nsHashtablesFwd.h"
18 #include <type_traits>
20 namespace mozilla::detail
{
21 template <class KeyType
>
23 KeyType
, std::enable_if_t
<sizeof(KeyType
) &&
24 std::is_base_of_v
<PLDHashEntryHdr
, KeyType
>>> {
28 template <typename KeyType
>
29 struct nsKeyClass
<KeyType
*> {
30 using type
= nsPtrHashKey
<KeyType
>;
34 struct nsKeyClass
<nsAtom
*> {
35 using type
= nsWeakAtomHashKey
;
38 template <typename Ret
, typename
... Args
>
39 struct nsKeyClass
<Ret (*)(Args
...)> {
40 using type
= nsFuncPtrHashKey
<Ret (*)(Args
...)>;
44 struct nsKeyClass
<nsCString
> {
45 using type
= nsCStringHashKey
;
48 // This uses the case-sensitive hash key class, if you want the
49 // case-insensitive hash key, use nsStringCaseInsensitiveHashKey explicitly.
51 struct nsKeyClass
<nsString
> {
52 using type
= nsStringHashKey
;
55 template <typename KeyType
>
56 struct nsKeyClass
<KeyType
, std::enable_if_t
<std::is_integral_v
<KeyType
> ||
57 std::is_enum_v
<KeyType
>>> {
58 using type
= nsIntegralHashKey
<KeyType
>;
62 struct nsKeyClass
<nsCOMPtr
<nsISupports
>> {
63 using type
= nsISupportsHashKey
;
67 struct nsKeyClass
<RefPtr
<T
>> {
68 using type
= nsRefPtrHashKey
<T
>;
72 struct nsKeyClass
<RefPtr
<nsAtom
>> {
73 using type
= nsAtomHashKey
;
77 struct nsKeyClass
<nsID
> {
78 using type
= nsIDHashKey
;
81 } // namespace mozilla::detail
83 // The actual definition of nsTHashMap is in nsHashtablesFwd.h, since it is a
86 #endif // XPCOM_DS_NSTHASHMAP_H_