From 08cb366c5ae9a3ad7666826e0c23b41db94ae40b Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Sat, 21 Oct 2006 11:40:44 +0000 Subject: [PATCH] There is still a huge memleak but I cannot find it... This commit removes 4 objects, reindents a bit and removes some kDebug svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=597681 --- libscience/elementparser.cpp | 13 +-- libscience/isotopeparser.cpp | 158 +++++++++++++++++----------------- libscience/xmlreadingtest.cpp | 2 +- 3 files changed, 89 insertions(+), 84 deletions(-) diff --git a/libscience/elementparser.cpp b/libscience/elementparser.cpp index 942c3bb..8a5d02a 100644 --- a/libscience/elementparser.cpp +++ b/libscience/elementparser.cpp @@ -52,12 +52,14 @@ class ElementSaxParser::Private inRPhrase( false ), inSPhrase( false ), inCountry( false ) - {} + {} - ~Private() - { - delete currentDataObject; - } + ~Private() + { + delete currentDataObject; + delete currentElement; + //qDeleteAll(elements); + } ChemicalDataObject *currentDataObject; ChemicalDataObject::BlueObeliskUnit currentUnit; @@ -223,7 +225,6 @@ bool ElementSaxParser::endElement( const QString &, const QString& localName, co } else if ( localName == "scalar" || localName == "label" || localName == "array" ) { - //kDebug() << "Check unit " << d->currentUnit << endl; d->currentDataObject->setUnit( d->currentUnit ); } return true; diff --git a/libscience/isotopeparser.cpp b/libscience/isotopeparser.cpp index 6dd34d6..8b393e9 100644 --- a/libscience/isotopeparser.cpp +++ b/libscience/isotopeparser.cpp @@ -46,6 +46,12 @@ public: { } + ~Private(){ + delete currentIsotope; + delete currentDataObject; + //qDeleteAll(isotopes); + } + ChemicalDataObject *currentDataObject; ChemicalDataObject::BlueObeliskUnit currentUnit; QVariant currentErrorValue; @@ -84,84 +90,82 @@ IsotopeParser::~IsotopeParser() bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs) { -//X kDebug() << "IsotopeParser::startElement(), localName " << localName << endl; - if (localName == "isotopeList") - { -//X kDebug() << "setting inElement true! ========================== NEW ELEMENT ========= " << endl; - d->inElement = true; - - //now save the symbol of the current element - for (int i = 0; i < attrs.length(); ++i) - { - if ( attrs.localName( i ) == "id" ) - d->currentElementSymbol = attrs.value( i ); + if (localName == "isotopeList") + { + d->inElement = true; -//X kDebug() << "Symbol of the current Element: " << attrs.value( i ) << endl; - } - } else if ( d->inElement && localName == "isotope") - { -//X kDebug() << "setting inIsotope true!" << endl; - d->currentIsotope = new Isotope(); - d->currentIsotope->addData( new ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) ); - d->inIsotope = true; - for (int i = 0; i < attrs.length(); ++i) - { - if ( attrs.localName( i ) == "number" ) - d->currentIsotope->setNucleons( attrs.value( i ).toInt() ); - } - } else if (d->inIsotope && localName == "scalar") - { - for (int i = 0; i < attrs.length(); ++i) - { - if ( attrs.localName( i ) == "errorValue" ) - { - d->currentErrorValue = QVariant( attrs.value( i ) ); - continue; - } - - if (attrs.value(i) == "bo:atomicNumber") - d->inAtomicNumber = true; - else if (attrs.value(i) == "bo:exactMass") - d->inExactMass = true; - else if (attrs.value(i) == "bo:halfLife"){ - for (int i = 0; i < attrs.length(); ++i) - { - if ( attrs.localName( i ) == "unit" ) - { - d->currentDataObject->setUnit( d->currentUnit ); - } - else - { - d->currentUnit = ChemicalDataObject::noUnit; - } - } - d->inHalfLife = true; - } - else if (attrs.value(i) == "bo:alphaDecay") - d->inAlphaDecay = true; - else if (attrs.value(i) == "bo:alphaDecayLikeliness") - d->inAlphaDecayLikeliness = true; - else if (attrs.value(i) == "bo:ecDecay") - d->inECDecay = true; - else if (attrs.value(i) == "bo:ecDecayLikeliness") - d->inECDecayLikeliness = true; - else if (attrs.value(i) == "bo:betaminusDecay") - d->inBetaminusDecay = true; - else if (attrs.value(i) == "bo:betaminusDecayLikeliness") - d->inBetaminusDecayLikeliness = true; - else if (attrs.value(i) == "bo:betaplusDecay") - d->inBetaplusDecay = true; - else if (attrs.value(i) == "bo:betaplusDecayLikeliness") - d->inBetaplusDecayLikeliness = true; - else if (attrs.value(i) == "bo:spin") - d->inSpin = true; - else if (attrs.value(i) == "bo:magneticMoment") - d->inMagMoment = true; - else if (attrs.value(i) == "bo:relativeAbundance") - d->inAbundance = true; - } - } - return true; + //now save the symbol of the current element + for (int i = 0; i < attrs.length(); ++i) + { + if ( attrs.localName( i ) == "id" ) + d->currentElementSymbol = attrs.value( i ); + + //X kDebug() << "Symbol of the current Element: " << attrs.value( i ) << endl; + } + } else if ( d->inElement && localName == "isotope") + { + //X kDebug() << "setting inIsotope true!" << endl; + d->currentIsotope = new Isotope(); + d->currentIsotope->addData( new ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) ); + d->inIsotope = true; + for (int i = 0; i < attrs.length(); ++i) + { + if ( attrs.localName( i ) == "number" ) + d->currentIsotope->setNucleons( attrs.value( i ).toInt() ); + } + } else if (d->inIsotope && localName == "scalar") + { + for (int i = 0; i < attrs.length(); ++i) + { + if ( attrs.localName( i ) == "errorValue" ) + { + d->currentErrorValue = QVariant( attrs.value( i ) ); + continue; + } + + if (attrs.value(i) == "bo:atomicNumber") + d->inAtomicNumber = true; + else if (attrs.value(i) == "bo:exactMass") + d->inExactMass = true; + else if (attrs.value(i) == "bo:halfLife"){ + for (int i = 0; i < attrs.length(); ++i) + { + if ( attrs.localName( i ) == "unit" ) + { + d->currentDataObject->setUnit( d->currentUnit ); + } + else + { + d->currentUnit = ChemicalDataObject::noUnit; + } + } + d->inHalfLife = true; + } + else if (attrs.value(i) == "bo:alphaDecay") + d->inAlphaDecay = true; + else if (attrs.value(i) == "bo:alphaDecayLikeliness") + d->inAlphaDecayLikeliness = true; + else if (attrs.value(i) == "bo:ecDecay") + d->inECDecay = true; + else if (attrs.value(i) == "bo:ecDecayLikeliness") + d->inECDecayLikeliness = true; + else if (attrs.value(i) == "bo:betaminusDecay") + d->inBetaminusDecay = true; + else if (attrs.value(i) == "bo:betaminusDecayLikeliness") + d->inBetaminusDecayLikeliness = true; + else if (attrs.value(i) == "bo:betaplusDecay") + d->inBetaplusDecay = true; + else if (attrs.value(i) == "bo:betaplusDecayLikeliness") + d->inBetaplusDecayLikeliness = true; + else if (attrs.value(i) == "bo:spin") + d->inSpin = true; + else if (attrs.value(i) == "bo:magneticMoment") + d->inMagMoment = true; + else if (attrs.value(i) == "bo:relativeAbundance") + d->inAbundance = true; + } + } + return true; } bool IsotopeParser::endElement( const QString&, const QString& localName, const QString& ) diff --git a/libscience/xmlreadingtest.cpp b/libscience/xmlreadingtest.cpp index 072c3c9..bd979f3 100644 --- a/libscience/xmlreadingtest.cpp +++ b/libscience/xmlreadingtest.cpp @@ -22,7 +22,6 @@ int main(int argc, char *argv[]) reader.parse(source); QList v = parser->getElements(); - delete parser; std::cout << "Found " << v.count() << " elements." << std::endl; @@ -44,6 +43,7 @@ int main(int argc, char *argv[]) } } + delete parser; qDeleteAll(v); return 0; -- 2.47.3