xpcom/glue/nsID.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsID_h__
     7 #define nsID_h__
     9 #include <string.h>
    11 #include "nscore.h"
    13 #define NSID_LENGTH 39
    15 /**
    16  * A "unique identifier". This is modeled after OSF DCE UUIDs.
    17  */
    19 struct nsID {
    20   /**
    21    * @name Identifier values
    22    */
    24   //@{
    25   uint32_t m0;
    26   uint16_t m1;
    27   uint16_t m2;
    28   uint8_t m3[8];
    29   //@}
    31   /**
    32    * @name Methods
    33    */
    35   //@{
    36   /**
    37    * Equivalency method. Compares this nsID with another.
    38    * @return <b>true</b> if they are the same, <b>false</b> if not.
    39    */
    41   inline bool Equals(const nsID& other) const {
    42     // Unfortunately memcmp isn't faster than this.
    43     return
    44       ((((uint32_t*) &m0)[0] == ((uint32_t*) &other.m0)[0]) &&
    45        (((uint32_t*) &m0)[1] == ((uint32_t*) &other.m0)[1]) &&
    46        (((uint32_t*) &m0)[2] == ((uint32_t*) &other.m0)[2]) &&
    47        (((uint32_t*) &m0)[3] == ((uint32_t*) &other.m0)[3]));
    48   }
    50   /**
    51    * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
    52    * string into an nsID
    53    */
    54   NS_COM_GLUE bool Parse(const char *aIDStr);
    56 #ifndef XPCOM_GLUE_AVOID_NSPR
    57   /**
    58    * nsID string encoder. Returns an allocated string in 
    59    * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
    60    * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW.
    61    */
    62   NS_COM_GLUE char* ToString() const;
    64   /**
    65    * nsID string encoder. Builds a string in 
    66    * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH]
    67    * buffer provided by the caller (for instance, on the stack).
    68    */
    69   NS_COM_GLUE void ToProvidedString(char (&dest)[NSID_LENGTH]) const;
    71 #endif // XPCOM_GLUE_AVOID_NSPR
    73   //@}
    74 };
    76 /*
    77  * Class IDs
    78  */
    80 typedef nsID nsCID;
    82 // Define an CID
    83 #define NS_DEFINE_CID(_name, _cidspec) \
    84   const nsCID _name = _cidspec
    86 #define NS_DEFINE_NAMED_CID(_name) \
    87   static nsCID k##_name = _name
    89 #define REFNSCID const nsCID&
    91 /**
    92  * An "interface id" which can be used to uniquely identify a given
    93  * interface.
    94  */
    96 typedef nsID nsIID;
    98 /**
    99  * A macro shorthand for <tt>const nsIID&<tt>
   100  */
   102 #define REFNSIID const nsIID&
   104 /**
   105  * Define an IID
   106  * obsolete - do not use this macro
   107  */
   109 #define NS_DEFINE_IID(_name, _iidspec) \
   110   const nsIID _name = _iidspec
   112 /**
   113  * A macro to build the static const IID accessor method. The Dummy
   114  * template parameter only exists so that the kIID symbol will be linked
   115  * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions
   116  * merged on windows). Dummy should always be instantiated as "int".
   117  */
   119 #define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid)                         \
   120   template <class Dummy>                                                \
   121   struct COMTypeInfo                                                    \
   122   {                                                                     \
   123     static const nsIID kIID NS_HIDDEN;                                  \
   124   };
   126 #define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid)           \
   127   template <class Dummy>                                                \
   128   const nsIID the_interface::COMTypeInfo<Dummy>::kIID NS_HIDDEN = the_iid;
   130 /**
   131  * A macro to build the static const CID accessor method
   132  */
   134 #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
   135   static const nsID& GetCID() {static const nsID cid = the_cid; return cid;}
   137 #define NS_GET_IID(T) (T::COMTypeInfo<int>::kIID)
   138 #define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<int>::kIID)
   140 #endif

mercurial