File: fo-xml-node.c

package info (click to toggle)
xmlroff 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 36,456 kB
  • ctags: 25,964
  • sloc: ansic: 178,200; xml: 109,155; sh: 8,973; makefile: 1,331; perl: 30
file content (164 lines) | stat: -rw-r--r-- 3,243 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Fo
 * fo-xml-node.c: Boxed object type for libxml2 xmlNode nodeument
 *
 * Copyright (C) 2003 Sun Microsystems
 * Copyright (C) 2007 Menteith Consulting Ltd
 *
 * See COPYING for the status of this software.
 */

#include <libxml/xmlIO.h>
#include "fo-utils.h"
#include "fo-xml-node-private.h"

extern int xmlLoadExtDtdDefaultValue;

const char *fo_xml_node_error_messages [] = {
  N_("FoXmlNode error"),
  N_("Unable to parse XML file: %s"),
  N_("Cannot open input nodeument: '%s'")
};

struct _FoXmlNode
{
  xmlNodePtr xml_node;

  guint ref_count;
};

/**
 * fo_xml_node_error_quark:
 * 
 * Get the error quark for #FoXmlNode.
 *
 * If the quark does not yet exist, create it.
 * 
 * Return value: Quark associated with #FoXmlNode errors.
 **/
GQuark
fo_xml_node_error_quark (void)
{
  static GQuark quark = 0;
  if (quark == 0)
    quark = g_quark_from_static_string ("FoXmlNode error");
  return quark;
}


/**
 * fo_xml_node_get_type:
 * 
 * Register the #FoXmlNode object type.
 * 
 * Return value: #GType value of the #FoXmlNode object type.
 **/
GType fo_xml_node_get_type (void)
{
  static GType our_type = 0;
  
  if (our_type == 0)
    our_type = g_boxed_type_register_static ("FoXmlNode",
					     (GBoxedCopyFunc) fo_xml_node_ref,
					     (GBoxedFreeFunc) fo_xml_node_unref);

  return our_type;
}

/**
 * fo_xml_node_new:
 * 
 * Creates a new #FoXmlNode.
 * 
 * Return value: the newly created #FoXmlNode. Use fo_xml_node_unref to free the
 * result.
 **/
FoXmlNode *
fo_xml_node_new (void)
{
  FoXmlNode *fo_xml_node = g_new0 (FoXmlNode, 1);

  fo_xml_node->ref_count = 1;

  return fo_xml_node;
}

/**
 * fo_xml_node_ref:
 * @fo_xml_node: a #FoXmlNode
 * 
 * Make a copy of a #FoXmlNode.
 * 
 * Return value: a newly allocated #FoXmlNode. This value
 *               must be freed using fo_xml_node_unref().
 **/
FoXmlNode *
fo_xml_node_ref  (FoXmlNode  *fo_xml_node)
{
  g_return_val_if_fail (fo_xml_node != NULL, NULL);
  g_return_val_if_fail (fo_xml_node->ref_count > 0, NULL);

  fo_xml_node->ref_count += 1;

  return fo_xml_node;
}

/**
 * fo_xml_node_unref:
 * @fo_xml_node: #FoXmlNode.
 * 
 * Unref and possibly free a #FoXmlNode.
 **/
void
fo_xml_node_unref  (FoXmlNode  *fo_xml_node)
{
  g_return_if_fail (fo_xml_node != NULL);
  g_return_if_fail (fo_xml_node->ref_count > 0);

  fo_xml_node->ref_count -= 1;

  if (fo_xml_node->ref_count == 0)
    {
      if (fo_xml_node->xml_node != NULL)
	xmlFreeNode (fo_xml_node->xml_node);

      g_free (fo_xml_node);
    }
}

/**
 * fo_xml_node_get_xml_node:
 * @fo_xml_node: #FoXmlNode
 * 
 * Get the xmlNodePtr in @fo_xml_node.
 * 
 * Return value: #xmlNodePtr.
 **/
xmlNodePtr
fo_xml_node_get_xml_node (FoXmlNode *fo_xml_node)
{
  g_return_val_if_fail (fo_xml_node != NULL, NULL);

  return fo_xml_node->xml_node;
}

/**
 * fo_xml_node_set_xml_node:
 * @fo_xml_node: #FoXmlNode.
 * @xml_node:    #xmlNodePtr.
 * 
 * Set the output #xmlNodePtr in @fo_xml_node.
 **/
void
fo_xml_node_set_xml_node (FoXmlNode    *fo_xml_node,
			  xmlNodePtr    xml_node)
{
  g_return_if_fail (fo_xml_node != NULL);

  if (fo_xml_node->xml_node != NULL)
    {
      xmlFreeNode (fo_xml_node->xml_node);
      fo_xml_node->xml_node = NULL;
    }

  fo_xml_node->xml_node = xml_node;
}