diff options
| author | Linus Jahn <lnj@kaidan.im> | 2021-04-02 16:35:33 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2021-04-06 15:47:48 +0200 |
| commit | 06248e6ec8eab90e55b2d2155aa88645e5dec57d (patch) | |
| tree | a7aeacba8628b908c3efb943b46241f9b37d5772 /src/base/QXmppElement.cpp | |
| parent | fae960ca44ae481c90ae0078604187030dc2396f (diff) | |
Clean up QXmppElement
Diffstat (limited to 'src/base/QXmppElement.cpp')
| -rw-r--r-- | src/base/QXmppElement.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/base/QXmppElement.cpp b/src/base/QXmppElement.cpp index 0aadfb2d..46d13a35 100644 --- a/src/base/QXmppElement.cpp +++ b/src/base/QXmppElement.cpp @@ -31,13 +31,13 @@ class QXmppElementPrivate { public: - QXmppElementPrivate(); + QXmppElementPrivate() = default; QXmppElementPrivate(const QDomElement &element); ~QXmppElementPrivate(); - QAtomicInt counter; + QAtomicInt counter = 1; - QXmppElementPrivate *parent; + QXmppElementPrivate *parent = nullptr; QMap<QString, QString> attributes; QList<QXmppElementPrivate *> children; QString name; @@ -46,13 +46,7 @@ public: QByteArray serializedSource; }; -QXmppElementPrivate::QXmppElementPrivate() - : counter(1), parent(nullptr) -{ -} - QXmppElementPrivate::QXmppElementPrivate(const QDomElement &element) - : counter(1), parent(nullptr) { if (element.isNull()) return; @@ -86,9 +80,11 @@ QXmppElementPrivate::QXmppElementPrivate(const QDomElement &element) QXmppElementPrivate::~QXmppElementPrivate() { - for (auto *child : children) - if (!child->counter.deref()) + for (auto *child : std::as_const(children)) { + if (!child->counter.deref()) { delete child; + } + } } /// @@ -139,8 +135,8 @@ QXmppElement::~QXmppElement() /// QXmppElement &QXmppElement::operator=(const QXmppElement &other) { - if (this != &other) // self-assignment check - { + // self-assignment check + if (this != &other) { other.d->counter.ref(); if (!d->counter.deref()) delete d; @@ -215,9 +211,11 @@ void QXmppElement::appendChild(const QXmppElement &child) /// QXmppElement QXmppElement::firstChildElement(const QString &name) const { - for (auto *child_d : d->children) - if (name.isEmpty() || child_d->name == name) + for (auto *child_d : std::as_const(d->children)) { + if (name.isEmpty() || child_d->name == name) { return QXmppElement(child_d); + } + } return QXmppElement(); } @@ -300,12 +298,15 @@ void QXmppElement::toXml(QXmlStreamWriter *writer) const writer->writeStartElement(d->name); if (d->attributes.contains("xmlns")) writer->writeDefaultNamespace(d->attributes.value("xmlns")); - for (const auto &attr : d->attributes.keys()) - if (attr != "xmlns") - helperToXmlAddAttribute(writer, attr, d->attributes.value(attr)); + std::for_each(d->attributes.keyBegin(), d->attributes.keyEnd(), [this, writer](const QString &key) { + if (key != "xmlns") { + helperToXmlAddAttribute(writer, key, d->attributes.value(key)); + } + }); if (!d->value.isEmpty()) writer->writeCharacters(d->value); - for (auto *childPrivate : d->children) + for (auto *childPrivate : std::as_const(d->children)) { QXmppElement(childPrivate).toXml(writer); + } writer->writeEndElement(); } |
