Bumping manifests a=b2g-bump
[gecko.git] / xpcom / glue / nsID.h
blob3d5b512d9be6e9877e43b26bb68e9a6f50a1864e
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/. */
7 #ifndef nsID_h__
8 #define nsID_h__
10 #include <string.h>
12 #include "nscore.h"
14 #define NSID_LENGTH 39
16 /**
17 * A "unique identifier". This is modeled after OSF DCE UUIDs.
20 struct nsID
22 /**
23 * @name Identifier values
26 //@{
27 uint32_t m0;
28 uint16_t m1;
29 uint16_t m2;
30 uint8_t m3[8];
31 //@}
33 /**
34 * @name Methods
37 //@{
38 /**
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.
46 return
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);
58 /**
59 * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
60 * string into an nsID
62 bool Parse(const char* aIDStr);
64 #ifndef XPCOM_GLUE_AVOID_NSPR
65 /**
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;
72 /**
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
81 //@}
85 * Class IDs
88 typedef nsID nsCID;
90 // Define an CID
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&
99 /**
100 * An "interface id" which can be used to uniquely identify a given
101 * interface.
104 typedef nsID nsIID;
107 * A macro shorthand for <tt>const nsIID&<tt>
110 #define REFNSIID const nsIID&
113 * Define an IID
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> \
129 struct COMTypeInfo;
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; \
135 }; \
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)
149 #endif