Changeset 561 for trunk/src/xml/dom/qdom.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/xml/dom/qdom.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtXml module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 57 57 #include <qvariant.h> 58 58 #include <qmap.h> 59 #include <qshareddata.h> 59 60 #include <qdebug.h> 60 61 #include <stdio.h> … … 125 126 { 126 127 public: 127 QDomImplementationPrivate() { ref = 1; } 128 inline QDomImplementationPrivate() {} 129 128 130 QDomImplementationPrivate* clone(); 129 131 QAtomicInt ref; … … 513 515 514 516 // Attributes 515 QDomDocumentTypePrivate* doctype() { return type ; };516 QDomImplementationPrivate* implementation() { return impl ; };517 QDomDocumentTypePrivate* doctype() { return type.data(); } 518 QDomImplementationPrivate* implementation() { return impl.data(); } 517 519 QDomElementPrivate* documentElement(); 518 520 … … 538 540 539 541 // Variables 540 Q DomImplementationPrivate*impl;541 Q DomDocumentTypePrivate*type;542 QExplicitlySharedDataPointer<QDomImplementationPrivate> impl; 543 QExplicitlySharedDataPointer<QDomDocumentTypePrivate> type; 542 544 543 545 void saveDocument(QTextStream& stream, const int indent, QDomNode::EncodingPolicy encUsed) const; … … 865 867 QDomImplementationPrivate* QDomImplementationPrivate::clone() 866 868 { 867 QDomImplementationPrivate* p = new QDomImplementationPrivate; 868 // We are not interested in this node 869 p->ref.deref(); 870 return p; 869 return new QDomImplementationPrivate; 871 870 } 872 871 … … 1846 1845 1847 1846 // We are no longer interested in the old node 1848 if (oldChild) 1849 oldChild->ref.deref(); 1847 oldChild->ref.deref(); 1850 1848 1851 1849 return oldChild; … … 1940 1938 \inmodule QtXml 1941 1939 \ingroup xml-tools 1942 \mainclass 1940 1943 1941 1944 1942 Many functions in the DOM return a QDomNode. … … 2695 2693 encoded in the given encoding, the result and behavior is undefined. 2696 2694 2697 \since 4.22695 \since 4.2 2698 2696 */ 2699 2697 void QDomNode::save(QTextStream& str, int indent, EncodingPolicy encodingPolicy) const … … 3061 3059 QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) 3062 3060 { 3063 Q DomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate(p);3061 QScopedPointer<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(p)); 3064 3062 m->readonly = readonly; 3065 3063 m->appendToParent = appendToParent; … … 3074 3072 // we are no longer interested in ownership 3075 3073 m->ref.deref(); 3076 return m ;3074 return m.take(); 3077 3075 } 3078 3076 … … 3500 3498 { 3501 3499 entities = new QDomNamedNodeMapPrivate(this); 3502 notations = new QDomNamedNodeMapPrivate(this); 3503 publicId.clear(); 3504 systemId.clear(); 3505 internalSubset.clear(); 3506 3507 entities->setAppendToParent(true); 3508 notations->setAppendToParent(true); 3500 QT_TRY { 3501 notations = new QDomNamedNodeMapPrivate(this); 3502 publicId.clear(); 3503 systemId.clear(); 3504 internalSubset.clear(); 3505 3506 entities->setAppendToParent(true); 3507 notations->setAppendToParent(true); 3508 } QT_CATCH(...) { 3509 delete entities; 3510 QT_RETHROW; 3511 } 3509 3512 } 3510 3513 … … 4356 4359 { 4357 4360 Q_ASSERT(impl->parent()); 4358 if (!impl || !impl->parent()->isElement())4361 if (!impl->parent()->isElement()) 4359 4362 return QDomElement(); 4360 4363 return QDomElement((QDomElementPrivate*)(impl->parent())); … … 4590 4593 nsDecl = QLatin1String(" xmlns:") + prefix; 4591 4594 } 4592 nsDecl += QLatin1String("=\"") + encodeText(namespaceURI, s) + QLatin1 String("\"");4595 nsDecl += QLatin1String("=\"") + encodeText(namespaceURI, s) + QLatin1Char('\"'); 4593 4596 } 4594 4597 s << '<' << qName << nsDecl; … … 4598 4601 /* Write out attributes. */ 4599 4602 if (!m_attr->map.isEmpty()) { 4600 s << ' ';4601 4603 QHash<QString, QDomNodePrivate *>::const_iterator it = m_attr->map.constBegin(); 4602 4604 for (; it != m_attr->map.constEnd(); ++it) { 4605 s << ' '; 4603 4606 if (it.value()->namespaceURI.isNull()) { 4604 4607 s << it.value()->name << "=\"" << encodeText(it.value()->value, s, true, true) << '\"'; … … 4623 4626 } 4624 4627 } 4625 s << ' ';4626 4628 } 4627 4629 } … … 6147 6149 QDomDocumentPrivate::QDomDocumentPrivate() 6148 6150 : QDomNodePrivate(0), 6151 impl(new QDomImplementationPrivate), 6149 6152 nodeListTime(1) 6150 6153 { 6151 impl = new QDomImplementationPrivate;6152 6154 type = new QDomDocumentTypePrivate(this, this); 6155 type->ref.deref(); 6153 6156 6154 6157 name = QLatin1String("#document"); … … 6157 6160 QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname) 6158 6161 : QDomNodePrivate(0), 6162 impl(new QDomImplementationPrivate), 6159 6163 nodeListTime(1) 6160 6164 { 6161 impl = new QDomImplementationPrivate;6162 6165 type = new QDomDocumentTypePrivate(this, this); 6166 type->ref.deref(); 6163 6167 type->name = aname; 6164 6168 … … 6168 6172 QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt) 6169 6173 : QDomNodePrivate(0), 6174 impl(new QDomImplementationPrivate), 6170 6175 nodeListTime(1) 6171 6176 { 6172 impl = new QDomImplementationPrivate;6173 6177 if (dt != 0) { 6174 6178 type = dt; 6175 type->ref.ref();6176 6179 } else { 6177 6180 type = new QDomDocumentTypePrivate(this, this); 6181 type->ref.deref(); 6178 6182 } 6179 6183 … … 6183 6187 QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep) 6184 6188 : QDomNodePrivate(n, deep), 6189 impl(n->impl->clone()), 6185 6190 nodeListTime(1) 6186 6191 { 6187 impl = n->impl->clone(); 6188 // Reference count is down to 0, so we set it to 1 here. 6189 impl->ref.ref(); 6190 type = (QDomDocumentTypePrivate*)n->type->cloneNode(); 6192 type = static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode()); 6191 6193 type->setParent(this); 6192 // Reference count is down to 0, so we set it to 1 here.6193 type->ref.ref();6194 6194 } 6195 6195 6196 6196 QDomDocumentPrivate::~QDomDocumentPrivate() 6197 6197 { 6198 if (!impl->ref.deref())6199 delete impl;6200 if (!type->ref.deref())6201 delete type;6202 6198 } 6203 6199 6204 6200 void QDomDocumentPrivate::clear() 6205 6201 { 6206 if (!impl->ref.deref()) 6207 delete impl; 6208 if (!type->ref.deref()) 6209 delete type; 6210 impl = 0; 6211 type = 0; 6202 impl.reset(); 6203 type.reset(); 6212 6204 QDomNodePrivate::clear(); 6213 6205 } … … 6232 6224 impl = new QDomImplementationPrivate; 6233 6225 type = new QDomDocumentTypePrivate(this, this); 6226 type->ref.deref(); 6234 6227 6235 6228 bool namespaceProcessing = reader->feature(QLatin1String("http://xml.org/sax/features/namespaces")) … … 6446 6439 const QDomNodePrivate* n = first; 6447 6440 6441 QTextCodec *codec = 0; 6442 6448 6443 if (n && n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml")) { 6449 6444 // we have an XML declaration … … 6452 6447 encoding.indexIn(data); 6453 6448 QString enc = encoding.cap(3); 6454 if (enc.isEmpty()) {6449 if (enc.isEmpty()) 6455 6450 enc = encoding.cap(5); 6456 } 6457 if (enc.isEmpty()) 6458 s.setCodec(QTextCodec::codecForName("UTF-8")); 6459 else 6460 s.setCodec(QTextCodec::codecForName(enc.toLatin1().data())); 6461 } else { 6462 s.setCodec(QTextCodec::codecForName("UTF-8")); 6451 if (!enc.isEmpty()) 6452 codec = QTextCodec::codecForName(enc.toLatin1().data()); 6463 6453 } 6454 if (!codec) 6455 codec = QTextCodec::codecForName("UTF-8"); 6456 if (codec) 6457 s.setCodec(codec); 6464 6458 #endif 6465 6459 bool doc = false; … … 6525 6519 6526 6520 \inmodule QtXml 6527 \mainclass 6521 6528 6522 \ingroup xml-tools 6529 6523 … … 7380 7374 7381 7375 QDomHandler::QDomHandler(QDomDocumentPrivate* adoc, bool namespaceProcessing) 7382 { 7383 doc = adoc; 7384 node = doc; 7385 cdata = false; 7386 nsProcessing = namespaceProcessing; 7376 : errorLine(0), errorColumn(0), doc(adoc), node(adoc), cdata(false), 7377 nsProcessing(namespaceProcessing), locator(0) 7378 { 7387 7379 } 7388 7380 … … 7416 7408 n = doc->createElement(qName); 7417 7409 } 7418 n->setLocation(locator->lineNumber(), locator->columnNumber()); 7410 7411 if (n) 7412 n->setLocation(locator->lineNumber(), locator->columnNumber()); 7419 7413 7420 7414 node->appendChild(n); … … 7436 7430 bool QDomHandler::endElement(const QString&, const QString&, const QString&) 7437 7431 { 7438 if ( node == doc)7432 if (!node || node == doc) 7439 7433 return false; 7440 7434 node = node->parent(); … … 7449 7443 return false; 7450 7444 7451 Q DomNodePrivate *n;7445 QScopedPointer<QDomNodePrivate> n; 7452 7446 if (cdata) { 7453 n = doc->createCDATASection(ch);7447 n.reset(doc->createCDATASection(ch)); 7454 7448 } else if (!entityName.isEmpty()) { 7455 Q DomEntityPrivate* e =new QDomEntityPrivate(doc, 0, entityName,7456 QString(), QString(), QString()) ;7449 QScopedPointer<QDomEntityPrivate> e(new QDomEntityPrivate(doc, 0, entityName, 7450 QString(), QString(), QString())); 7457 7451 e->value = ch; 7458 doc->doctype()->appendChild(e); 7459 n = doc->createEntityReference(entityName); 7452 doc->doctype()->appendChild(e.data()); 7453 e.take(); 7454 n.reset(doc->createEntityReference(entityName)); 7460 7455 } else { 7461 n = doc->createTextNode(ch);7456 n.reset(doc->createTextNode(ch)); 7462 7457 } 7463 7458 n->setLocation(locator->lineNumber(), locator->columnNumber()); 7464 node->appendChild(n); 7459 node->appendChild(n.data()); 7460 n.take(); 7465 7461 7466 7462 return true;
Note:
See TracChangeset
for help on using the changeset viewer.