1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/glue/nsID.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsID_h__ 1.10 +#define nsID_h__ 1.11 + 1.12 +#include <string.h> 1.13 + 1.14 +#include "nscore.h" 1.15 + 1.16 +#define NSID_LENGTH 39 1.17 + 1.18 +/** 1.19 + * A "unique identifier". This is modeled after OSF DCE UUIDs. 1.20 + */ 1.21 + 1.22 +struct nsID { 1.23 + /** 1.24 + * @name Identifier values 1.25 + */ 1.26 + 1.27 + //@{ 1.28 + uint32_t m0; 1.29 + uint16_t m1; 1.30 + uint16_t m2; 1.31 + uint8_t m3[8]; 1.32 + //@} 1.33 + 1.34 + /** 1.35 + * @name Methods 1.36 + */ 1.37 + 1.38 + //@{ 1.39 + /** 1.40 + * Equivalency method. Compares this nsID with another. 1.41 + * @return <b>true</b> if they are the same, <b>false</b> if not. 1.42 + */ 1.43 + 1.44 + inline bool Equals(const nsID& other) const { 1.45 + // Unfortunately memcmp isn't faster than this. 1.46 + return 1.47 + ((((uint32_t*) &m0)[0] == ((uint32_t*) &other.m0)[0]) && 1.48 + (((uint32_t*) &m0)[1] == ((uint32_t*) &other.m0)[1]) && 1.49 + (((uint32_t*) &m0)[2] == ((uint32_t*) &other.m0)[2]) && 1.50 + (((uint32_t*) &m0)[3] == ((uint32_t*) &other.m0)[3])); 1.51 + } 1.52 + 1.53 + /** 1.54 + * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 1.55 + * string into an nsID 1.56 + */ 1.57 + NS_COM_GLUE bool Parse(const char *aIDStr); 1.58 + 1.59 +#ifndef XPCOM_GLUE_AVOID_NSPR 1.60 + /** 1.61 + * nsID string encoder. Returns an allocated string in 1.62 + * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string. 1.63 + * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW. 1.64 + */ 1.65 + NS_COM_GLUE char* ToString() const; 1.66 + 1.67 + /** 1.68 + * nsID string encoder. Builds a string in 1.69 + * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH] 1.70 + * buffer provided by the caller (for instance, on the stack). 1.71 + */ 1.72 + NS_COM_GLUE void ToProvidedString(char (&dest)[NSID_LENGTH]) const; 1.73 + 1.74 +#endif // XPCOM_GLUE_AVOID_NSPR 1.75 + 1.76 + //@} 1.77 +}; 1.78 + 1.79 +/* 1.80 + * Class IDs 1.81 + */ 1.82 + 1.83 +typedef nsID nsCID; 1.84 + 1.85 +// Define an CID 1.86 +#define NS_DEFINE_CID(_name, _cidspec) \ 1.87 + const nsCID _name = _cidspec 1.88 + 1.89 +#define NS_DEFINE_NAMED_CID(_name) \ 1.90 + static nsCID k##_name = _name 1.91 + 1.92 +#define REFNSCID const nsCID& 1.93 + 1.94 +/** 1.95 + * An "interface id" which can be used to uniquely identify a given 1.96 + * interface. 1.97 + */ 1.98 + 1.99 +typedef nsID nsIID; 1.100 + 1.101 +/** 1.102 + * A macro shorthand for <tt>const nsIID&<tt> 1.103 + */ 1.104 + 1.105 +#define REFNSIID const nsIID& 1.106 + 1.107 +/** 1.108 + * Define an IID 1.109 + * obsolete - do not use this macro 1.110 + */ 1.111 + 1.112 +#define NS_DEFINE_IID(_name, _iidspec) \ 1.113 + const nsIID _name = _iidspec 1.114 + 1.115 +/** 1.116 + * A macro to build the static const IID accessor method. The Dummy 1.117 + * template parameter only exists so that the kIID symbol will be linked 1.118 + * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions 1.119 + * merged on windows). Dummy should always be instantiated as "int". 1.120 + */ 1.121 + 1.122 +#define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \ 1.123 + template <class Dummy> \ 1.124 + struct COMTypeInfo \ 1.125 + { \ 1.126 + static const nsIID kIID NS_HIDDEN; \ 1.127 + }; 1.128 + 1.129 +#define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \ 1.130 + template <class Dummy> \ 1.131 + const nsIID the_interface::COMTypeInfo<Dummy>::kIID NS_HIDDEN = the_iid; 1.132 + 1.133 +/** 1.134 + * A macro to build the static const CID accessor method 1.135 + */ 1.136 + 1.137 +#define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \ 1.138 + static const nsID& GetCID() {static const nsID cid = the_cid; return cid;} 1.139 + 1.140 +#define NS_GET_IID(T) (T::COMTypeInfo<int>::kIID) 1.141 +#define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<int>::kIID) 1.142 + 1.143 +#endif