GamepadHandle.cpp (1209B)
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 #include "GamepadHandle.h" 8 9 #include "mozilla/Assertions.h" 10 #include "mozilla/HashFunctions.h" 11 12 namespace mozilla::dom { 13 14 GamepadHandle::GamepadHandle(uint32_t aValue, GamepadHandleKind aKind) 15 : mValue(aValue), mKind(aKind) { 16 MOZ_RELEASE_ASSERT(mValue); 17 } 18 19 GamepadHandleKind GamepadHandle::GetKind() const { return mKind; } 20 21 PLDHashNumber GamepadHandle::Hash() const { 22 return HashGeneric(mValue, uint8_t(mKind)); 23 } 24 25 bool operator==(const GamepadHandle& a, const GamepadHandle& b) { 26 return (a.mValue == b.mValue) && (a.mKind == b.mKind); 27 } 28 29 bool operator!=(const GamepadHandle& a, const GamepadHandle& b) { 30 return !(a == b); 31 } 32 33 bool operator<(const GamepadHandle& a, const GamepadHandle& b) { 34 if (a.mKind == b.mKind) { 35 return a.mValue < b.mValue; 36 } 37 // Arbitrarily order them by kind 38 return uint8_t(a.mKind) < uint8_t(b.mKind); 39 } 40 41 } // namespace mozilla::dom