/work/obj-fuzz/dist/include/nsID.h
Line | Count | Source (jump to first uncovered line) |
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 nsID_h__ |
8 | | #define nsID_h__ |
9 | | |
10 | | #include <string.h> |
11 | | |
12 | | #include "nscore.h" |
13 | | |
14 | 12 | #define NSID_LENGTH 39 |
15 | | |
16 | | /** |
17 | | * A "unique identifier". This is modeled after OSF DCE UUIDs. |
18 | | */ |
19 | | |
20 | | struct nsID |
21 | | { |
22 | | /** |
23 | | * @name Identifier values |
24 | | */ |
25 | | |
26 | | //@{ |
27 | | uint32_t m0; |
28 | | uint16_t m1; |
29 | | uint16_t m2; |
30 | | uint8_t m3[8]; |
31 | | //@} |
32 | | |
33 | | /** |
34 | | * @name Methods |
35 | | */ |
36 | | |
37 | | //@{ |
38 | | /** |
39 | | * Ensures everything is zeroed out. |
40 | | */ |
41 | | void Clear(); |
42 | | |
43 | | /** |
44 | | * Equivalency method. Compares this nsID with another. |
45 | | * @return <b>true</b> if they are the same, <b>false</b> if not. |
46 | | */ |
47 | | |
48 | | inline bool Equals(const nsID& aOther) const |
49 | | { |
50 | | // Unfortunately memcmp isn't faster than this. |
51 | | return |
52 | | (((uint32_t*)&m0)[0] == ((uint32_t*)&aOther.m0)[0]) && |
53 | | (((uint32_t*)&m0)[1] == ((uint32_t*)&aOther.m0)[1]) && |
54 | | (((uint32_t*)&m0)[2] == ((uint32_t*)&aOther.m0)[2]) && |
55 | | (((uint32_t*)&m0)[3] == ((uint32_t*)&aOther.m0)[3]); |
56 | | } |
57 | | |
58 | | inline bool operator==(const nsID& aOther) const |
59 | | { |
60 | | return Equals(aOther); |
61 | | } |
62 | | |
63 | | /** |
64 | | * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} |
65 | | * string into an nsID |
66 | | */ |
67 | | bool Parse(const char* aIDStr); |
68 | | |
69 | | #ifndef XPCOM_GLUE_AVOID_NSPR |
70 | | /** |
71 | | * nsID string encoder. Returns an allocated string in |
72 | | * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string. |
73 | | * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW. |
74 | | */ |
75 | | char* ToString() const; |
76 | | |
77 | | /** |
78 | | * nsID string encoder. Builds a string in |
79 | | * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH] |
80 | | * buffer provided by the caller (for instance, on the stack). |
81 | | */ |
82 | | void ToProvidedString(char (&aDest)[NSID_LENGTH]) const; |
83 | | |
84 | | #endif // XPCOM_GLUE_AVOID_NSPR |
85 | | |
86 | | // Infallibly duplicate an nsID. Must be freed with free(). |
87 | | nsID* Clone() const; |
88 | | |
89 | | //@} |
90 | | }; |
91 | | |
92 | | #ifndef XPCOM_GLUE_AVOID_NSPR |
93 | | /** |
94 | | * A stack helper class to convert a nsID to a string. Useful |
95 | | * for printing nsIDs. For example: |
96 | | * nsID aID = ...; |
97 | | * printf("%s", nsIDToCString(aID).get()); |
98 | | */ |
99 | | class nsIDToCString |
100 | | { |
101 | | public: |
102 | | explicit nsIDToCString(const nsID& aID) |
103 | 0 | { |
104 | 0 | aID.ToProvidedString(mStringBytes); |
105 | 0 | } |
106 | | |
107 | | const char *get() const |
108 | 0 | { |
109 | 0 | return mStringBytes; |
110 | 0 | } |
111 | | |
112 | | protected: |
113 | | char mStringBytes[NSID_LENGTH]; |
114 | | }; |
115 | | #endif |
116 | | |
117 | | /* |
118 | | * Class IDs |
119 | | */ |
120 | | |
121 | | typedef nsID nsCID; |
122 | | |
123 | | // Define an CID |
124 | | #define NS_DEFINE_CID(_name, _cidspec) \ |
125 | 0 | const nsCID _name = _cidspec |
126 | | |
127 | | #define NS_DEFINE_NAMED_CID(_name) \ |
128 | | static const nsCID k##_name = _name |
129 | | |
130 | | #define REFNSCID const nsCID& |
131 | | |
132 | | /** |
133 | | * An "interface id" which can be used to uniquely identify a given |
134 | | * interface. |
135 | | */ |
136 | | |
137 | | typedef nsID nsIID; |
138 | | |
139 | | /** |
140 | | * A macro shorthand for <tt>const nsIID&<tt> |
141 | | */ |
142 | | |
143 | | #define REFNSIID const nsIID& |
144 | | |
145 | | /** |
146 | | * Define an IID |
147 | | * obsolete - do not use this macro |
148 | | */ |
149 | | |
150 | | #define NS_DEFINE_IID(_name, _iidspec) \ |
151 | 0 | const nsIID _name = _iidspec |
152 | | |
153 | | /** |
154 | | * A macro to build the static const IID accessor method. The Dummy |
155 | | * template parameter only exists so that the kIID symbol will be linked |
156 | | * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions |
157 | | * merged on windows). Dummy should always be instantiated as "void". |
158 | | */ |
159 | | |
160 | | #define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \ |
161 | | template<typename T, typename U> \ |
162 | | struct COMTypeInfo; |
163 | | |
164 | | #define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \ |
165 | | template<typename T> \ |
166 | | struct the_interface::COMTypeInfo<the_interface, T> { \ |
167 | | static const nsIID kIID NS_HIDDEN; \ |
168 | | }; \ |
169 | | template<typename T> \ |
170 | | const nsIID the_interface::COMTypeInfo<the_interface, T>::kIID NS_HIDDEN = the_iid; |
171 | | |
172 | | /** |
173 | | * A macro to build the static const CID accessor method |
174 | | */ |
175 | | |
176 | | #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \ |
177 | 2 | static const nsID& GetCID() {static const nsID cid = the_cid; return cid;} Unexecuted instantiation: nsLocalFile::GetCID() Unexecuted instantiation: nsScriptSecurityManager::GetCID() Line | Count | Source | 177 | 1 | static const nsID& GetCID() {static const nsID cid = the_cid; return cid;} |
nsXPCConstructor::GetCID() Line | Count | Source | 177 | 1 | static const nsID& GetCID() {static const nsID cid = the_cid; return cid;} |
Unexecuted instantiation: nsJAR::GetCID() |
178 | | |
179 | 269M | #define NS_GET_IID(T) (T::COMTypeInfo<T, void>::kIID) |
180 | 24.4M | #define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<T, void>::kIID) |
181 | | |
182 | | #endif |