Record.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /**
  6. * Class for representing record arguments. Basically an array under the hood.
  7. */
  8. #ifndef mozilla_dom_Record_h
  9. #define mozilla_dom_Record_h
  10. #include "nsTHashtable.h"
  11. #include "nsHashKeys.h"
  12. #include "nsStringGlue.h"
  13. #include "nsTArray.h"
  14. #include "mozilla/Attributes.h"
  15. #include "mozilla/Move.h"
  16. namespace mozilla {
  17. namespace dom {
  18. namespace binding_detail {
  19. template<typename KeyType, typename ValueType>
  20. class RecordEntry
  21. {
  22. public:
  23. RecordEntry()
  24. {
  25. }
  26. // Move constructor so we can do Records of Records.
  27. RecordEntry(RecordEntry<KeyType, ValueType>&& aOther)
  28. : mKey(Move(aOther.mKey)),
  29. mValue(Move(aOther.mValue))
  30. {
  31. }
  32. KeyType mKey;
  33. ValueType mValue;
  34. };
  35. } // namespace binding_detail
  36. template<typename KeyType, typename ValueType>
  37. class Record
  38. {
  39. public:
  40. typedef typename binding_detail::RecordEntry<KeyType, ValueType> EntryType;
  41. typedef Record<KeyType, ValueType> SelfType;
  42. Record()
  43. {
  44. }
  45. // Move constructor so we can do Record of Record.
  46. Record(SelfType&& aOther) :
  47. mEntries(Move(aOther.mEntries))
  48. {
  49. }
  50. const nsTArray<EntryType>& Entries() const
  51. {
  52. return mEntries;
  53. }
  54. nsTArray<EntryType>& Entries()
  55. {
  56. return mEntries;
  57. }
  58. private:
  59. nsTArray<EntryType> mEntries;
  60. };
  61. } // namespace dom
  62. } // namespace mozilla
  63. template<typename K, typename V>
  64. class nsDefaultComparator<mozilla::dom::binding_detail::RecordEntry<K, V>, K>
  65. {
  66. public:
  67. bool Equals(const mozilla::dom::binding_detail::RecordEntry<K, V>& aEntry,
  68. const K& aKey) const
  69. {
  70. return aEntry.mKey == aKey;
  71. }
  72. };
  73. #endif // mozilla_dom_Record_h