Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / bindings / Record.h
blob1c9145a40de58cf6cc317a626abd28853c6f83e9
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 /**
8 * Class for representing record arguments. Basically an array under the hood.
9 */
11 #ifndef mozilla_dom_Record_h
12 #define mozilla_dom_Record_h
14 #include <utility>
16 #include "mozilla/Attributes.h"
17 #include "nsHashKeys.h"
18 #include "nsString.h"
19 #include "nsTArray.h"
20 #include "nsTHashtable.h"
22 namespace mozilla::dom {
24 namespace binding_detail {
25 template <typename KeyType, typename ValueType>
26 class RecordEntry {
27 public:
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)) {}
34 KeyType mKey;
35 ValueType 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*> {
42 public:
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)) {}
49 KeyType mKey;
50 JSObject* mValue;
53 } // namespace binding_detail
55 template <typename KeyType, typename ValueType>
56 class Record {
57 public:
58 typedef typename binding_detail::RecordEntry<KeyType, ValueType> EntryType;
59 typedef Record<KeyType, ValueType> SelfType;
61 Record() = default;
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; }
70 private:
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> {
78 public:
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