source: NonGTP/FCollada/FUtils/FUXmlWriter.h @ 964

Revision 964, 8.8 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6/**
7        @file FUXmlWriter.h
8        This file defines the FUXmlWriter namespace.
9*/
10
11#ifndef _FU_XML_WRITER_H_
12#define _FU_XML_WRITER_H_
13
14#ifdef HAS_LIBXML
15
16/**
17        Common XML writing utility functions.
18        Based on top of the LibXML2 library.
19        This whole namespace is considered external and should only be used
20        by the FCollada library.
21
22        @ingroup FUtils
23*/
24namespace FUXmlWriter
25{
26        /** Creates a dangling XML tree node.
27                @param name The name of the new XML tree node.
28                @return The new XML tree node. This pointer should never be NULL. */
29        FCOLLADA_EXPORT xmlNode* CreateNode(const char* name);
30
31        /** Appends a dangling XML tree child node to a XML tree node.
32                The child XML tree node is added at the end of the parent XML tree node children list.
33                @param parent The parent XML tree node.
34                @param child The child XML tree node. */
35        FCOLLADA_EXPORT void AddChild(xmlNode* parent, xmlNode* child);
36
37        /** Creates a child XML tree node within a XML tree node.
38                The child XML tree node is added at the end of the parent XML tree node children list.
39                @param parent The parent XML tree node.
40                @param name The name of the new child node.
41                @return The new child XML tree node. */
42        FCOLLADA_EXPORT xmlNode* AddChild(xmlNode* parent, const char* name);
43
44        /** Creates a child XML tree node within a XML tree node.
45                The child XML tree node is added at the end of the parent XML tree node children list.
46                The given content string is added to the returned child XML tree node.
47                @param parent The parent XML tree node.
48                @param name The name of the new child XML tree node.
49                @param content The content to add to the new child XML tree node.
50                @return The new child XML tree node. */
51        FCOLLADA_EXPORT xmlNode* AddChild(xmlNode* parent, const char* name, const char* content);
52#ifdef UNICODE
53        FCOLLADA_EXPORT xmlNode* AddChild(xmlNode* parent, const char* name, const fstring& content); /**< See above. */
54#endif
55        inline xmlNode* AddChild(xmlNode* parent, const char* name, const string& content) { return AddChild(parent, name, content.c_str()); } /**< See above. */
56        inline xmlNode* AddChild(xmlNode* parent, const char* name, FUSStringBuilder& content) { return AddChild(parent, name, content.ToCharPtr()); } /**< See above. */
57
58        /** Creates a child XML tree node within a XML tree node.
59                The child XML tree node is added at the end of the parent XML tree node children list.
60                The given content value is added, in string-form, to the returned child XML tree node.
61                @param parent The parent XML tree node.
62                @param name The name of the new child XML tree node.
63                @param value A primitive value. This value is stringified and added, as content, to the new child XML tree node.
64                @return The new child XML tree node. */
65        template <typename T> inline xmlNode* AddChild(xmlNode* parent, const char* name, const T& value) { globalSBuilder.set(value); return AddChild(parent, name, globalSBuilder); }
66
67        /** Appends a dangling XML tree node as a sibling of a XML tree node.
68                Two sibling XML tree nodes have the same parent XML tree node.
69                The dangling XML tree node is added at the end of the parent XML tree node children list.
70                @param sibling The sibling XML tree node. It must have a valid parent XML tree node.
71                @param dangling The dangling XML tree node. */
72        FCOLLADA_EXPORT void AddSibling(xmlNode* sibling, xmlNode* dangling);
73
74        /** Creates a XML tree node as a sibling of a XML tree node.
75                Two sibling XML tree nodes have the same parent XML tree node.
76                The new XML tree node is added at the end of the parent XML tree node children list.
77                @param sibling The sibling XML tree node. It must have a valid parent XML tree node.
78                @param name The name of the new XML tree node.
79                @return The new sibling XML tree node. */
80        FCOLLADA_EXPORT xmlNode* AddSibling(xmlNode* sibling, const char* name);
81
82        /** Returns a child XML tree node within a XML tree node.
83                If the child XML tree node with the given name does not exists, it is created and
84                the given content is added to the new XML tree node.
85                @param parent The parent XML tree node.
86                @param name The name of the child XML tree node.
87                @param content The content to add to the child XML tree node, if it must be created.
88                @return The child XML tree node. */
89        FCOLLADA_EXPORT xmlNode* AddChildOnce(xmlNode* parent, const char* name, const char* content=NULL);
90        inline xmlNode* AddChildOnce(xmlNode* parent, const char* name, const string& content) { return AddChildOnce(parent, name, content.c_str()); } /**< See above. */
91        inline xmlNode* AddChildOnce(xmlNode* parent, const char* name, FUSStringBuilder& content) { return AddChildOnce(parent, name, content.ToCharPtr()); } /**< See above. */
92
93        /** Returns a child XML tree node within a XML tree node.
94                If the child XML tree node with the given name does not exists, it is created and
95                the given content is added to the new XML tree node.
96                @param parent The parent XML tree node.
97                @param name The name of the child XML tree node.
98                @param value A primitive value. If the child XML tree node must be created: this value is stringified and added as content.
99                @return The child XML tree node. */
100        template <typename T> inline xmlNode* AddChildOnce(xmlNode* parent, const char* name, const T& value) { globalSBuilder.set(value); return AddChildOnce(parent, name, globalSBuilder); }
101
102        /** Appends a content string to a XML tree node.
103                The content string is added at the end of the XML tree node's content, with no special characters added.
104                @param node The XML tree node.
105                @param content The content to add to the XML tree node. */
106        FCOLLADA_EXPORT void AddContent(xmlNode* node, const char* content);
107#ifdef UNICODE
108        FCOLLADA_EXPORT void AddContent(xmlNode* node, const fstring& content); /**< See above. */
109#endif
110        inline void AddContent(xmlNode* node, const string& content) { AddContent(node, content.c_str()); } /**< See above. */
111        inline void AddContent(xmlNode* node, FUSStringBuilder& content) { AddContent(node, content.ToCharPtr()); } /**< See above. */
112
113        /** Appends a primitive value to a XML tree node.
114                The primitive value is added at the end of the XML tree node's content, with no special characters added.
115                @param node The XML tree node.
116                @param value A primitive value. The value is stringified and added as content to the XML tree node. */
117        template <typename T> inline void AddContent(xmlNode* node, const T& value) { globalSBuilder.set(value); return AddContent(node, globalSBuilder); }
118
119        /** Appends a XML attribute to a XML tree node.
120                A XML attribute appears in the form @<node name="value"/@>.
121                @param node The XML tree node.
122                @param attributeName The name of the XML attribute.
123                @param attributeValue The value of the XML attribute. */
124        FCOLLADA_EXPORT void AddAttribute(xmlNode* node, const char* attributeName, const char* attributeValue);
125#ifdef UNICODE
126        FCOLLADA_EXPORT void AddAttribute(xmlNode* node, const char* attributeName, const fstring& attributeValue); /**< See above. */
127#endif
128        inline void AddAttribute(xmlNode* node, const char* attributeName, FUSStringBuilder& attributeValue) { AddAttribute(node, attributeName, attributeValue.ToCharPtr()); } /**< See above. */
129        inline void AddAttribute(xmlNode* node, const char* attributeName, const string& attributeValue) { AddAttribute(node, attributeName, attributeValue.c_str()); } /**< See above. */
130
131        /** Appends a XML attribute to a XML tree node.
132                A XML attribute appears in the form @<node name="value"@/@>.
133                @param node The XML tree node.
134                @param attributeName The name of the XML attribute.
135                @param attributeValue A primitive value. The value is stringified and set as the value of the XML attribute. */
136        template <typename T> inline void AddAttribute(xmlNode* node, const char* attributeName, const T& attributeValue) { globalSBuilder.set(attributeValue); AddAttribute(node, attributeName, globalSBuilder.ToCharPtr()); }
137
138        /** Appends a dangling XML tree node to a XML tree node
139                The dangling XML tree node is inserted in lexical order,
140                after all the sibling XML tree node with the same name.
141                @param parent The XML tree node onto which the dangling XML node tree is appended.
142                @param child The dangling XML tree node. */
143        FCOLLADA_EXPORT void AddChildSorted(xmlNode* parent, xmlNode* child);
144
145        /** Creates a new child XML tree node of a XML tree node
146                The new child XML tree node is inserted in lexical order,
147                after all the sibling XML tree node with the same name.
148                @param parent The XML tree node onto which the new XML node tree is created.
149                @param name The name of the new child XML tree node.
150                @param content A content string to be added to the child XML tree node.
151                @return The new child XML tree node. */
152        FCOLLADA_EXPORT xmlNode* AddChildSorted(xmlNode* parent, const char* name, const char* content=NULL);
153};
154
155#endif // HAS_LIBXML
156
157#endif // _FU_XML_WRITER_H_
Note: See TracBrowser for help on using the repository browser.