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/. */
8 * Class for representing record arguments. Basically an array under the hood.
11 #ifndef mozilla_dom_Record_h
12 #define mozilla_dom_Record_h
16 #include "mozilla/Attributes.h"
17 #include "nsHashKeys.h"
20 #include "nsTHashtable.h"
22 namespace mozilla::dom
{
24 namespace binding_detail
{
25 template <typename KeyType
, typename ValueType
>
28 RecordEntry() = default;
30 // Move constructor so we can do Records of Records.
31 RecordEntry(RecordEntry
<KeyType
, ValueType
>&& aOther
)
32 : mKey(std::move(aOther
.mKey
)), mValue(std::move(aOther
.mValue
)) {}
38 // Specialize for a JSObject* ValueType and initialize it on construction, so we
39 // don't need to worry about un-initialized JSObject* floating around.
40 template <typename KeyType
>
41 class RecordEntry
<KeyType
, JSObject
*> {
43 RecordEntry() : mValue(nullptr) {}
45 // Move constructor so we can do Records of Records.
46 RecordEntry(RecordEntry
<KeyType
, JSObject
*>&& aOther
)
47 : mKey(std::move(aOther
.mKey
)), mValue(std::move(aOther
.mValue
)) {}
53 } // namespace binding_detail
55 template <typename KeyType
, typename ValueType
>
58 typedef typename
binding_detail::RecordEntry
<KeyType
, ValueType
> EntryType
;
59 typedef Record
<KeyType
, ValueType
> SelfType
;
63 // Move constructor so we can do Record of Record.
64 Record(SelfType
&& aOther
) : mEntries(std::move(aOther
.mEntries
)) {}
66 const nsTArray
<EntryType
>& Entries() const { return mEntries
; }
68 nsTArray
<EntryType
>& Entries() { return mEntries
; }
71 nsTArray
<EntryType
> mEntries
;
74 } // namespace mozilla::dom
76 template <typename K
, typename V
>
77 class nsDefaultComparator
<mozilla::dom::binding_detail::RecordEntry
<K
, V
>, K
> {
79 bool Equals(const mozilla::dom::binding_detail::RecordEntry
<K
, V
>& aEntry
,
80 const K
& aKey
) const {
81 return aEntry
.mKey
== aKey
;
85 #endif // mozilla_dom_Record_h