nsID.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #ifndef nsID_h__
  38. #define nsID_h__
  39. #include <string.h>
  40. #ifndef nscore_h___
  41. #include "nscore.h"
  42. #endif
  43. /**
  44. * A "unique identifier". This is modeled after OSF DCE UUIDs.
  45. * @status FROZEN
  46. */
  47. struct nsID {
  48. /**
  49. * @name Indentifier values
  50. */
  51. //@{
  52. PRUint32 m0;
  53. PRUint16 m1;
  54. PRUint16 m2;
  55. PRUint8 m3[8];
  56. //@}
  57. /**
  58. * @name Methods
  59. */
  60. //@{
  61. /**
  62. * Equivalency method. Compares this nsID with another.
  63. * @return <b>PR_TRUE</b> if they are the same, <b>PR_FALSE</b> if not.
  64. */
  65. inline PRBool Equals(const nsID& other) const {
  66. // One would think that this could be done faster with a really
  67. // efficient implementation of memcmp(), but evidently no
  68. // memcmp()'s out there are better than this code.
  69. //
  70. // See bug http://bugzilla.mozilla.org/show_bug.cgi?id=164580 for
  71. // details.
  72. return (PRBool)
  73. ((((PRUint32*) &m0)[0] == ((PRUint32*) &other.m0)[0]) &&
  74. (((PRUint32*) &m0)[1] == ((PRUint32*) &other.m0)[1]) &&
  75. (((PRUint32*) &m0)[2] == ((PRUint32*) &other.m0)[2]) &&
  76. (((PRUint32*) &m0)[3] == ((PRUint32*) &other.m0)[3]));
  77. }
  78. /**
  79. * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
  80. * string into an nsID
  81. */
  82. NS_COM_GLUE PRBool Parse(const char *aIDStr);
  83. /**
  84. * nsID string encoder. Returns an allocated string in
  85. * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
  86. */
  87. NS_COM_GLUE char* ToString() const;
  88. //@}
  89. };
  90. /*
  91. * Class IDs
  92. */
  93. typedef nsID nsCID;
  94. // Define an CID
  95. #define NS_DEFINE_CID(_name, _cidspec) \
  96. const nsCID _name = _cidspec
  97. #define REFNSCID const nsCID&
  98. /**
  99. * An "interface id" which can be used to uniquely identify a given
  100. * interface.
  101. */
  102. typedef nsID nsIID;
  103. /**
  104. * A macro shorthand for <tt>const nsIID&<tt>
  105. */
  106. #define REFNSIID const nsIID&
  107. /**
  108. * Define an IID
  109. * obsolete - do not use this macro
  110. */
  111. #define NS_DEFINE_IID(_name, _iidspec) \
  112. const nsIID _name = _iidspec
  113. /**
  114. * A macro to build the static const IID accessor method
  115. */
  116. #define NS_DEFINE_STATIC_IID_ACCESSOR(the_iid) \
  117. static const nsIID& GetIID() {static const nsIID iid = the_iid; return iid;}
  118. /**
  119. * A macro to build the static const CID accessor method
  120. */
  121. #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
  122. static const nsID& GetCID() {static const nsID cid = the_cid; return cid;}
  123. #endif