xml.h revision 323bf6a10a0b2a254da0d1d04a570a061f77330d
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync/** @file
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * IPRT - XML Helper APIs.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync */
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync/*
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * Copyright (C) 2007-2011 Oracle Corporation
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync *
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * available from http://www.virtualbox.org. This file is free software;
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * you can redistribute it and/or modify it under the terms of the GNU
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * General Public License (GPL) as published by the Free Software
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync *
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * The contents of this file may alternatively be used under the terms
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * of the Common Development and Distribution License Version 1.0
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * VirtualBox OSE distribution, in which case the provisions of the
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * CDDL are applicable instead of those of the GPL.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync *
456f370fcde010d585d9174df045978a6c9893c1vboxsync * You may elect to license modified versions of this file under the
27537ffef7291d0bb3a24e459a6b94c65586defevboxsync * terms and conditions of either the GPL or the CDDL or both.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync */
8c5d1958147c3988a7693b5a7666f5fe21a93b7bvboxsync
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync#ifndef ___iprt_xml_h
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync#define ___iprt_xml_h
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync
8c5d1958147c3988a7693b5a7666f5fe21a93b7bvboxsync#ifndef IN_RING3
c4c106ad74e0ad745ac49a2c4182c4f42ced7248vboxsync# error "There are no XML APIs available in Ring-0 Context!"
742ee7392dfc0ce0b48216189ce26534208b3f48vboxsync#endif
c4c106ad74e0ad745ac49a2c4182c4f42ced7248vboxsync
c4c106ad74e0ad745ac49a2c4182c4f42ced7248vboxsync#include <list>
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync#include <memory>
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync#include <iprt/cpp/exception.h>
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/** @defgroup grp_rt_cpp_xml C++ XML support
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @ingroup grp_rt_cpp
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/* Forwards */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef struct _xmlParserInput xmlParserInput;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef xmlParserInput *xmlParserInputPtr;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef struct _xmlParserCtxt xmlParserCtxt;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef xmlParserCtxt *xmlParserCtxtPtr;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef struct _xmlError xmlError;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef xmlError *xmlErrorPtr;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef struct _xmlAttr xmlAttr;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef struct _xmlNode xmlNode;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/** @} */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncnamespace xml
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @addtogroup grp_rt_cpp_xml
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync// Exceptions
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync//////////////////////////////////////////////////////////////////////////////
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS LogicError : public RTCError
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync LogicError(const char *aMsg = NULL)
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync : RTCError(aMsg)
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync LogicError(RT_SRC_POS_DECL);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS RuntimeError : public RTCError
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync{
f7d6665d93770b79026556438d5e081807917420vboxsyncpublic:
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync RuntimeError(const char *aMsg = NULL)
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync : RTCError(aMsg)
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync {}
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync};
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync
7bff28e0cedd8656acd24b420759649184d8cf00vboxsyncclass RT_DECL_CLASS XmlError : public RuntimeError
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync XmlError(xmlErrorPtr aErr);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync static char* Format(xmlErrorPtr aErr);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync// Logical errors
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync//////////////////////////////////////////////////////////////////////////////
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS ENotImplemented : public LogicError
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync ENotImplemented(const char *aMsg = NULL) : LogicError(aMsg) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync ENotImplemented(RT_SRC_POS_DECL) : LogicError(RT_SRC_POS_ARGS) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
e1efbeea1e5e1e63cc2be01c582cec73bc58e839vboxsyncclass RT_DECL_CLASS EInvalidArg : public LogicError
e1efbeea1e5e1e63cc2be01c582cec73bc58e839vboxsync{
e1efbeea1e5e1e63cc2be01c582cec73bc58e839vboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync EInvalidArg(const char *aMsg = NULL) : LogicError(aMsg) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync EInvalidArg(RT_SRC_POS_DECL) : LogicError(RT_SRC_POS_ARGS) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS EDocumentNotEmpty : public LogicError
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync EDocumentNotEmpty(const char *aMsg = NULL) : LogicError(aMsg) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync EDocumentNotEmpty(RT_SRC_POS_DECL) : LogicError(RT_SRC_POS_ARGS) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS ENodeIsNotElement : public LogicError
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync ENodeIsNotElement(const char *aMsg = NULL) : LogicError(aMsg) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync ENodeIsNotElement(RT_SRC_POS_DECL) : LogicError(RT_SRC_POS_ARGS) {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync// Runtime errors
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync//////////////////////////////////////////////////////////////////////////////
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS EIPRTFailure : public RuntimeError
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync EIPRTFailure(int aRC, const char *pcszContext, ...);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync int rc() const
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync {
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync return mRC;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync }
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncprivate:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync int mRC;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * The Stream class is a base class for I/O streams.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS Stream
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual ~Stream() {}
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual const char *uri() const = 0;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Returns the current read/write position in the stream. The returned
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * position is a zero-based byte offset from the beginning of the file.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Throws ENotImplemented if this operation is not implemented for the
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * given stream.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual uint64_t pos() const = 0;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Sets the current read/write position in the stream.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aPos Zero-based byte offset from the beginning of the stream.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Throws ENotImplemented if this operation is not implemented for the
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * given stream.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual void setPos (uint64_t aPos) = 0;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * The Input class represents an input stream.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * This input stream is used to read the settings tree from.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * This is an abstract class that must be subclassed in order to fill it with
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * useful functionality.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS Input : virtual public Stream
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Reads from the stream to the supplied buffer.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aBuf Buffer to store read data to.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aLen Buffer length.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @return Number of bytes read.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual int read (char *aBuf, int aLen) = 0;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS Output : virtual public Stream
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Writes to the stream from the supplied buffer.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aBuf Buffer to write data from.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aLen Buffer length.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @return Number of bytes written.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual int write (const char *aBuf, int aLen) = 0;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
ea196eaae4348f1908e5693c07f62d1759d870d1vboxsync * Truncates the stream from the current position and upto the end.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * The new file size will become exactly #pos() bytes.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Throws ENotImplemented if this operation is not implemented for the
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * given stream.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual void truncate() = 0;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync//////////////////////////////////////////////////////////////////////////////
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * The File class is a stream implementation that reads from and writes to
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * regular files.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * The File class uses IPRT File API for file operations. Note that IPRT File
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * API is not thread-safe. This means that if you pass the same RTFILE handle to
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * different File instances that may be simultaneously used on different
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * threads, you should care about serialization; otherwise you will get garbage
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * when reading from or writing to such File instances.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS File : public Input, public Output
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Possible file access modes.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync enum Mode { Mode_Read, Mode_WriteCreate, Mode_Overwrite, Mode_ReadWrite };
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Opens a file with the given name in the given mode. If @a aMode is Read
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * or ReadWrite, the file must exist. If @a aMode is Write, the file must
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * not exist. Otherwise, an EIPRTFailure excetion will be thrown.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aMode File mode.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aFileName File name.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aFlushIt Whether to flush a writable file before closing it.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync File(Mode aMode, const char *aFileName, bool aFlushIt = false);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Uses the given file handle to perform file operations. This file
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * handle must be already open in necessary mode (read, or write, or mixed).
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * The read/write position of the given handle will be reset to the
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * beginning of the file on success.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Note that the given file handle will not be automatically closed upon
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * this object destruction.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @note It you pass the same RTFILE handle to more than one File instance,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * please make sure you have provided serialization in case if these
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * instasnces are to be simultaneously used by different threads.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Otherwise you may get garbage when reading or writing.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aHandle Open file handle.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aFileName File name (for reference).
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * @param aFlushIt Whether to flush a writable file before closing it.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync File(RTFILE aHandle, const char *aFileName = NULL, bool aFlushIt = false);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Destroys the File object. If the object was created from a file name
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * the corresponding file will be automatically closed. If the object was
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * created from a file handle, it will remain open.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual ~File();
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync const char *uri() const;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync uint64_t pos() const;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync void setPos(uint64_t aPos);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * See Input::read(). If this method is called in wrong file mode,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * LogicError will be thrown.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync int read(char *aBuf, int aLen);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * See Output::write(). If this method is called in wrong file mode,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * LogicError will be thrown.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync int write(const char *aBuf, int aLen);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * See Output::truncate(). If this method is called in wrong file mode,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * LogicError will be thrown.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync void truncate();
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncprivate:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /* Obscure class data */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync struct Data;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync Data *m;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /* auto_ptr data doesn't have proper copy semantics */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP (File)
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * The MemoryBuf class represents a stream implementation that reads from the
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * memory buffer.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS MemoryBuf : public Input
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync MemoryBuf (const char *aBuf, size_t aLen, const char *aURI = NULL);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync virtual ~MemoryBuf();
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync const char *uri() const;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync int read(char *aBuf, int aLen);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync uint64_t pos() const;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync void setPos(uint64_t aPos);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncprivate:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /* Obscure class data */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync struct Data;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync Data *m;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /* auto_ptr data doesn't have proper copy semantics */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(MemoryBuf)
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/*
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * GlobalLock
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef xmlParserInput* FNEXTERNALENTITYLOADER(const char *aURI,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync const char *aID,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync xmlParserCtxt *aCtxt);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef FNEXTERNALENTITYLOADER *PFNEXTERNALENTITYLOADER;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass RT_DECL_CLASS GlobalLock
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync{
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncpublic:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync GlobalLock();
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync ~GlobalLock();
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync void setExternalEntityLoader(PFNEXTERNALENTITYLOADER pFunc);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync static xmlParserInput* callDefaultLoader(const char *aURI,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync const char *aID,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync xmlParserCtxt *aCtxt);
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncprivate:
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync /* Obscure class data. */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync struct Data;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync struct Data *m;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync};
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass ElementNode;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsynctypedef std::list<const ElementNode*> ElementNodesList;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass AttributeNode;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncclass ContentNode;
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync/**
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * Node base class. Cannot be used directly, but ElementNode, ContentNode and
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync * AttributeNode derive from this. This does implement useful public methods though.
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
771761cda2c81e899526a0dce22c8cd2510fff82vboxsyncclass RT_DECL_CLASS Node
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync{
771761cda2c81e899526a0dce22c8cd2510fff82vboxsyncpublic:
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync ~Node();
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync const char* getName() const;
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync bool nameEquals(const char *pcszNamespace, const char *pcsz) const;
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync bool nameEquals(const char *pcsz) const
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync {
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync return nameEquals(NULL, pcsz);
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync }
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync const char* getValue() const;
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync bool copyValue(int32_t &i) const;
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync bool copyValue(uint32_t &i) const;
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync bool copyValue(int64_t &i) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync bool copyValue(uint64_t &i) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync int getLineNumber() const;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync int isElement() const
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync {
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync return m_Type == IsElement;
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync }
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync
771761cda2c81e899526a0dce22c8cd2510fff82vboxsyncprotected:
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync typedef enum {IsElement, IsAttribute, IsContent} EnumType;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync EnumType m_Type;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync Node *m_pParent;
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync xmlNode *m_plibNode; // != NULL if this is an element or content node
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync xmlAttr *m_plibAttr; // != NULL if this is an attribute node
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync const char *m_pcszNamespacePrefix; // not always set
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync const char *m_pcszNamespaceHref; // full http:// spec
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync const char *m_pcszName; // element or attribute name, points either into plibNode or plibAttr;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync // NULL if this is a content node
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync // hide the default constructor so people use only our factory methods
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync Node(EnumType type,
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync Node *pParent,
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync xmlNode *plibNode,
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync xmlAttr *plibAttr);
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync Node(const Node &x); // no copying
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync void buildChildren(const ElementNode &elmRoot);
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync /* Obscure class data */
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync struct Data;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync Data *m;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync friend class AttributeNode;
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync};
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync/**
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync * Node subclass that represents an element.
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync *
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync * For elements, Node::getName() returns the element name, and Node::getValue()
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync * returns the text contents, if any.
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync *
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync * Since the Node constructor is private, one can create element nodes
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync * only through the following factory methods:
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync *
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync * -- Document::createRootElement()
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync * -- ElementNode::createChild()
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync */
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsyncclass RT_DECL_CLASS ElementNode : public Node
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync{
771761cda2c81e899526a0dce22c8cd2510fff82vboxsyncpublic:
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync int getChildElements(ElementNodesList &children,
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync const char *pcszMatch = NULL) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync const ElementNode* findChildElement(const char *pcszNamespace,
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync const char *pcszMatch) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync const ElementNode* findChildElement(const char *pcszMatch) const
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync {
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync return findChildElement(NULL, pcszMatch);
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync }
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync const ElementNode* findChildElementFromId(const char *pcszId) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync const AttributeNode* findAttribute(const char *pcszMatch) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync bool getAttributeValue(const char *pcszMatch, const char *&ppcsz) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync bool getAttributeValue(const char *pcszMatch, iprt::MiniString &str) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync bool getAttributeValuePath(const char *pcszMatch, iprt::MiniString &str) const;
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync bool getAttributeValue(const char *pcszMatch, int32_t &i) const;
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync bool getAttributeValue(const char *pcszMatch, uint32_t &i) const;
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync bool getAttributeValue(const char *pcszMatch, int64_t &i) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync bool getAttributeValue(const char *pcszMatch, uint64_t &i) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync bool getAttributeValue(const char *pcszMatch, bool &f) const;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync ElementNode* createChild(const char *pcszElementName);
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync ContentNode* addContent(const char *pcszContent);
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync ContentNode* addContent(const iprt::MiniString &strContent)
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync {
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync return addContent(strContent.c_str());
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync }
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync AttributeNode* setAttribute(const char *pcszName, const char *pcszValue);
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync AttributeNode* setAttribute(const char *pcszName, const iprt::MiniString &strValue)
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync {
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync return setAttribute(pcszName, strValue.c_str());
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync }
df3d4c8e9c81584c535676a3d40c57d868ac61bbvboxsync AttributeNode* setAttributePath(const char *pcszName, const iprt::MiniString &strValue);
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync AttributeNode* setAttribute(const char *pcszName, int32_t i);
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync AttributeNode* setAttribute(const char *pcszName, uint32_t i);
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync AttributeNode* setAttribute(const char *pcszName, int64_t i);
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync AttributeNode* setAttribute(const char *pcszName, uint64_t i);
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync AttributeNode* setAttributeHex(const char *pcszName, uint32_t i);
ea17f2e36383176db94ff3608f628a1e7432fa60vboxsync AttributeNode* setAttribute(const char *pcszName, bool f);
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync
7bff28e0cedd8656acd24b420759649184d8cf00vboxsyncprotected:
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync // hide the default constructor so people use only our factory methods
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync ElementNode(const ElementNode *pelmRoot, Node *pParent, xmlNode *plibNode);
9c59bcefe2993070fafaf0d6cee9673f48479128vboxsync ElementNode(const ElementNode &x); // no copying
f902ede7eb073d09a81c1d470c089c7b14921714vboxsync
97674677e4f2aeae576c39f966568dd664ba7979vboxsync const ElementNode *m_pelmRoot;
efbdd9fc22305720d20be7cc37b4f45f43146b09vboxsync
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync friend class Node;
18673eee0624b4581d3d56ab9ad9d10ebc7f5bddvboxsync friend class Document;
22e47c581ecabc66ee210e93099727074f74b2b9vboxsync friend class XmlFileParser;
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync};
907ba2c9b3d1821f95be17115ecad9fe8a2cae02vboxsync
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync/**
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * Node subclass that represents content (non-element text).
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync *
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * Since the Node constructor is private, one can create new content nodes
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * only through the following factory methods:
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync *
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * -- ElementNode::addContent()
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync */
7bff28e0cedd8656acd24b420759649184d8cf00vboxsyncclass RT_DECL_CLASS ContentNode : public Node
3b58b08293698f7f081b5558c52e80741a4a6763vboxsync{
c5861c548c83913808475ea59cab2e09a23247c8vboxsyncpublic:
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncprotected:
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync // hide the default constructor so people use only our factory methods
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync ContentNode(Node *pParent, xmlNode *plibNode);
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync ContentNode(const ContentNode &x); // no copying
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync friend class Node;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync friend class ElementNode;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync};
ea17f2e36383176db94ff3608f628a1e7432fa60vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync/**
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * Node subclass that represents an attribute of an element.
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync *
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * For attributes, Node::getName() returns the attribute name, and Node::getValue()
9c59bcefe2993070fafaf0d6cee9673f48479128vboxsync * returns the attribute value, if any.
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync *
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * Since the Node constructor is private, one can create new attribute nodes
efbdd9fc22305720d20be7cc37b4f45f43146b09vboxsync * only through the following factory methods:
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync *
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * -- ElementNode::setAttribute()
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync */
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncclass RT_DECL_CLASS AttributeNode : public Node
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync{
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsyncpublic:
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncprotected:
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync // hide the default constructor so people use only our factory methods
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync AttributeNode(const ElementNode &elmRoot,
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync Node *pParent,
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync xmlAttr *plibAttr,
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync const char **ppcszKey);
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync AttributeNode(const AttributeNode &x); // no copying
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync iprt::MiniString m_strKey;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync friend class Node;
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync friend class ElementNode;
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync};
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync/**
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync * Handy helper class with which one can loop through all or some children
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync * of a particular element. See NodesLoop::forAllNodes() for details.
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync */
8e1c5c73ab19c968abbd3decf41e4783cbd8c017vboxsyncclass RT_DECL_CLASS NodesLoop
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync{
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsyncpublic:
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync NodesLoop(const ElementNode &node, const char *pcszMatch = NULL);
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync ~NodesLoop();
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync const ElementNode* forAllNodes() const;
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsyncprivate:
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync /* Obscure class data */
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync struct Data;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync Data *m;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync};
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync/**
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync * The XML document class. An instance of this needs to be created by a user
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync * of the XML classes and then passed to
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync *
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * -- XmlMemParser or XmlFileParser to read an XML document; those classes then
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * fill the caller's Document with ElementNode, ContentNode and AttributeNode
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync * instances. The typical sequence then is:
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync * @code
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync Document doc;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync XmlFileParser parser;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync parser.read("file.xml", doc);
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync Element *pelmRoot = doc.getRootElement();
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync @endcode
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync *
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync * -- XmlMemWriter or XmlFileWriter to write out an XML document after it has
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync * been created and filled. Example:
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync *
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync * @code
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync Document doc;
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync Element *pelmRoot = doc.createRootElement();
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync // add children
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync xml::XmlFileWriter writer(doc);
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync writer.write("file.xml", true);
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync @endcode
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync */
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsyncclass RT_DECL_CLASS Document
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync{
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsyncpublic:
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync Document();
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync ~Document();
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync Document(const Document &x);
ae9aaa62489b8ace9ce2a0a15f0b2f7d3be340c6vboxsync Document& operator=(const Document &x);
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync const ElementNode* getRootElement() const;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync ElementNode* getRootElement();
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync ElementNode* createRootElement(const char *pcszRootElementName,
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync const char *pcszComment = NULL);
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncprivate:
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync friend class XmlMemParser;
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync friend class XmlFileParser;
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync friend class XmlMemWriter;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync friend class XmlFileWriter;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync void refreshInternals();
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync
ae9aaa62489b8ace9ce2a0a15f0b2f7d3be340c6vboxsync /* Obscure class data */
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync struct Data;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync Data *m;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync};
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync/*
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * XmlParserBase
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync *
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync */
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncclass RT_DECL_CLASS XmlParserBase
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync{
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncprotected:
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync XmlParserBase();
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync ~XmlParserBase();
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync xmlParserCtxtPtr m_ctxt;
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync};
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync/*
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * XmlMemParser
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsync *
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync */
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncclass RT_DECL_CLASS XmlMemParser : public XmlParserBase
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync{
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsyncpublic:
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync XmlMemParser();
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync ~XmlMemParser();
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync void read(const void* pvBuf, size_t cbSize, const iprt::MiniString &strFilename, Document &doc);
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync};
6e3cc82d5d5effda92c9fec18b870d54386f99favboxsync
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync/*
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync * XmlFileParser
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync *
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync */
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsyncclass RT_DECL_CLASS XmlFileParser : public XmlParserBase
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync{
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsyncpublic:
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync XmlFileParser();
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync ~XmlFileParser();
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync void read(const iprt::MiniString &strFilename, Document &doc);
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
9a08dd6ed47cffa9cacbb9d53db1ce71d04db61fvboxsyncprivate:
f4ccb18a71e0e531719734918583f84fbc72ebfevboxsync /* Obscure class data */
13b516eac15d19e108e587a9d9ecc85e1961ac6dvboxsync struct Data;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync struct Data *m;
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync static int ReadCallback(void *aCtxt, char *aBuf, int aLen);
76800c2d8e954bb5249d2d30f4af41c6ea03ad5evboxsync static int CloseCallback (void *aCtxt);
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync};
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync/*
8dc3361c3de6b4f38230d57c547ab74b713f6ff1vboxsync * XmlMemParser
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync *
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync */
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync
class RT_DECL_CLASS XmlMemWriter
{
public:
XmlMemWriter();
~XmlMemWriter();
void write(const Document &doc, void** ppvBuf, size_t *pcbSize);
private:
void* m_pBuf;
};
/*
* XmlFileWriter
*
*/
class RT_DECL_CLASS XmlFileWriter
{
public:
XmlFileWriter(Document &doc);
~XmlFileWriter();
/**
* Writes the XML document to the specified file.
*
* @param pcszFilename The name of the output file.
* @param fSafe If @c true, some extra safety precautions will be
* taken when writing the file:
* -# The file is written with a '-tmp' suffix.
* -# It is flushed to disk after writing.
* -# Any original file is renamed to '-prev'.
* -# The '-tmp' file is then renamed to the
* specified name.
* -# The directory changes are flushed to disk.
* The suffixes are available via s_pszTmpSuff and
* s_pszPrevSuff.
*/
void write(const char *pcszFilename, bool fSafe);
static int WriteCallback(void *aCtxt, const char *aBuf, int aLen);
static int CloseCallback(void *aCtxt);
/** The suffix used by XmlFileWriter::write() for the temporary file. */
static const char * const s_pszTmpSuff;
/** The suffix used by XmlFileWriter::write() for the previous (backup) file. */
static const char * const s_pszPrevSuff;
private:
void writeInternal(const char *pcszFilename, bool fSafe);
/* Obscure class data */
struct Data;
Data *m;
};
#if defined(_MSC_VER)
#pragma warning (default:4251)
#endif
/** @} */
} // end namespace xml
#endif /* !___iprt_xml_h */