Line data Source code
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/. */
6 :
7 : /**
8 : * Class for representing record arguments. Basically an array under the hood.
9 : */
10 :
11 : #ifndef mozilla_dom_Record_h
12 : #define mozilla_dom_Record_h
13 :
14 : #include "nsTHashtable.h"
15 : #include "nsHashKeys.h"
16 : #include "nsStringGlue.h"
17 : #include "nsTArray.h"
18 : #include "mozilla/Attributes.h"
19 : #include "mozilla/Move.h"
20 :
21 : namespace mozilla {
22 : namespace dom {
23 :
24 : namespace binding_detail {
25 : template<typename KeyType, typename ValueType>
26 0 : class RecordEntry
27 : {
28 : public:
29 0 : RecordEntry()
30 0 : {
31 0 : }
32 :
33 : // Move constructor so we can do Records of Records.
34 : RecordEntry(RecordEntry<KeyType, ValueType>&& aOther)
35 : : mKey(Move(aOther.mKey)),
36 : mValue(Move(aOther.mValue))
37 : {
38 : }
39 :
40 : KeyType mKey;
41 : ValueType mValue;
42 : };
43 :
44 : } // namespace binding_detail
45 :
46 : template<typename KeyType, typename ValueType>
47 0 : class Record
48 : {
49 : public:
50 : typedef typename binding_detail::RecordEntry<KeyType, ValueType> EntryType;
51 : typedef Record<KeyType, ValueType> SelfType;
52 :
53 0 : Record()
54 0 : {
55 0 : }
56 :
57 : // Move constructor so we can do Record of Record.
58 : Record(SelfType&& aOther) :
59 : mEntries(Move(aOther.mEntries))
60 : {
61 : }
62 :
63 0 : const nsTArray<EntryType>& Entries() const
64 : {
65 0 : return mEntries;
66 : }
67 :
68 0 : nsTArray<EntryType>& Entries()
69 : {
70 0 : return mEntries;
71 : }
72 :
73 : private:
74 : nsTArray<EntryType> mEntries;
75 : };
76 :
77 : } // namespace dom
78 : } // namespace mozilla
79 :
80 : template<typename K, typename V>
81 : class nsDefaultComparator<mozilla::dom::binding_detail::RecordEntry<K, V>, K>
82 : {
83 : public:
84 0 : bool Equals(const mozilla::dom::binding_detail::RecordEntry<K, V>& aEntry,
85 : const K& aKey) const
86 : {
87 0 : return aEntry.mKey == aKey;
88 : }
89 : };
90 :
91 : #endif // mozilla_dom_Record_h
|