summaryrefslogtreecommitdiff
path: root/src/domcxx.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/domcxx.h')
-rw-r--r--src/domcxx.h50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/domcxx.h b/src/domcxx.h
index bd96078..9ebc023 100644
--- a/src/domcxx.h
+++ b/src/domcxx.h
@@ -93,7 +93,7 @@ namespace DOM
DOMException(int e)
{
ASSERT(e != 0);
- code = (short)e;
+ m_code = e;
}
typedef enum
@@ -110,20 +110,21 @@ namespace DOM
INUSE_ATTRIBUTE_ERR = 10
} CODES;
- int getCode()
- { return code; }
- char* getMessage()
- { /* TODO: Get from the domc library */ return NULL; }
- void getDetails(int* cde, char** message,
- char** documentUri, int* fileLine)
+ short getCode()
+ { return (short)m_code; }
+ const char* getMessage()
+ { return msgno_msg(m_code); }
+ void getDetails(short* code, const char** message,
+ const char** documentUri, int* fileLine)
{
- *cde = code;
- *message = NULL; // TODO: Get from domc library
+ *code = (short)m_code;
+ *message = msgno_msg(m_code);
*documentUri = NULL;
*fileLine = 0;
}
- short code;
+ protected:
+ int m_code;
};
class NodeList;
@@ -132,11 +133,17 @@ namespace DOM
class Document;
class DOMImplementation;
+ /* Checks whether an element is part of the tree */
+ #define LOOSE_NODE(n) \
+ ((n) && ((n)->nodeType == DOM_ATTRIBUTE_NODE ? \
+ (n)->u.Attr.ownerElement == NULL : \
+ (n)->parentNode == NULL)) \
+
/* We only perform ref counting on nodes outside the tree */
#define INC_NODE_REF(n) \
- if((n).m_node != NULL && ((n).m_node)->parentNode == NULL) incref((n).m_node)
+ if(LOOSE_NODE(n)) incref(n)
#define DEC_NODE_REF(n) \
- if((n).m_node != NULL && ((n).m_node)->parentNode == NULL) decref((n).m_node)
+ if(LOOSE_NODE(n)) decref(n)
/**
* Thin wrapper class for a DOM Node
@@ -165,14 +172,14 @@ namespace DOM
Node(const Node& node)
{
- INC_NODE_REF(node);
+ INC_NODE_REF(node.m_node);
m_node = node.m_node;
}
Node& operator=(const Node& other)
{
- INC_NODE_REF(other);
- DEC_NODE_REF(*this);
+ INC_NODE_REF(other.m_node);
+ DEC_NODE_REF(m_node);
m_node = other.m_node;
return *this;
}
@@ -180,13 +187,13 @@ namespace DOM
Node& operator=(const void* null)
{
ASSERT(null == NULL);
- DEC_NODE_REF(*this);
+ DEC_NODE_REF(m_node);
m_node = NULL;
return *this;
}
~Node()
- { DEC_NODE_REF(*this); }
+ { DEC_NODE_REF(m_node); }
bool operator==(const Node& other) const
{ return m_node == other.m_node; }
@@ -395,7 +402,7 @@ namespace DOM
m_node->attributes->length > 0;
}
- void* setUserData(void* data)
+ void setUserData(void* data)
throw(DOMException)
{
ASSERT_VALID();
@@ -416,7 +423,7 @@ namespace DOM
Node(DOM_Node* node)
{
m_node = node;
- INC_NODE_REF(*this);
+ INC_NODE_REF(m_node);
}
protected:
@@ -437,8 +444,9 @@ namespace DOM
--(node->rtfxRefCount);
if(node->rtfxRefCount <= 0)
{
- ASSERT(node->ownerDocument);
- DOM_Document_destroyNode(node->ownerDocument, node);
+ ASSERT(node->nodeType == DOM_DOCUMENT_NODE || node->ownerDocument);
+ DOM_Document_destroyNode(node->nodeType == DOM_DOCUMENT_NODE ?
+ node : node->ownerDocument, node);
}
}
};