Bug 387503 - Convert nsINode bits to an anonymous enum, and make a macro into an inline function for better debugging. rs=sicking
authorjwalden@mit.edu
Tue, 10 Jul 2007 15:49:42 -0700
changeset 3303 24559654b2611288e11e36990cbc1f8b85bad2ca
parent 3302 eca508ad4b16e36e968795e6df44b0556776ad0b
child 3304 4448b0fa5ff6b765a66548a6dc56593e735ea78c
push idunknown
push userunknown
push dateunknown
reviewerssicking
bugs387503
milestone1.9a7pre
Bug 387503 - Convert nsINode bits to an anonymous enum, and make a macro into an inline function for better debugging. rs=sicking
content/base/public/nsINode.h
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -55,59 +55,70 @@ class nsEventChainPostVisitor;
 class nsIEventListenerManager;
 class nsIPrincipal;
 class nsVoidArray;
 class nsIMutationObserver;
 class nsChildContentList;
 class nsNodeWeakReference;
 class nsNodeSupportsWeakRefTearoff;
 
-// This bit will be set if the node doesn't have nsSlots
-#define NODE_DOESNT_HAVE_SLOTS       0x00000001U
+enum {
+  // This bit will be set if the node doesn't have nsSlots
+  NODE_DOESNT_HAVE_SLOTS =       0x00000001U,
 
-// This bit will be set if the node has a listener manager in the listener
-// manager hash
-#define NODE_HAS_LISTENERMANAGER     0x00000002U
+  // This bit will be set if the node has a listener manager in the listener
+  // manager hash
+  NODE_HAS_LISTENERMANAGER =     0x00000002U,
 
-// Whether this node has had any properties set on it
-#define NODE_HAS_PROPERTIES          0x00000004U
+  // Whether this node has had any properties set on it
+  NODE_HAS_PROPERTIES =          0x00000004U,
 
-// Whether this node is anonymous
-// NOTE: Should only be used on nsIContent nodes
-#define NODE_IS_ANONYMOUS            0x00000008U
+  // Whether this node is anonymous
+  // NOTE: Should only be used on nsIContent nodes
+  NODE_IS_ANONYMOUS =            0x00000008U,
+
+  // Whether this node is anonymous for events
+  // NOTE: Should only be used on nsIContent nodes
+  NODE_IS_ANONYMOUS_FOR_EVENTS = 0x00000010U,
 
-// Whether this node is anonymous for events
-// NOTE: Should only be used on nsIContent nodes
-#define NODE_IS_ANONYMOUS_FOR_EVENTS 0x00000010U
+  // Whether this node may have a frame
+  // NOTE: Should only be used on nsIContent nodes
+  NODE_MAY_HAVE_FRAME =          0x00000020U,
 
-// Whether this node may have a frame
-// NOTE: Should only be used on nsIContent nodes
-#define NODE_MAY_HAVE_FRAME          0x00000020U
+  // Forces the XBL code to treat this node as if it were
+  // in the document and therefore should get bindings attached.
+  NODE_FORCE_XBL_BINDINGS =      0x00000040U,
 
-// Forces the XBL code to treat this node as if it were
-// in the document and therefore should get bindings attached.
-#define NODE_FORCE_XBL_BINDINGS      0x00000040U
+  // Whether a binding manager may have a pointer to this
+  NODE_MAY_BE_IN_BINDING_MNGR =  0x00000080U,
+
+  NODE_IS_EDITABLE =             0x00000100U,
 
-// Whether a binding manager may have a pointer to this
-#define NODE_MAY_BE_IN_BINDING_MNGR  0x00000080U
+  // Four bits for the script-type ID
+  NODE_SCRIPT_TYPE_OFFSET =                9,
 
-#define NODE_IS_EDITABLE             0x00000100U
+  NODE_SCRIPT_TYPE_SIZE =                  4,
 
-// Four bits for the script-type ID
-#define NODE_SCRIPT_TYPE_OFFSET                9
-
-// Remaining bits are node type specific.
-#define NODE_TYPE_SPECIFIC_BITS_OFFSET       0x0d
+  // Remaining bits are node type specific.
+  NODE_TYPE_SPECIFIC_BITS_OFFSET =
+    NODE_SCRIPT_TYPE_OFFSET + NODE_SCRIPT_TYPE_SIZE
+};
 
-// Useful macro for getting a node given an nsIContent and an nsIDocument
-// Returns the first argument cast to nsINode if it is non-null, otherwise
-// returns the second (which may be null)
-#define NODE_FROM(content_, document_)                  \
-  ((content_) ? static_cast<nsINode*>((content_)) :  \
-                static_cast<nsINode*>((document_)))
+// Useful inline function for getting a node given an nsIContent and an
+// nsIDocument.  Returns the first argument cast to nsINode if it is non-null,
+// otherwise returns the second (which may be null).  We use type variables
+// instead of nsIContent* and nsIDocument* because the actual types must be
+// known for the cast to work.
+template<class C, class D>
+inline nsINode* NODE_FROM(C& aContent, D& aDocument)
+{
+  if (aContent)
+    return static_cast<nsINode*>(aContent);
+  return static_cast<nsINode*>(aDocument);
+}
 
 
 // IID for the nsINode interface
 #define NS_INODE_IID \
 { 0xd3e63f80, 0x9e98, 0x47d7, \
   { 0xac, 0x8d, 0xad, 0x6f, 0x20, 0x6c, 0xe7, 0xc6 } }
 
 // hack to make egcs / gcc 2.95.2 happy