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/. */
14 #define NSID_LENGTH 39
17 * A "unique identifier". This is modeled after OSF DCE UUIDs.
23 * @name Identifier values
39 * Equivalency method. Compares this nsID with another.
40 * @return <b>true</b> if they are the same, <b>false</b> if not.
43 inline bool Equals(const nsID
& aOther
) const
45 // Unfortunately memcmp isn't faster than this.
47 (((uint32_t*)&m0
)[0] == ((uint32_t*)&aOther
.m0
)[0]) &&
48 (((uint32_t*)&m0
)[1] == ((uint32_t*)&aOther
.m0
)[1]) &&
49 (((uint32_t*)&m0
)[2] == ((uint32_t*)&aOther
.m0
)[2]) &&
50 (((uint32_t*)&m0
)[3] == ((uint32_t*)&aOther
.m0
)[3]);
53 inline bool operator==(const nsID
& aOther
) const
55 return Equals(aOther
);
59 * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
62 bool Parse(const char* aIDStr
);
64 #ifndef XPCOM_GLUE_AVOID_NSPR
66 * nsID string encoder. Returns an allocated string in
67 * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
68 * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW.
70 char* ToString() const;
73 * nsID string encoder. Builds a string in
74 * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH]
75 * buffer provided by the caller (for instance, on the stack).
77 void ToProvidedString(char (&aDest
)[NSID_LENGTH
]) const;
79 #endif // XPCOM_GLUE_AVOID_NSPR
91 #define NS_DEFINE_CID(_name, _cidspec) \
92 const nsCID _name = _cidspec
94 #define NS_DEFINE_NAMED_CID(_name) \
95 static nsCID k##_name = _name
97 #define REFNSCID const nsCID&
100 * An "interface id" which can be used to uniquely identify a given
107 * A macro shorthand for <tt>const nsIID&<tt>
110 #define REFNSIID const nsIID&
114 * obsolete - do not use this macro
117 #define NS_DEFINE_IID(_name, _iidspec) \
118 const nsIID _name = _iidspec
121 * A macro to build the static const IID accessor method. The Dummy
122 * template parameter only exists so that the kIID symbol will be linked
123 * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions
124 * merged on windows). Dummy should always be instantiated as "void".
127 #define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \
128 template<typename T, typename U> \
131 #define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \
132 template<typename T> \
133 struct the_interface::COMTypeInfo<the_interface, T> { \
134 static const nsIID kIID NS_HIDDEN; \
136 template<typename T> \
137 const nsIID the_interface::COMTypeInfo<the_interface, T>::kIID NS_HIDDEN = the_iid;
140 * A macro to build the static const CID accessor method
143 #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
144 static const nsID& GetCID() {static const nsID cid = the_cid; return cid;}
146 #define NS_GET_IID(T) (T::COMTypeInfo<T, void>::kIID)
147 #define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<T, void>::kIID)