michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsID_h__ michael@0: #define nsID_h__ michael@0: michael@0: #include michael@0: michael@0: #include "nscore.h" michael@0: michael@0: #define NSID_LENGTH 39 michael@0: michael@0: /** michael@0: * A "unique identifier". This is modeled after OSF DCE UUIDs. michael@0: */ michael@0: michael@0: struct nsID { michael@0: /** michael@0: * @name Identifier values michael@0: */ michael@0: michael@0: //@{ michael@0: uint32_t m0; michael@0: uint16_t m1; michael@0: uint16_t m2; michael@0: uint8_t m3[8]; michael@0: //@} michael@0: michael@0: /** michael@0: * @name Methods michael@0: */ michael@0: michael@0: //@{ michael@0: /** michael@0: * Equivalency method. Compares this nsID with another. michael@0: * @return true if they are the same, false if not. michael@0: */ michael@0: michael@0: inline bool Equals(const nsID& other) const { michael@0: // Unfortunately memcmp isn't faster than this. michael@0: return michael@0: ((((uint32_t*) &m0)[0] == ((uint32_t*) &other.m0)[0]) && michael@0: (((uint32_t*) &m0)[1] == ((uint32_t*) &other.m0)[1]) && michael@0: (((uint32_t*) &m0)[2] == ((uint32_t*) &other.m0)[2]) && michael@0: (((uint32_t*) &m0)[3] == ((uint32_t*) &other.m0)[3])); michael@0: } michael@0: michael@0: /** michael@0: * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} michael@0: * string into an nsID michael@0: */ michael@0: NS_COM_GLUE bool Parse(const char *aIDStr); michael@0: michael@0: #ifndef XPCOM_GLUE_AVOID_NSPR michael@0: /** michael@0: * nsID string encoder. Returns an allocated string in michael@0: * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string. michael@0: * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW. michael@0: */ michael@0: NS_COM_GLUE char* ToString() const; michael@0: michael@0: /** michael@0: * nsID string encoder. Builds a string in michael@0: * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH] michael@0: * buffer provided by the caller (for instance, on the stack). michael@0: */ michael@0: NS_COM_GLUE void ToProvidedString(char (&dest)[NSID_LENGTH]) const; michael@0: michael@0: #endif // XPCOM_GLUE_AVOID_NSPR michael@0: michael@0: //@} michael@0: }; michael@0: michael@0: /* michael@0: * Class IDs michael@0: */ michael@0: michael@0: typedef nsID nsCID; michael@0: michael@0: // Define an CID michael@0: #define NS_DEFINE_CID(_name, _cidspec) \ michael@0: const nsCID _name = _cidspec michael@0: michael@0: #define NS_DEFINE_NAMED_CID(_name) \ michael@0: static nsCID k##_name = _name michael@0: michael@0: #define REFNSCID const nsCID& michael@0: michael@0: /** michael@0: * An "interface id" which can be used to uniquely identify a given michael@0: * interface. michael@0: */ michael@0: michael@0: typedef nsID nsIID; michael@0: michael@0: /** michael@0: * A macro shorthand for const nsIID& michael@0: */ michael@0: michael@0: #define REFNSIID const nsIID& michael@0: michael@0: /** michael@0: * Define an IID michael@0: * obsolete - do not use this macro michael@0: */ michael@0: michael@0: #define NS_DEFINE_IID(_name, _iidspec) \ michael@0: const nsIID _name = _iidspec michael@0: michael@0: /** michael@0: * A macro to build the static const IID accessor method. The Dummy michael@0: * template parameter only exists so that the kIID symbol will be linked michael@0: * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions michael@0: * merged on windows). Dummy should always be instantiated as "int". michael@0: */ michael@0: michael@0: #define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \ michael@0: template \ michael@0: struct COMTypeInfo \ michael@0: { \ michael@0: static const nsIID kIID NS_HIDDEN; \ michael@0: }; michael@0: michael@0: #define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \ michael@0: template \ michael@0: const nsIID the_interface::COMTypeInfo::kIID NS_HIDDEN = the_iid; michael@0: michael@0: /** michael@0: * A macro to build the static const CID accessor method michael@0: */ michael@0: michael@0: #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \ michael@0: static const nsID& GetCID() {static const nsID cid = the_cid; return cid;} michael@0: michael@0: #define NS_GET_IID(T) (T::COMTypeInfo::kIID) michael@0: #define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo::kIID) michael@0: michael@0: #endif