summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorBo Yang <struggleyb.nku@gmail.com>2009-03-15 13:38:51 +0000
committerBo Yang <struggleyb.nku@gmail.com>2009-03-15 13:38:51 +0000
commit800687f1cd21b88bef97ece26db32f17eb59c722 (patch)
tree81bb7e1db7ea7c5203d8e32a0799fc9df6de6432 /src/core
parent2d5b33c9d7a8b3b5f7cc1a952e0a4c21a222ab7f (diff)
downloadlibdom-800687f1cd21b88bef97ece26db32f17eb59c722.tar.gz
libdom-800687f1cd21b88bef97ece26db32f17eb59c722.tar.bz2
Convert the dom_characterdata to use vtable.
svn path=/trunk/dom/; revision=6787
Diffstat (limited to 'src/core')
-rw-r--r--src/core/attr.h2
-rw-r--r--src/core/characterdata.c58
-rw-r--r--src/core/characterdata.h37
-rw-r--r--src/core/node.c2
-rw-r--r--src/core/node.h2
5 files changed, 79 insertions, 22 deletions
diff --git a/src/core/attr.h b/src/core/attr.h
index 4106dbe..11b2528 100644
--- a/src/core/attr.h
+++ b/src/core/attr.h
@@ -11,8 +11,8 @@
#include <dom/core/exceptions.h>
struct dom_document;
-struct dom_attr;
struct dom_string;
+typedef struct dom_attr dom_attr;
dom_exception dom_attr_create(struct dom_document *doc,
struct dom_string *name, struct dom_string *namespace,
diff --git a/src/core/characterdata.c b/src/core/characterdata.c
index 317dfd2..558eb45 100644
--- a/src/core/characterdata.c
+++ b/src/core/characterdata.c
@@ -13,6 +13,32 @@
#include "core/node.h"
#include "utils/utils.h"
+/* The virtual functions for dom_characterdata */
+static struct dom_characterdata_vtable characterdata_vtable = {
+ {
+ DOM_NODE_VTABLE
+ },
+ DOM_CHARACTERDATA_VTABLE
+};
+
+/**
+ * Create a DOM characterdata node and compose the vtable
+ *
+ * Return The new constructed DOM characterdata node of NULL if fail
+ */
+dom_characterdata *dom_characterdata_create(struct dom_document *doc)
+{
+ dom_characterdata *cdata = dom_document_alloc(doc, NULL,
+ sizeof(struct dom_characterdata));
+
+ if (cdata == NULL)
+ return NULL;
+
+ /* Some unused variable will cause a failed compile */
+ UNUSED(characterdata_vtable);
+ return cdata;
+}
+
/**
* Initialise a character data node
*
@@ -61,10 +87,10 @@ void dom_characterdata_finalise(struct dom_document *doc,
* DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in
* this implementation; dom_strings are unbounded.
*/
-dom_exception dom_characterdata_get_data(struct dom_characterdata *cdata,
+dom_exception _dom_characterdata_get_data(struct dom_characterdata *cdata,
struct dom_string **data)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
if (c->value != NULL) {
dom_string_ref(c->value);
@@ -86,10 +112,10 @@ dom_exception dom_characterdata_get_data(struct dom_characterdata *cdata,
* should unref it after the call (as the caller should have already claimed
* a reference on the string). The node's existing content will be unrefed.
*/
-dom_exception dom_characterdata_set_data(struct dom_characterdata *cdata,
+dom_exception _dom_characterdata_set_data(struct dom_characterdata *cdata,
struct dom_string *data)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
if (_dom_node_readonly(c)) {
return DOM_NO_MODIFICATION_ALLOWED_ERR;
@@ -112,10 +138,10 @@ dom_exception dom_characterdata_set_data(struct dom_characterdata *cdata,
* \param length Pointer to location to receive character length of content
* \return DOM_NO_ERR.
*/
-dom_exception dom_characterdata_get_length(struct dom_characterdata *cdata,
+dom_exception _dom_characterdata_get_length(struct dom_characterdata *cdata,
unsigned long *length)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
if (c->value != NULL) {
*length = dom_string_length(c->value);
@@ -144,11 +170,11 @@ dom_exception dom_characterdata_get_length(struct dom_characterdata *cdata,
* DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in
* this implementation; dom_strings are unbounded.
*/
-dom_exception dom_characterdata_substring_data(
+dom_exception _dom_characterdata_substring_data(
struct dom_characterdata *cdata, unsigned long offset,
unsigned long count, struct dom_string **data)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
uint32_t len, end;
if (c->value != NULL) {
@@ -174,10 +200,10 @@ dom_exception dom_characterdata_substring_data(
* \return DOM_NO_ERR on success,
* DOM_NO_MODIFICATION_ALLOWED_ERR if ::cdata is readonly.
*/
-dom_exception dom_characterdata_append_data(struct dom_characterdata *cdata,
+dom_exception _dom_characterdata_append_data(struct dom_characterdata *cdata,
struct dom_string *data)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
struct dom_string *temp;
dom_exception err;
@@ -212,10 +238,10 @@ dom_exception dom_characterdata_append_data(struct dom_characterdata *cdata,
* number of characters in ::cdata,
* DOM_NO_MODIFICATION_ALLOWED_ERR if ::cdata is readonly.
*/
-dom_exception dom_characterdata_insert_data(struct dom_characterdata *cdata,
+dom_exception _dom_characterdata_insert_data(struct dom_characterdata *cdata,
unsigned long offset, struct dom_string *data)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
struct dom_string *temp;
uint32_t len;
dom_exception err;
@@ -259,10 +285,10 @@ dom_exception dom_characterdata_insert_data(struct dom_characterdata *cdata,
* number of characters in ::cdata,
* DOM_NO_MODIFICATION_ALLOWED_ERR if ::cdata is readonly.
*/
-dom_exception dom_characterdata_delete_data(struct dom_characterdata *cdata,
+dom_exception _dom_characterdata_delete_data(struct dom_characterdata *cdata,
unsigned long offset, unsigned long count)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
struct dom_string *temp;
uint32_t len, end;
dom_exception err;
@@ -309,11 +335,11 @@ dom_exception dom_characterdata_delete_data(struct dom_characterdata *cdata,
* number of characters in ::cdata,
* DOM_NO_MODIFICATION_ALLOWED_ERR if ::cdata is readonly.
*/
-dom_exception dom_characterdata_replace_data(struct dom_characterdata *cdata,
+dom_exception _dom_characterdata_replace_data(struct dom_characterdata *cdata,
unsigned long offset, unsigned long count,
struct dom_string *data)
{
- struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_node_internal *c = (struct dom_node_internal *) cdata;
struct dom_string *temp;
uint32_t len, end;
dom_exception err;
diff --git a/src/core/characterdata.h b/src/core/characterdata.h
index e8b45fd..901b110 100644
--- a/src/core/characterdata.h
+++ b/src/core/characterdata.h
@@ -15,10 +15,11 @@
/**
* DOM character data node
*/
-struct dom_characterdata {
- struct dom_node base; /**< Base node */
-};
+typedef struct dom_characterdata {
+ struct dom_node_internal base; /**< Base node */
+} dom_characterdata;
+dom_characterdata *dom_characterdata_create(struct dom_document *doc);
dom_exception dom_characterdata_initialise(struct dom_characterdata *cdata,
struct dom_document *doc, dom_node_type type,
struct dom_string *name, struct dom_string *value);
@@ -26,4 +27,34 @@ dom_exception dom_characterdata_initialise(struct dom_characterdata *cdata,
void dom_characterdata_finalise(struct dom_document *doc,
struct dom_characterdata *cdata);
+/* The virtual functions for characterdata */
+dom_exception _dom_characterdata_get_data(struct dom_characterdata *cdata,
+ struct dom_string **data);
+dom_exception _dom_characterdata_set_data(struct dom_characterdata *cdata,
+ struct dom_string *data);
+dom_exception _dom_characterdata_get_length(struct dom_characterdata *cdata,
+ unsigned long *length);
+dom_exception _dom_characterdata_substring_data(
+ struct dom_characterdata *cdata, unsigned long offset,
+ unsigned long count, struct dom_string **data);
+dom_exception _dom_characterdata_append_data(struct dom_characterdata *cdata,
+ struct dom_string *data);
+dom_exception _dom_characterdata_insert_data(struct dom_characterdata *cdata,
+ unsigned long offset, struct dom_string *data);
+dom_exception _dom_characterdata_delete_data(struct dom_characterdata *cdata,
+ unsigned long offset, unsigned long count);
+dom_exception _dom_characterdata_replace_data(struct dom_characterdata *cdata,
+ unsigned long offset, unsigned long count,
+ struct dom_string *data);
+
+#define DOM_CHARACTERDATA_VTABLE \
+ _dom_characterdata_get_data, \
+ _dom_characterdata_set_data, \
+ _dom_characterdata_get_length, \
+ _dom_characterdata_substring_data, \
+ _dom_characterdata_append_data, \
+ _dom_characterdata_insert_data, \
+ _dom_characterdata_delete_data, \
+ _dom_characterdata_replace_data
+
#endif
diff --git a/src/core/node.c b/src/core/node.c
index 0b0c4a6..f40431e 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -53,7 +53,7 @@ static struct dom_node_vtable node_vtable = {
*
* Return The new constructed DOM node or NULL if fail.
*/
-dom_node_internal * dom_node_create()
+dom_node_internal * dom_node_create(struct dom_document *doc)
{
dom_node_internal *node = dom_document_alloc(doc, NULL,
sizeof(struct dom_node_internal));
diff --git a/src/core/node.h b/src/core/node.h
index e37a012..27c9f35 100644
--- a/src/core/node.h
+++ b/src/core/node.h
@@ -56,7 +56,7 @@ struct dom_node_internal {
uint32_t refcnt; /**< Reference count */
};
-dom_node_internal * dom_node_create(dom_alloc alloc, void *pw);
+dom_node_internal * dom_node_create(struct dom_document *doc);
dom_exception dom_node_initialise(struct dom_node_internal *node,
struct dom_document *doc, dom_node_type type,