Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / dom / midi / MIDIInputMap.h
blob5826290dbc813eeaedf82a7548fcdf866e6c117d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 #ifndef mozilla_dom_MIDIInputMap_h
8 #define mozilla_dom_MIDIInputMap_h
10 #include "mozilla/dom/MIDIPort.h"
11 #include "nsCOMPtr.h"
12 #include "nsTHashMap.h"
13 #include "nsWrapperCache.h"
15 class nsPIDOMWindowInner;
17 namespace mozilla::dom {
19 /**
20 * Maplike DOM object that holds a list of all MIDI input ports available for
21 * access. Almost all functions are implemented automatically by WebIDL.
23 class MIDIInputMap final : public nsISupports, public nsWrapperCache {
24 public:
25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(MIDIInputMap)
27 nsPIDOMWindowInner* GetParentObject() const { return mParent; }
29 explicit MIDIInputMap(nsPIDOMWindowInner* aParent);
30 JSObject* WrapObject(JSContext* aCx,
31 JS::Handle<JSObject*> aGivenProto) override;
32 bool Has(nsAString& aId) { return mPorts.Get(aId) != nullptr; }
33 void Insert(nsAString& aId, RefPtr<MIDIPort> aPort) {
34 mPorts.InsertOrUpdate(aId, aPort);
36 void Remove(nsAString& aId) { mPorts.Remove(aId); }
38 private:
39 ~MIDIInputMap() = default;
40 nsTHashMap<nsString, RefPtr<MIDIPort>> mPorts;
41 nsCOMPtr<nsPIDOMWindowInner> mParent;
44 } // namespace mozilla::dom
46 #endif // mozilla_dom_MIDIInputMap_h