Line data Source code
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> struct ParamTraits;
14 : } // namespace IPC
15 :
16 : namespace mozilla {
17 : namespace dom {
18 : class ContentParent;
19 : class TabParent;
20 :
21 :
22 : template<typename T>
23 : class IdType
24 : {
25 : friend struct IPC::ParamTraits<IdType<T>>;
26 :
27 : public:
28 18 : IdType() : mId(0) {}
29 13 : explicit IdType(uint64_t aId) : mId(aId) {}
30 :
31 32 : operator uint64_t() const { return mId; }
32 :
33 2 : IdType& operator=(uint64_t aId)
34 : {
35 2 : mId = aId;
36 2 : return *this;
37 : }
38 :
39 : bool operator<(const IdType& rhs)
40 : {
41 : return mId < rhs.mId;
42 : }
43 : private:
44 : uint64_t mId;
45 : };
46 :
47 : typedef IdType<TabParent> TabId;
48 : typedef IdType<ContentParent> ContentParentId;
49 :
50 : } // namespace dom
51 : } // namespace mozilla
52 :
53 : namespace IPC {
54 :
55 : template<typename T>
56 : struct ParamTraits<mozilla::dom::IdType<T>>
57 : {
58 : typedef mozilla::dom::IdType<T> paramType;
59 :
60 5 : static void Write(Message* aMsg, const paramType& aParam)
61 : {
62 5 : WriteParam(aMsg, aParam.mId);
63 5 : }
64 :
65 7 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
66 : {
67 7 : return ReadParam(aMsg, aIter, &aResult->mId);
68 : }
69 : };
70 :
71 : } // namespace IPC
72 :
73 : #endif // mozilla_dom_IdType_h
|