Bug 1242963 - nsID stringification helper for logging; r=froydnj
authorVladimir Vukicevic <vladimir@pobox.com>
Thu, 08 Oct 2015 13:11:04 -0400
changeset 290755 9a135bc3752971f8a76c1cb6fa4ffefbb613d93c
parent 290754 110003172c5b120c6d6a0aacb63c96661666efa5
child 290756 32d19555348e3d8da52cc5b73a9232ea1de37769
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1242963
milestone48.0a1
Bug 1242963 - nsID stringification helper for logging; r=froydnj From 6321c215bed173f89127558b2eec3cc1b475cf84 Mon Sep 17 00:00:00 2001 MozReview-Commit-ID: IPhQhW8v4iH
xpcom/glue/nsID.h
--- a/xpcom/glue/nsID.h
+++ b/xpcom/glue/nsID.h
@@ -81,16 +81,41 @@ struct nsID
    */
   void ToProvidedString(char (&aDest)[NSID_LENGTH]) const;
 
 #endif // XPCOM_GLUE_AVOID_NSPR
 
   //@}
 };
 
+#ifndef XPCOM_GLUE_AVOID_NSPR
+/**
+ * A stack helper class to convert a nsID to a string.  Useful
+ * for printing nsIDs.  For example:
+ *   nsID aID = ...;
+ *   printf("%s", nsIDToCString(aID).get());
+ */
+class nsIDToCString
+{
+public:
+  explicit nsIDToCString(const nsID& aID)
+  {
+    aID.ToProvidedString(mStringBytes);
+  }
+
+  const char *get() const
+  {
+    return mStringBytes;
+  }
+
+protected:
+  char mStringBytes[NSID_LENGTH];
+};
+#endif
+
 /*
  * Class IDs
  */
 
 typedef nsID nsCID;
 
 // Define an CID
 #define NS_DEFINE_CID(_name, _cidspec) \