1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsID_h__
39 : #define nsID_h__
40 :
41 : #include <string.h>
42 :
43 : #ifndef nscore_h___
44 : #include "nscore.h"
45 : #endif
46 :
47 : #define NSID_LENGTH 39
48 :
49 : /**
50 : * A "unique identifier". This is modeled after OSF DCE UUIDs.
51 : */
52 :
53 : struct nsID {
54 : /**
55 : * @name Identifier values
56 : */
57 :
58 : //@{
59 : PRUint32 m0;
60 : PRUint16 m1;
61 : PRUint16 m2;
62 : PRUint8 m3[8];
63 : //@}
64 :
65 : /**
66 : * @name Methods
67 : */
68 :
69 : //@{
70 : /**
71 : * Equivalency method. Compares this nsID with another.
72 : * @return <b>true</b> if they are the same, <b>false</b> if not.
73 : */
74 :
75 156182790 : inline bool Equals(const nsID& other) const {
76 : // Unfortunately memcmp isn't faster than this.
77 : return
78 156182790 : ((((PRUint32*) &m0)[0] == ((PRUint32*) &other.m0)[0]) &&
79 45126397 : (((PRUint32*) &m0)[1] == ((PRUint32*) &other.m0)[1]) &&
80 45126398 : (((PRUint32*) &m0)[2] == ((PRUint32*) &other.m0)[2]) &&
81 246435585 : (((PRUint32*) &m0)[3] == ((PRUint32*) &other.m0)[3]));
82 : }
83 :
84 : /**
85 : * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
86 : * string into an nsID
87 : */
88 : NS_COM_GLUE bool Parse(const char *aIDStr);
89 :
90 : #ifndef XPCOM_GLUE_AVOID_NSPR
91 : /**
92 : * nsID string encoder. Returns an allocated string in
93 : * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
94 : * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW.
95 : */
96 : NS_COM_GLUE char* ToString() const;
97 :
98 : /**
99 : * nsID string encoder. Builds a string in
100 : * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH]
101 : * buffer provided by the caller (for instance, on the stack).
102 : */
103 : NS_COM_GLUE void ToProvidedString(char (&dest)[NSID_LENGTH]) const;
104 :
105 : #endif // XPCOM_GLUE_AVOID_NSPR
106 :
107 : //@}
108 : };
109 :
110 : /*
111 : * Class IDs
112 : */
113 :
114 : typedef nsID nsCID;
115 :
116 : // Define an CID
117 : #define NS_DEFINE_CID(_name, _cidspec) \
118 : const nsCID _name = _cidspec
119 :
120 : #define NS_DEFINE_NAMED_CID(_name) \
121 : static nsCID k##_name = _name
122 :
123 : #define REFNSCID const nsCID&
124 :
125 : /**
126 : * An "interface id" which can be used to uniquely identify a given
127 : * interface.
128 : */
129 :
130 : typedef nsID nsIID;
131 :
132 : /**
133 : * A macro shorthand for <tt>const nsIID&<tt>
134 : */
135 :
136 : #define REFNSIID const nsIID&
137 :
138 : /**
139 : * Define an IID
140 : * obsolete - do not use this macro
141 : */
142 :
143 : #define NS_DEFINE_IID(_name, _iidspec) \
144 : const nsIID _name = _iidspec
145 :
146 : /**
147 : * A macro to build the static const IID accessor method. The Dummy
148 : * template parameter only exists so that the kIID symbol will be linked
149 : * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions
150 : * merged on windows). Dummy should always be instantiated as "int".
151 : */
152 :
153 : #define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \
154 : template <class Dummy> \
155 : struct COMTypeInfo \
156 : { \
157 : static const nsIID kIID NS_HIDDEN; \
158 : }; \
159 : static const nsIID& GetIID() {return COMTypeInfo<int>::kIID;}
160 :
161 : #define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \
162 : template <class Dummy> \
163 : const nsIID the_interface::COMTypeInfo<Dummy>::kIID NS_HIDDEN = the_iid;
164 :
165 : /**
166 : * A macro to build the static const CID accessor method
167 : */
168 :
169 : #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
170 : static const nsID& GetCID() {static const nsID cid = the_cid; return cid;}
171 :
172 : #define NS_GET_IID(T) (::T::COMTypeInfo<int>::kIID)
173 : #define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<int>::kIID)
174 :
175 : #endif
|