• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _QPXMLWRITER_H
2 #define _QPXMLWRITER_H
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Helper Library
5  * -------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Test log library
24  *//*--------------------------------------------------------------------*/
25 
26 #include "deDefs.h"
27 
28 #include <stdio.h>
29 
30 DE_BEGIN_EXTERN_C
31 
32 typedef struct qpXmlWriter_s	qpXmlWriter;
33 
34 typedef enum qpXmlAttributeType_e
35 {
36 	QP_XML_ATTRIBUTE_STRING = 0,
37 	QP_XML_ATTRIBUTE_INT,
38 	QP_XML_ATTRIBUTE_BOOL,
39 
40 	QP_XML_ATTRIBUTE_LAST
41 } qpXmlAttributeType;
42 
43 typedef struct qpXmlAttribute_s
44 {
45 	const char*			name;
46 	qpXmlAttributeType	type;
47 	const char*			stringValue;
48 	int					intValue;
49 	deBool				boolValue;
50 } qpXmlAttribute;
51 
qpSetStringAttrib(const char * name,const char * value)52 DE_INLINE qpXmlAttribute qpSetStringAttrib (const char* name, const char* value)
53 {
54 	qpXmlAttribute attrib;
55 	attrib.name			= name;
56 	attrib.type			= QP_XML_ATTRIBUTE_STRING;
57 	attrib.stringValue	= value;
58 	attrib.intValue		= -678;
59 	attrib.boolValue	= (deBool)0xFFFFFFFFu;
60 	return attrib;
61 }
62 
qpSetIntAttrib(const char * name,int value)63 DE_INLINE qpXmlAttribute qpSetIntAttrib (const char* name, int value)
64 {
65 	qpXmlAttribute attrib;
66 	attrib.name			= name;
67 	attrib.type			= QP_XML_ATTRIBUTE_INT;
68 	attrib.stringValue	= "<intAttrib>";
69 	attrib.intValue		= value;
70 	attrib.boolValue	= (deBool)0xFFFFFFFFu;
71 	return attrib;
72 }
73 
qpSetBoolAttrib(const char * name,deBool value)74 DE_INLINE qpXmlAttribute qpSetBoolAttrib (const char* name, deBool value)
75 {
76 	qpXmlAttribute attrib;
77 	attrib.name			= name;
78 	attrib.type			= QP_XML_ATTRIBUTE_BOOL;
79 	attrib.stringValue	= "<boolAttrib>";
80 	attrib.intValue		= -679;
81 	attrib.boolValue	= value;
82 	return attrib;
83 }
84 /*--------------------------------------------------------------------*//*!
85  * \brief Create a file based XML Writer instance
86  * \param fileName Name of the file
87  * \param useCompression Set to DE_TRUE to use compression, if supported by implementation
88  * \param flushAfterWrite Set to DE_TRUE to call fflush after writing each XML token
89  * \return qpXmlWriter instance, or DE_NULL if cannot create file
90  *//*--------------------------------------------------------------------*/
91 qpXmlWriter*	qpXmlWriter_createFileWriter (FILE* outFile, deBool useCompression, deBool flushAfterWrite);
92 
93 /*--------------------------------------------------------------------*//*!
94  * \brief XML Writer instance
95  * \param a	qpXmlWriter instance
96  *//*--------------------------------------------------------------------*/
97 void			qpXmlWriter_destroy (qpXmlWriter* writer);
98 
99 /*--------------------------------------------------------------------*//*!
100  * \brief XML Writer instance
101  * \param a	qpXmlWriter instance
102  *//*--------------------------------------------------------------------*/
103 void			qpXmlWriter_flush (qpXmlWriter* writer);
104 
105 /*--------------------------------------------------------------------*//*!
106  * \brief Start XML document
107  * \param writer qpXmlWriter instance
108  * \param writeXmlHeader whether to write the <xml.. header
109  * \return true on success, false on error
110  *//*--------------------------------------------------------------------*/
111 deBool			qpXmlWriter_startDocument (qpXmlWriter* writer, deBool writeXmlHeader);
112 
113 /*--------------------------------------------------------------------*//*!
114  * \brief End XML document
115  * \param writer qpXmlWriter instance
116  * \return true on success, false on error
117  *//*--------------------------------------------------------------------*/
118 deBool			qpXmlWriter_endDocument (qpXmlWriter* writer);
119 
120 /*--------------------------------------------------------------------*//*!
121  * \brief Start XML element
122  * \param writer qpXmlWriter instance
123  * \param elementName Name of the element
124  * \return true on success, false on error
125  *//*--------------------------------------------------------------------*/
126 deBool			qpXmlWriter_startElement (qpXmlWriter* writer, const char* elementName, int numAttribs, const qpXmlAttribute* attribs);
127 
128 /*--------------------------------------------------------------------*//*!
129  * \brief End XML element
130  * \param writer qpXmlWriter instance
131  * \param elementName Name of the element
132  * \return true on success, false on error
133  *//*--------------------------------------------------------------------*/
134 deBool			qpXmlWriter_endElement (qpXmlWriter* writer, const char* elementName);
135 
136 /*--------------------------------------------------------------------*//*!
137  * \brief Write raw string into XML document
138  * \param writer qpXmlWriter instance
139  * \param content String to be written
140  * \return true on success, false on error
141  *//*--------------------------------------------------------------------*/
142 deBool			qpXmlWriter_writeString (qpXmlWriter* writer, const char* content);
143 
144 /*--------------------------------------------------------------------*//*!
145  * \brief Write base64 encoded data into XML document
146  * \param writer	qpXmlWriter instance
147  * \param data		Pointer to data to be written
148  * \param numBytes	Length of data in bytes
149  * \return true on success, false on error
150  *//*--------------------------------------------------------------------*/
151 deBool			qpXmlWriter_writeBase64 (qpXmlWriter* writer, const deUint8* data, size_t numBytes);
152 
153 /*--------------------------------------------------------------------*//*!
154  * \brief Convenience function for writing XML element
155  * \param writer qpXmlWriter instance
156  * \param elementName Name of the element
157  * \param elementContent Contents of the element
158  * \return true on success, false on error
159  *//*--------------------------------------------------------------------*/
160 deBool			qpXmlWriter_writeStringElement (qpXmlWriter* writer, const char* elementName, const char* elementContent);
161 
162 DE_END_EXTERN_C
163 
164 #endif /* _QPXMLWRITER_H */
165