]> Git trees. - libqmvoc.git/commitdiff
There is still a huge memleak but I cannot find it... This commit removes 4 objects...
authorCarsten Niehaus <cniehaus@gmx.de>
Sat, 21 Oct 2006 11:40:44 +0000 (11:40 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Sat, 21 Oct 2006 11:40:44 +0000 (11:40 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=597681

libscience/elementparser.cpp
libscience/isotopeparser.cpp
libscience/xmlreadingtest.cpp

index 942c3bb7f2de35719e10738ab8e17715b353417d..8a5d02ab3c63942a89f472682b2b70307f633079 100644 (file)
@@ -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;
index 6dd34d6288a21a015cfa1717c41e7798f0d40a3d..8b393e9a2db8b74af19ad3c94ffcb5595dca825f 100644 (file)
@@ -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& )
index 072c3c96f53d9efb2d5e4892b2ff6091448d5123..bd979f3061463c2f8cbf6aa7459148142e19a3d2 100644 (file)
@@ -22,7 +22,6 @@ int main(int argc, char *argv[])
     reader.parse(source);
 
     QList<Element*> 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;