|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsID_h__ |
|
7 #define nsID_h__ |
|
8 |
|
9 #include <string.h> |
|
10 |
|
11 #include "nscore.h" |
|
12 |
|
13 #define NSID_LENGTH 39 |
|
14 |
|
15 /** |
|
16 * A "unique identifier". This is modeled after OSF DCE UUIDs. |
|
17 */ |
|
18 |
|
19 struct nsID { |
|
20 /** |
|
21 * @name Identifier values |
|
22 */ |
|
23 |
|
24 //@{ |
|
25 uint32_t m0; |
|
26 uint16_t m1; |
|
27 uint16_t m2; |
|
28 uint8_t m3[8]; |
|
29 //@} |
|
30 |
|
31 /** |
|
32 * @name Methods |
|
33 */ |
|
34 |
|
35 //@{ |
|
36 /** |
|
37 * Equivalency method. Compares this nsID with another. |
|
38 * @return <b>true</b> if they are the same, <b>false</b> if not. |
|
39 */ |
|
40 |
|
41 inline bool Equals(const nsID& other) const { |
|
42 // Unfortunately memcmp isn't faster than this. |
|
43 return |
|
44 ((((uint32_t*) &m0)[0] == ((uint32_t*) &other.m0)[0]) && |
|
45 (((uint32_t*) &m0)[1] == ((uint32_t*) &other.m0)[1]) && |
|
46 (((uint32_t*) &m0)[2] == ((uint32_t*) &other.m0)[2]) && |
|
47 (((uint32_t*) &m0)[3] == ((uint32_t*) &other.m0)[3])); |
|
48 } |
|
49 |
|
50 /** |
|
51 * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} |
|
52 * string into an nsID |
|
53 */ |
|
54 NS_COM_GLUE bool Parse(const char *aIDStr); |
|
55 |
|
56 #ifndef XPCOM_GLUE_AVOID_NSPR |
|
57 /** |
|
58 * nsID string encoder. Returns an allocated string in |
|
59 * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string. |
|
60 * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW. |
|
61 */ |
|
62 NS_COM_GLUE char* ToString() const; |
|
63 |
|
64 /** |
|
65 * nsID string encoder. Builds a string in |
|
66 * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH] |
|
67 * buffer provided by the caller (for instance, on the stack). |
|
68 */ |
|
69 NS_COM_GLUE void ToProvidedString(char (&dest)[NSID_LENGTH]) const; |
|
70 |
|
71 #endif // XPCOM_GLUE_AVOID_NSPR |
|
72 |
|
73 //@} |
|
74 }; |
|
75 |
|
76 /* |
|
77 * Class IDs |
|
78 */ |
|
79 |
|
80 typedef nsID nsCID; |
|
81 |
|
82 // Define an CID |
|
83 #define NS_DEFINE_CID(_name, _cidspec) \ |
|
84 const nsCID _name = _cidspec |
|
85 |
|
86 #define NS_DEFINE_NAMED_CID(_name) \ |
|
87 static nsCID k##_name = _name |
|
88 |
|
89 #define REFNSCID const nsCID& |
|
90 |
|
91 /** |
|
92 * An "interface id" which can be used to uniquely identify a given |
|
93 * interface. |
|
94 */ |
|
95 |
|
96 typedef nsID nsIID; |
|
97 |
|
98 /** |
|
99 * A macro shorthand for <tt>const nsIID&<tt> |
|
100 */ |
|
101 |
|
102 #define REFNSIID const nsIID& |
|
103 |
|
104 /** |
|
105 * Define an IID |
|
106 * obsolete - do not use this macro |
|
107 */ |
|
108 |
|
109 #define NS_DEFINE_IID(_name, _iidspec) \ |
|
110 const nsIID _name = _iidspec |
|
111 |
|
112 /** |
|
113 * A macro to build the static const IID accessor method. The Dummy |
|
114 * template parameter only exists so that the kIID symbol will be linked |
|
115 * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions |
|
116 * merged on windows). Dummy should always be instantiated as "int". |
|
117 */ |
|
118 |
|
119 #define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \ |
|
120 template <class Dummy> \ |
|
121 struct COMTypeInfo \ |
|
122 { \ |
|
123 static const nsIID kIID NS_HIDDEN; \ |
|
124 }; |
|
125 |
|
126 #define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \ |
|
127 template <class Dummy> \ |
|
128 const nsIID the_interface::COMTypeInfo<Dummy>::kIID NS_HIDDEN = the_iid; |
|
129 |
|
130 /** |
|
131 * A macro to build the static const CID accessor method |
|
132 */ |
|
133 |
|
134 #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \ |
|
135 static const nsID& GetCID() {static const nsID cid = the_cid; return cid;} |
|
136 |
|
137 #define NS_GET_IID(T) (T::COMTypeInfo<int>::kIID) |
|
138 #define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<int>::kIID) |
|
139 |
|
140 #endif |