Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / dom / ipc / IdType.h
blobccf8b52693267376ed14aeb784e38f8ecd43a659
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/. */
7 #ifndef mozilla_dom_IdType_h
8 #define mozilla_dom_IdType_h
10 #include "ipc/IPCMessageUtils.h"
12 namespace IPC {
13 template <typename T>
14 struct ParamTraits;
15 } // namespace IPC
17 namespace mozilla::dom {
18 class BrowsingContext;
19 class ContentParent;
20 class BrowserParent;
22 template <typename T>
23 class IdType {
24 friend struct IPC::ParamTraits<IdType<T>>;
26 public:
27 IdType() : mId(0) {}
28 explicit IdType(uint64_t aId) : mId(aId) {}
30 operator uint64_t() const { return mId; }
32 IdType& operator=(uint64_t aId) {
33 mId = aId;
34 return *this;
37 bool operator<(const IdType& rhs) { return mId < rhs.mId; }
39 private:
40 uint64_t mId;
43 using TabId = IdType<BrowserParent>;
44 using ContentParentId = IdType<ContentParent>;
45 } // namespace mozilla::dom
47 namespace IPC {
49 template <typename T>
50 struct ParamTraits<mozilla::dom::IdType<T>> {
51 using paramType = mozilla::dom::IdType<T>;
53 static void Write(MessageWriter* aWriter, const paramType& aParam) {
54 WriteParam(aWriter, aParam.mId);
57 static bool Read(MessageReader* aReader, paramType* aResult) {
58 return ReadParam(aReader, &aResult->mId);
62 } // namespace IPC
64 #endif // mozilla_dom_IdType_h