⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlwrite.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: xmlwrite.cpp,v 1.5.32.1 2004/07/19 21:04:07 hubbe Exp $ *  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. *  * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks.  You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL.  Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. *  * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. *  * Technology Compatibility Kit Test Suite(s) Location: *    http://www.helixcommunity.org/content/tck *  * Contributor(s): *  * ***** END LICENSE BLOCK ***** *//*  * $Id: xmlwrite.cpp,v 1.5.32.1 2004/07/19 21:04:07 hubbe Exp $ * * XMLWriter Class Implementation File * ----------------------------------- *  * Author:	Consumer Group *		RealNetworks Inc., Copyright (C) 1997, All rights reserved *		January 12, 1999 * * Abstraction: * This file contains the implementation of the XMLWriter class and all it's  * helper classes. * */// Includes for this file...#include "xmlwrite.h"#include "looseprs.h"#include "hxslist.h"#include "chxdataf.h"#include "hxcom.h"#include "hxbuffer.h"#include "hxstrutl.h"//#include <fcntl.h>// For debugging...#include "hxassert.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE             static const char HX_THIS_FILE[] = __FILE__;#endif#define MAX_WRITER_BUFFER 1024#if defined _WINDOWS#define WRITER_EOL "\n"#elif defined _MACINTOSH#define WRITER_EOL "\r"#else#define WRITER_EOL "\n"#endif/* * XMLWriter * --------- * Constructor. * * input: * void * * output: * N/A * */XMLWriter::XMLWriter(void){}/* * ~XMLWriter * ---------- * Destructor. * * input: * void * * output: * N/A * */XMLWriter::~XMLWriter(void){    // Clear it...    Clear();}/* * CreateTag * --------- * Creates a tag in the writer and returns a pointer to it. * * input: * const char *name	    - Name for the tag. * * output: * XMLWriterTag *	    - Pointer to the newly created tag. * */XMLWriterTag *XMLWriter::CreateTag(const char *name){    // Create the tag...    XMLWriterTag *newTag = new XMLWriterTag;    HX_ASSERT(newTag != NULL);    newTag->SetName(name);        // Add the tag to the array...    m_tags.AddTail(newTag);    return newTag;}/* * Write * ----- * Writes all the data to a IHXBuffer object and returns a pointer to the buffer. * * input: * IHXBuffer *		- Pointer to an IHXBuffer.  User must delete it. * INT32& length	- Number of characters written out to the buffer. * * output: * BOOL			- TRUE if successful. * */BOOLXMLWriter::Write(IHXBuffer *buffer, INT32& numChars){    HX_ASSERT(buffer != NULL);    // Get the size required...    INT32 length = GetLength();    // Set the size for the buffer...    buffer->SetSize(length + length/2);    // Go through the tags and write them to the buffer...    LISTPOSITION position = m_tags.GetHeadPosition();    while (position != NULL)	((XMLWriterTag *)(m_tags.GetNext(position)))->Write(buffer, numChars);    // Ok..    return TRUE;}/*  * GetLength * --------- * Returns the entire length required for the tree of xml. * * input: * void * * output: * INT32	    - Length to write the xml. * */INT32XMLWriter::GetLength(void) const{    INT32 length = 0;    // Go through the list of tags and sum up their individual lengths....    LISTPOSITION position = m_tags.GetHeadPosition();    while (position != NULL)    {	XMLWriterTag *tag = (XMLWriterTag *)(m_tags.GetNext(position));	length += tag->GetLength();    }    return length;}/*  * Clear * ----- * Clear the structure from memory. * * input: * void * * output: * void * */voidXMLWriter::Clear(void){    // If there are any tags in the list, delete them...    LISTPOSITION position = m_tags.GetHeadPosition();    while(position != NULL)    {	delete (XMLWriterTag *)(m_tags.GetNext(position));    }}//*****************************************************************************************************************// XMLWriterAttribute Implementation//***************************************************************************************************************** /* * XMLWriterAttribute * ------------------ * Writer attribute constructor. * * input: * void * * output: * N/A * */XMLWriterAttribute::XMLWriterAttribute(void) : m_name(NULL), m_value(NULL){} /*  * ~XMLWriterAttribute * ------------------- * Writer attribute destructor. * * input: * void * * output: * N/A * */XMLWriterAttribute::~XMLWriterAttribute(void){    // Delete the strings...    if (m_name != NULL) delete [] m_name;    if (m_value != NULL) delete [] m_value;    m_name = m_value = NULL;}/*  * Write * ----- * Write to the given buffer. * * input: * IHXBuffer *buffer		    - Buffer to write to. * INT32 loc			    - Pointer into the buffer from where to begin to write. * * output: * void * */voidXMLWriterAttribute::Write(IHXBuffer *buffer, INT32& loc){    HX_ASSERT(buffer != NULL);        // If either the name or the value are empty, do not write anything out...    if (m_name == NULL) return;    // Properly format what we will write out...    char temp[MAX_WRITER_BUFFER]; /* Flawfinder: ignore */    temp[0] = '\0';    char tabs[MAX_WRITER_BUFFER]; /* Flawfinder: ignore */    tabs[0] = '\0';    // Create the proper indentation...    for (INT32 i = 0; i < m_depth; i++)	SafeStrCat(tabs, "\t", MAX_WRITER_BUFFER);    // Create the output string...    SafeSprintf(temp, MAX_WRITER_BUFFER, "%s%s=\"%s\"", tabs, m_name, m_value);    // Write to file...    SafeStrCpy((char *)(buffer->GetBuffer()) + loc,  temp, buffer->GetSize()-loc);    loc += strlen(temp);}/* * GetLength * --------- * Returns the length required to print this attribute. * * input: * void * * output: * INT32	    - Length required. * */INT32 XMLWriterAttribute::GetLength(void) const{    // Get the lengths of the strings and return their sum...    INT32 nameLength = strlen(m_name);    INT32 valueLength = strlen(m_value);    return m_depth + nameLength + valueLength + 2;}/* * SetName * ------- * Set the name for the attribute. * * input: * const char *name	    - Name of the attribute. * * output: * void * */void XMLWriterAttribute::SetName(const char *name){    if (m_name != NULL) delete [] m_name;    m_name = NULL;    if (name == NULL) return;    m_name = new char[strlen(name) + 1];    strcpy(m_name, name); /* Flawfinder: ignore */}/* * SetValue * -------- * Set the value for the attribute. * * input: * const char *value		- Value of the attribute. * * output: * void * */voidXMLWriterAttribute::SetValue(const char *value){    if (m_value != NULL) delete [] m_value;    m_value = NULL;    if (value == NULL) return;    m_value = new char[strlen(value) + 1];    strcpy(m_value, value); /* Flawfinder: ignore */}//*****************************************************************************************************************// XMLWriterTag Implementation//*****************************************************************************************************************/*  * XMLWriterTag * ------------ * Constructor. * * input: * void * * output: * N/A * */XMLWriterTag::XMLWriterTag(void) : m_type(XMLPlainTag), m_name(NULL), m_comment(NULL), m_depth(0){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -