2014-05-23 21:32:38 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/**
|
2017-02-15 05:01:35 +00:00
|
|
|
* Class for representing record arguments. Basically an array under the hood.
|
2014-05-23 21:32:38 +00:00
|
|
|
*/
|
|
|
|
|
2017-02-15 05:01:35 +00:00
|
|
|
#ifndef mozilla_dom_Record_h
|
|
|
|
#define mozilla_dom_Record_h
|
2014-05-23 21:32:38 +00:00
|
|
|
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2017-12-07 00:52:51 +00:00
|
|
|
#include "nsString.h"
|
2014-05-23 21:32:38 +00:00
|
|
|
#include "nsTArray.h"
|
2015-03-19 07:46:40 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-05-23 21:32:38 +00:00
|
|
|
#include "mozilla/Move.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace binding_detail {
|
2017-02-15 05:00:00 +00:00
|
|
|
template <typename KeyType, typename ValueType>
|
2017-02-15 05:01:35 +00:00
|
|
|
class RecordEntry {
|
2014-05-23 21:32:38 +00:00
|
|
|
public:
|
2017-02-15 05:01:35 +00:00
|
|
|
RecordEntry() {}
|
2014-05-23 21:32:38 +00:00
|
|
|
|
2017-02-15 05:01:35 +00:00
|
|
|
// Move constructor so we can do Records of Records.
|
|
|
|
RecordEntry(RecordEntry<KeyType, ValueType>&& aOther)
|
2018-05-30 19:15:35 +00:00
|
|
|
: mKey(std::move(aOther.mKey)), mValue(std::move(aOther.mValue)) {}
|
2014-05-23 21:32:38 +00:00
|
|
|
|
2017-02-15 05:00:00 +00:00
|
|
|
KeyType mKey;
|
|
|
|
ValueType mValue;
|
2014-05-23 21:32:38 +00:00
|
|
|
};
|
2015-07-13 15:25:42 +00:00
|
|
|
|
2019-04-16 19:18:52 +00:00
|
|
|
// Specialize for a JSObject* ValueType and initialize it on construction, so we
|
|
|
|
// don't need to worry about un-initialized JSObject* floating around.
|
|
|
|
template <typename KeyType>
|
|
|
|
class RecordEntry<KeyType, JSObject*> {
|
|
|
|
public:
|
|
|
|
RecordEntry() : mValue(nullptr) {}
|
|
|
|
|
|
|
|
// Move constructor so we can do Records of Records.
|
|
|
|
RecordEntry(RecordEntry<KeyType, JSObject*>&& aOther)
|
|
|
|
: mKey(std::move(aOther.mKey)), mValue(std::move(aOther.mValue)) {}
|
|
|
|
|
|
|
|
KeyType mKey;
|
|
|
|
JSObject* mValue;
|
|
|
|
};
|
|
|
|
|
2014-05-23 21:32:38 +00:00
|
|
|
} // namespace binding_detail
|
|
|
|
|
2017-02-15 05:01:35 +00:00
|
|
|
template <typename KeyType, typename ValueType>
|
|
|
|
class Record {
|
2014-05-23 21:32:38 +00:00
|
|
|
public:
|
2017-02-15 05:01:39 +00:00
|
|
|
typedef typename binding_detail::RecordEntry<KeyType, ValueType> EntryType;
|
2017-02-15 05:01:35 +00:00
|
|
|
typedef Record<KeyType, ValueType> SelfType;
|
2014-05-23 21:32:38 +00:00
|
|
|
|
2017-02-15 05:01:35 +00:00
|
|
|
Record() {}
|
2014-05-23 21:32:38 +00:00
|
|
|
|
2017-02-15 05:01:35 +00:00
|
|
|
// Move constructor so we can do Record of Record.
|
2018-05-30 19:15:35 +00:00
|
|
|
Record(SelfType&& aOther) : mEntries(std::move(aOther.mEntries)) {}
|
2014-05-23 21:32:38 +00:00
|
|
|
|
2017-02-15 05:00:00 +00:00
|
|
|
const nsTArray<EntryType>& Entries() const { return mEntries; }
|
2014-05-23 21:32:38 +00:00
|
|
|
|
2017-02-15 05:00:00 +00:00
|
|
|
nsTArray<EntryType>& Entries() { return mEntries; }
|
2014-06-25 17:25:09 +00:00
|
|
|
|
2017-02-15 05:00:00 +00:00
|
|
|
private:
|
|
|
|
nsTArray<EntryType> mEntries;
|
2014-05-23 21:32:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2017-02-15 05:01:41 +00:00
|
|
|
template <typename K, typename V>
|
|
|
|
class nsDefaultComparator<mozilla::dom::binding_detail::RecordEntry<K, V>, K> {
|
|
|
|
public:
|
|
|
|
bool Equals(const mozilla::dom::binding_detail::RecordEntry<K, V>& aEntry,
|
|
|
|
const K& aKey) const {
|
|
|
|
return aEntry.mKey == aKey;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-15 05:01:35 +00:00
|
|
|
#endif // mozilla_dom_Record_h
|