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 30DE_BEGIN_EXTERN_C 31 32typedef struct qpXmlWriter_s qpXmlWriter; 33 34typedef 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 43typedef struct qpXmlAttribute_s 44{ 45 const char* name; 46 qpXmlAttributeType type; 47 const char* stringValue; 48 int intValue; 49 deBool boolValue; 50} qpXmlAttribute; 51 52DE_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 63DE_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 74DE_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 *//*--------------------------------------------------------------------*/ 91qpXmlWriter* qpXmlWriter_createFileWriter (FILE* outFile, deBool useCompression, deBool flushAfterWrite); 92 93/*--------------------------------------------------------------------*//*! 94 * \brief XML Writer instance 95 * \param a qpXmlWriter instance 96 *//*--------------------------------------------------------------------*/ 97void qpXmlWriter_destroy (qpXmlWriter* writer); 98 99/*--------------------------------------------------------------------*//*! 100 * \brief XML Writer instance 101 * \param a qpXmlWriter instance 102 *//*--------------------------------------------------------------------*/ 103void qpXmlWriter_flush (qpXmlWriter* writer); 104 105/*--------------------------------------------------------------------*//*! 106 * \brief Start XML document 107 * \param writer qpXmlWriter instance 108 * \return true on success, false on error 109 *//*--------------------------------------------------------------------*/ 110deBool qpXmlWriter_startDocument (qpXmlWriter* writer); 111 112/*--------------------------------------------------------------------*//*! 113 * \brief End XML document 114 * \param writer qpXmlWriter instance 115 * \return true on success, false on error 116 *//*--------------------------------------------------------------------*/ 117deBool qpXmlWriter_endDocument (qpXmlWriter* writer); 118 119/*--------------------------------------------------------------------*//*! 120 * \brief Start XML element 121 * \param writer qpXmlWriter instance 122 * \param elementName Name of the element 123 * \return true on success, false on error 124 *//*--------------------------------------------------------------------*/ 125deBool qpXmlWriter_startElement (qpXmlWriter* writer, const char* elementName, int numAttribs, const qpXmlAttribute* attribs); 126 127/*--------------------------------------------------------------------*//*! 128 * \brief End XML element 129 * \param writer qpXmlWriter instance 130 * \param elementName Name of the element 131 * \return true on success, false on error 132 *//*--------------------------------------------------------------------*/ 133deBool qpXmlWriter_endElement (qpXmlWriter* writer, const char* elementName); 134 135/*--------------------------------------------------------------------*//*! 136 * \brief Write raw string into XML document 137 * \param writer qpXmlWriter instance 138 * \param content String to be written 139 * \return true on success, false on error 140 *//*--------------------------------------------------------------------*/ 141deBool qpXmlWriter_writeString (qpXmlWriter* writer, const char* content); 142 143/*--------------------------------------------------------------------*//*! 144 * \brief Write base64 encoded data into XML document 145 * \param writer qpXmlWriter instance 146 * \param data Pointer to data to be written 147 * \param numBytes Length of data in bytes 148 * \return true on success, false on error 149 *//*--------------------------------------------------------------------*/ 150deBool qpXmlWriter_writeBase64 (qpXmlWriter* writer, const deUint8* data, size_t numBytes); 151 152/*--------------------------------------------------------------------*//*! 153 * \brief Convenience function for writing XML element 154 * \param writer qpXmlWriter instance 155 * \param elementName Name of the element 156 * \param elementContent Contents of the element 157 * \return true on success, false on error 158 *//*--------------------------------------------------------------------*/ 159deBool qpXmlWriter_writeStringElement (qpXmlWriter* writer, const char* elementName, const char* elementContent); 160 161DE_END_EXTERN_C 162 163#endif /* _QPXMLWRITER_H */ 164