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

📄 qdom.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtXML module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <qplatformdefs.h>#include <qdom.h>#include "qxmlutils_p.h"#ifndef QT_NO_DOM#include <qatomic.h>#include <qbuffer.h>#include <qhash.h>#include <qiodevice.h>#include <qlist.h>#include <qregexp.h>#include <qtextcodec.h>#include <qtextstream.h>#include <qxml.h>#include <qvariant.h>#include <qmap.h>#include <qdebug.h>#include <stdio.h>/*  ### old todo comments -- I don't know if they still apply...  If the document dies, remove all pointers to it from children  which can not be deleted at this time.  If a node dies and has direct children which can not be deleted,  then remove the pointer to the parent.  createElement and friends create double reference counts.*//* ##### new TODOs:  Remove emtpy emthods in the *Private classes  Make a lot of the (mostly empty) methods in the public classes inline.  Specially constructors assignment operators and comparison operators are candidates.  The virtual isXxx functions in *Private can probably be replaced by inline methods checking the nodeType().*//*  Reference counting:  Some simple rules:  1) If an intern object returns a pointer to another intern object     then the reference count of the returned object is not increased.  2) If an extern object is created and gets a pointer to some intern     object, then the extern object increases the intern objects reference count.  3) If an extern object is deleted, then it decreases the reference count     on its associated intern object and deletes it if nobody else hold references     on the intern object.*//*  Helper to split a qualified name in the prefix and local name.*/static void qt_split_namespace(QString& prefix, QString& name, const QString& qName, bool hasURI){    int i = qName.indexOf(QLatin1Char(':'));    if (i == -1) {        if (hasURI)            prefix = QLatin1String("");        else            prefix.clear();        name = qName;    } else {        prefix = qName.left(i);        name = qName.mid(i + 1);    }}// ##### shouldn't this be a member of QDomDocumentPrivate?/*  Counter for the QDomNodeListPrivate timestamps.*/static volatile long qt_nodeListTime = 0;/************************************************************** * * Private class declerations * **************************************************************/class QDomImplementationPrivate{public:    QDomImplementationPrivate() { ref = 1; }    QDomImplementationPrivate* clone();    QAtomic ref;    static QDomImplementation::InvalidDataPolicy invalidDataPolicy;};class QDomNodePrivate{public:    QDomNodePrivate(QDomDocumentPrivate*, QDomNodePrivate* parent = 0);    QDomNodePrivate(QDomNodePrivate* n, bool deep);    virtual ~QDomNodePrivate();    QString nodeName() const { return name; }    QString nodeValue() const { return value; }    virtual void setNodeValue(const QString& v) { value = v; }    QDomDocumentPrivate* ownerDocument();    void setOwnerDocument(QDomDocumentPrivate* doc);    virtual QDomNodePrivate* insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild);    virtual QDomNodePrivate* insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild);    virtual QDomNodePrivate* replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild);    virtual QDomNodePrivate* removeChild(QDomNodePrivate* oldChild);    virtual QDomNodePrivate* appendChild(QDomNodePrivate* newChild);    QDomNodePrivate* namedItem(const QString& name);    virtual QDomNodePrivate* cloneNode(bool deep = true);    virtual void normalize();    virtual void clear();    inline QDomNodePrivate* parent() const { return hasParent ? ownerNode : 0; }    inline void setParent(QDomNodePrivate *p) { ownerNode = p; hasParent = true; }    void setNoParent() {        ownerNode = hasParent ? (QDomNodePrivate*)ownerDocument() : 0;        hasParent = false;    }    // Dynamic cast    virtual bool isAttr() const                     { return false; }    virtual bool isCDATASection() const             { return false; }    virtual bool isDocumentFragment() const         { return false; }    virtual bool isDocument() const                 { return false; }    virtual bool isDocumentType() const             { return false; }    virtual bool isElement() const                  { return false; }    virtual bool isEntityReference() const          { return false; }    virtual bool isText() const                     { return false; }    virtual bool isEntity() const                   { return false; }    virtual bool isNotation() const                 { return false; }    virtual bool isProcessingInstruction() const    { return false; }    virtual bool isCharacterData() const            { return false; }    virtual bool isComment() const                  { return false; }    virtual QDomNode::NodeType nodeType() const { return QDomNode::BaseNode; }    virtual void save(QTextStream&, int, int) const;    void setLocation(int lineNumber, int columnNumber);    // Variables    QAtomic ref;    QDomNodePrivate* prev;    QDomNodePrivate* next;    QDomNodePrivate* ownerNode; // either the node's parent or the node's owner document    QDomNodePrivate* first;    QDomNodePrivate* last;    QString name; // this is the local name if prefix != null    QString value;    QString prefix; // set this only for ElementNode and AttributeNode    QString namespaceURI; // set this only for ElementNode and AttributeNode    bool createdWithDom1Interface : 1;    bool hasParent                : 1;    int lineNumber;    int columnNumber;};class QDomNodeListPrivate{public:    QDomNodeListPrivate(QDomNodePrivate*);    QDomNodeListPrivate(QDomNodePrivate*, const QString& );    QDomNodeListPrivate(QDomNodePrivate*, const QString&, const QString& );    ~QDomNodeListPrivate();    bool operator== (const QDomNodeListPrivate&) const;    bool operator!= (const QDomNodeListPrivate&) const;    void createList();    QDomNodePrivate* item(int index);    uint length() const;    QAtomic ref;    QDomNodePrivate* node_impl;    QString tagname;    QString nsURI;    QList<QDomNodePrivate*> list;    long timestamp;};class QDomNamedNodeMapPrivate{public:    QDomNamedNodeMapPrivate(QDomNodePrivate*);    ~QDomNamedNodeMapPrivate();    QDomNodePrivate* namedItem(const QString& name) const;    QDomNodePrivate* namedItemNS(const QString& nsURI, const QString& localName) const;    QDomNodePrivate* setNamedItem(QDomNodePrivate* arg);    QDomNodePrivate* setNamedItemNS(QDomNodePrivate* arg);    QDomNodePrivate* removeNamedItem(const QString& name);    QDomNodePrivate* item(int index) const;    uint length() const;    bool contains(const QString& name) const;    bool containsNS(const QString& nsURI, const QString & localName) const;    /**     * Remove all children from the map.     */    void clearMap();    bool isReadOnly() { return readonly; }    void setReadOnly(bool r) { readonly = r; }    bool isAppendToParent() { return appendToParent; }    /**     * If true, then the node will redirect insert/remove calls     * to its parent by calling QDomNodePrivate::appendChild or removeChild.     * In addition the map wont increase or decrease the reference count     * of the nodes it contains.     *     * By default this value is false and the map will handle reference counting     * by itself.     */    void setAppendToParent(bool b) { appendToParent = b; }    /**     * Creates a copy of the map. It is a deep copy     * that means that all children are cloned.     */    QDomNamedNodeMapPrivate* clone(QDomNodePrivate* parent);    // Variables    QAtomic ref;    QHash<QString, QDomNodePrivate *> map;    QDomNodePrivate* parent;    bool readonly;    bool appendToParent;};class QDomDocumentTypePrivate : public QDomNodePrivate{public:    QDomDocumentTypePrivate(QDomDocumentPrivate*, QDomNodePrivate* parent = 0);    QDomDocumentTypePrivate(QDomDocumentTypePrivate* n, bool deep);    ~QDomDocumentTypePrivate();    void init();    // Reimplemented from QDomNodePrivate    QDomNodePrivate* cloneNode(bool deep = true);    QDomNodePrivate* insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild);    QDomNodePrivate* insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild);    QDomNodePrivate* replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild);    QDomNodePrivate* removeChild(QDomNodePrivate* oldChild);    QDomNodePrivate* appendChild(QDomNodePrivate* newChild);    virtual bool isDocumentType() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::DocumentTypeNode; }    void save(QTextStream& s, int, int) const;    // Variables    QDomNamedNodeMapPrivate* entities;    QDomNamedNodeMapPrivate* notations;    QString publicId;    QString systemId;    QString internalSubset;};class QDomDocumentFragmentPrivate : public QDomNodePrivate{public:    QDomDocumentFragmentPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent = 0);    QDomDocumentFragmentPrivate(QDomNodePrivate* n, bool deep);    // Reimplemented from QDomNodePrivate    virtual QDomNodePrivate* cloneNode(bool deep = true);    virtual bool isDocumentFragment() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::DocumentFragmentNode; }};class QDomCharacterDataPrivate : public QDomNodePrivate{public:    QDomCharacterDataPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& data);    QDomCharacterDataPrivate(QDomCharacterDataPrivate* n, bool deep);    uint dataLength() const;    QString substringData(unsigned long offset, unsigned long count) const;    void appendData(const QString& arg);    void insertData(unsigned long offset, const QString& arg);    void deleteData(unsigned long offset, unsigned long count);    void replaceData(unsigned long offset, unsigned long count, const QString& arg);    // Reimplemented from QDomNodePrivate    virtual bool isCharacterData() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::CharacterDataNode; }    QDomNodePrivate* cloneNode(bool deep = true);};class QDomTextPrivate : public QDomCharacterDataPrivate{public:    QDomTextPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& val);    QDomTextPrivate(QDomTextPrivate* n, bool deep);    QDomTextPrivate* splitText(int offset);    // Reimplemented from QDomNodePrivate    QDomNodePrivate* cloneNode(bool deep = true);    virtual bool isText() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::TextNode; }    virtual void save(QTextStream& s, int, int) const;};class QDomAttrPrivate : public QDomNodePrivate{public:    QDomAttrPrivate(QDomDocumentPrivate*, QDomNodePrivate*, const QString& name);    QDomAttrPrivate(QDomDocumentPrivate*, QDomNodePrivate*, const QString& nsURI, const QString& qName);    QDomAttrPrivate(QDomAttrPrivate* n, bool deep);    bool specified() const;    // Reimplemented from QDomNodePrivate    void setNodeValue(const QString& v);    QDomNodePrivate* cloneNode(bool deep = true);    virtual bool isAttr() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::AttributeNode; }    virtual void save(QTextStream& s, int, int) const;    // Variables    bool m_specified;};class QDomElementPrivate : public QDomNodePrivate{public:    QDomElementPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name);    QDomElementPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& nsURI, const QString& qName);    QDomElementPrivate(QDomElementPrivate* n, bool deep);    ~QDomElementPrivate();    QString attribute(const QString& name, const QString& defValue) const;    QString attributeNS(const QString& nsURI, const QString& localName, const QString& defValue) const;    void setAttribute(const QString& name, const QString& value);    void setAttributeNS(const QString& nsURI, const QString& qName, const QString& newValue);    void removeAttribute(const QString& name);    QDomAttrPrivate* attributeNode(const QString& name);    QDomAttrPrivate* attributeNodeNS(const QString& nsURI, const QString& localName);    QDomAttrPrivate* setAttributeNode(QDomAttrPrivate* newAttr);    QDomAttrPrivate* setAttributeNodeNS(QDomAttrPrivate* newAttr);    QDomAttrPrivate* removeAttributeNode(QDomAttrPrivate* oldAttr);    bool hasAttribute(const QString& name);    bool hasAttributeNS(const QString& nsURI, const QString& localName);    QString text();    // Reimplemented from QDomNodePrivate    QDomNamedNodeMapPrivate* attributes() { return m_attr; }    bool hasAttributes() { return (m_attr->length() > 0); }    virtual bool isElement() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::ElementNode; }    QDomNodePrivate* cloneNode(bool deep = true);    virtual void save(QTextStream& s, int, int) const;    // Variables    QDomNamedNodeMapPrivate* m_attr;};class QDomCommentPrivate : public QDomCharacterDataPrivate{public:    QDomCommentPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& val);    QDomCommentPrivate(QDomCommentPrivate* n, bool deep);    // Reimplemented from QDomNodePrivate    QDomNodePrivate* cloneNode(bool deep = true);    virtual bool isComment() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::CommentNode; }    virtual void save(QTextStream& s, int, int) const;};class QDomCDATASectionPrivate : public QDomTextPrivate{public:    QDomCDATASectionPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& val);    QDomCDATASectionPrivate(QDomCDATASectionPrivate* n, bool deep);    // Reimplemented from QDomNodePrivate    QDomNodePrivate* cloneNode(bool deep = true);    virtual bool isCDATASection() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::CDATASectionNode; }    virtual void save(QTextStream& s, int, int) const;};class QDomNotationPrivate : public QDomNodePrivate{public:    QDomNotationPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,                          const QString& pub, const QString& sys);    QDomNotationPrivate(QDomNotationPrivate* n, bool deep);    // Reimplemented from QDomNodePrivate    QDomNodePrivate* cloneNode(bool deep = true);    virtual bool isNotation() const { return true; }    QDomNode::NodeType nodeType() const { return QDomNode::NotationNode; }    virtual void save(QTextStream& s, int, int) const;

⌨️ 快捷键说明

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