IdType.h (1494B)
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 #ifndef mozilla_dom_IdType_h 8 #define mozilla_dom_IdType_h 9 10 #include "ipc/IPCMessageUtils.h" 11 12 namespace IPC { 13 template <typename T> 14 struct ParamTraits; 15 } // namespace IPC 16 17 namespace mozilla::dom { 18 class BrowsingContext; 19 class ContentParent; 20 class BrowserParent; 21 22 template <typename T> 23 class IdType { 24 friend struct IPC::ParamTraits<IdType<T>>; 25 26 public: 27 IdType() : mId(0) {} 28 explicit IdType(uint64_t aId) : mId(aId) {} 29 30 operator uint64_t() const { return mId; } 31 32 IdType& operator=(uint64_t aId) { 33 mId = aId; 34 return *this; 35 } 36 37 bool operator<(const IdType& rhs) { return mId < rhs.mId; } 38 39 private: 40 uint64_t mId; 41 }; 42 43 using TabId = IdType<BrowserParent>; 44 using ContentParentId = IdType<ContentParent>; 45 } // namespace mozilla::dom 46 47 namespace IPC { 48 49 template <typename T> 50 struct ParamTraits<mozilla::dom::IdType<T>> { 51 using paramType = mozilla::dom::IdType<T>; 52 53 static void Write(MessageWriter* aWriter, const paramType& aParam) { 54 WriteParam(aWriter, aParam.mId); 55 } 56 57 static bool Read(MessageReader* aReader, paramType* aResult) { 58 return ReadParam(aReader, &aResult->mId); 59 } 60 }; 61 62 } // namespace IPC 63 64 #endif // mozilla_dom_IdType_h