]> Git trees. - libqmvoc.git/commitdiff
Porting to QList<ChemicalDataObject> (no pointer
authorCarsten Niehaus <cniehaus@gmx.de>
Sun, 29 Oct 2006 11:13:45 +0000 (11:13 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Sun, 29 Oct 2006 11:13:45 +0000 (11:13 +0000)
Porting to QSharedPointer and co, this shares implicitly.

Result:
 ==8109== LEAK SUMMARY:
 ==8109==    definitely lost: 980 bytes in 17 blocks.
 ==8109==    indirectly lost: 14,505 bytes in 245 blocks.
 ==8109==      possibly lost: 792 bytes in 6 bloc

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=599978

libscience/chemicaldataobject.cpp
libscience/chemicaldataobject.h
libscience/element.cpp
libscience/element.h
libscience/elementparser.cpp
libscience/isotope.cpp
libscience/isotope.h
libscience/isotopeparser.cpp
libscience/spectrumparser.cpp
libscience/spectrumparser.h
libscience/xmlreadingtest.cpp

index 1792ac81bfb8c4e063a625fa95678d598c219b10..efaf615a6934ecc6f91b744a8ca6fb08b04dcba9 100644 (file)
  *   Free Software Foundation, Inc.,                                       *
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.          *
  ***************************************************************************/
-#include "chemicaldataobject.h"
-
-int ChemicalDataObject::mycount = 0;
-
 #include <kdebug.h>
+#include "chemicaldataobject.h"
 
-class ChemicalDataObjectPrivate
+//########################
+ChemicalDataObjectPrivate::ChemicalDataObjectPrivate()
 {
-       public:
-               QVariant m_value;
-               QVariant m_errorValue;
-               ChemicalDataObject::BlueObelisk m_type;
-               ChemicalDataObject::BlueObeliskUnit m_unit;
+}
 
-    ~ChemicalDataObjectPrivate();
-};
+ChemicalDataObjectPrivate::ChemicalDataObjectPrivate(const ChemicalDataObjectPrivate &other)
+: QSharedData(other)
+{
+}
 
 ChemicalDataObjectPrivate::~ChemicalDataObjectPrivate()
 {
 }
+//##############
 
 ChemicalDataObject::ChemicalDataObject( const QVariant& v, BlueObelisk type, const QVariant& errorValue ) 
-: d(new ChemicalDataObjectPrivate()) 
 {
-       mycount++;
-       kDebug() << "CDO non-default contructor. There are now " << mycount
-                << " allocated CDOs" << endl;
-
-       d->m_value = v;
-       d->m_errorValue = errorValue;
-       d->m_type = type;
-       d->m_unit = ChemicalDataObject::noUnit;
+    d = new ChemicalDataObjectPrivate;
+    d->m_value = v;
+    d->m_errorValue = errorValue;
+    d->m_type = type;
+    d->m_unit = ChemicalDataObject::noUnit;
 }
 
 ChemicalDataObject::ChemicalDataObject() 
-: d(new ChemicalDataObjectPrivate())
 {
-       mycount++;
-       kDebug() << "CDO default contructor. There are now " << mycount
-                << " allocated CDOs" << endl;  d->m_value = QVariant();
-       d->m_errorValue = QVariant();
-       d->m_unit = ChemicalDataObject::noUnit;
+    d = new ChemicalDataObjectPrivate;
+    d->m_errorValue = QVariant();
+    d->m_unit = ChemicalDataObject::noUnit;
 }
 
 bool ChemicalDataObject::operator==( const int v ) const
@@ -93,14 +83,6 @@ bool ChemicalDataObject::operator==( const QString& v ) const
        return d->m_value.toString() == v;
 }
 
-ChemicalDataObject::~ChemicalDataObject()
-{
-       mycount--;
-       kDebug() << "CDO destructor. There are now " << mycount
-                << " allocated CDOs" << endl;  
-  delete d;
-}
-
 QString ChemicalDataObject::valueAsString() const
 {
        return d->m_value.toString();
index c7a904ebbb950ec2c41fbecdaee4287a5d3d51d8..adfe24822d0669c530ccb4790c27f43ea7d8ccb5 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.          *
  ***************************************************************************/
 
+#include <QSharedData>
+#include <QSharedDataPointer>
 #include <QVariant>
 #include <QString>
 
 #include <libkdeedu_science_export.h>
 
 class ChemicalDataObjectPrivate;
-
 /**
  * A ChemicalDataObject is an object which contains information about 
  * a chemical element. This can for example be a boiling point. The information
@@ -129,11 +130,6 @@ class EDUSCIENCE_EXPORT ChemicalDataObject
                 * @param v the value of the object
                 */
                void setErrorValue(  const QVariant& v );
-               
-               /**
-                * Destructor.
-                */
-               ~ChemicalDataObject();
 
                /**
                 * Every ChemicalDataObject contains one data. For example a
@@ -239,8 +235,19 @@ class EDUSCIENCE_EXPORT ChemicalDataObject
                static BlueObeliskUnit unit( const QString& unitname );
                
        private:
-               ChemicalDataObjectPrivate *d;
-               static int mycount;
+    QSharedDataPointer<ChemicalDataObjectPrivate> d;
 };
 
+class ChemicalDataObjectPrivate : public QSharedData
+{
+    public:
+        ChemicalDataObjectPrivate();
+        ChemicalDataObjectPrivate(const ChemicalDataObjectPrivate &other);
+        ~ChemicalDataObjectPrivate();
+
+        QVariant m_value;
+        QVariant m_errorValue;
+        ChemicalDataObject::BlueObelisk m_type;
+        ChemicalDataObject::BlueObeliskUnit m_unit;
+};
 #endif // CHEMICALDATAOBJECT_H
index dee144202f51286a7f0fd2bfb1e374fdc2f51aca..e790363059143755b3e6d5bd84f2aa0a1da4e0b5 100644 (file)
@@ -29,39 +29,35 @@ Element::Element()
 
 QVariant Element::dataAsVariant( ChemicalDataObject::BlueObelisk type ) const
 {
-       foreach( ChemicalDataObject* o, dataList ) {
-               if ( o->type() == type )
-                       return o->value();
+       foreach( ChemicalDataObject o, dataList ) {
+               if ( o.type() == type )
+                       return o.value();
        }
        return QVariant();
 }
 
 QString Element::dataAsString(ChemicalDataObject::BlueObelisk type) const
 {
-       foreach( ChemicalDataObject*o, dataList ) {
-               if ( o->type() == type )
-                       return o->valueAsString();
+       foreach( ChemicalDataObject o, dataList ) {
+               if ( o.type() == type )
+                       return o.valueAsString();
        }
        return QString();
 }
 
 Element::~Element()
 {
-    qDeleteAll(dataList);
-
     delete m_spectrum;
     m_spectrum = 0;
 }
 
-void Element::addData( ChemicalDataObject*o )
+void Element::addData( const ChemicalDataObject& o )
 {
-       // skip null pointers
-       if ( !o ) return;
        dataList.append( o );
 }
 
 void Element::addData( const QVariant& value, ChemicalDataObject::BlueObelisk type )
 {
-       ChemicalDataObject* tmp = new ChemicalDataObject( value, type );
+       ChemicalDataObject tmp( value, type );
        dataList.append( tmp );
 }
index 19e4f4c05d99228244403e66a8c4c945bd3c2df5..97b43ab7a3eba37c6f9564d13318107ba3e7c238 100644 (file)
@@ -49,7 +49,7 @@ class EDUSCIENCE_EXPORT Element
                 * Add the ChemicalDataObject @p o to this Element
                 * @param o the ChemicalDataObject to be added
                 */
-               void addData( ChemicalDataObject*o );
+               void addData( const ChemicalDataObject& o );
 
                /**
                 * Add a ChemicalDataObject with @p value of @p type to this
@@ -72,7 +72,7 @@ class EDUSCIENCE_EXPORT Element
                /**
                 * @return the data of the Element
                 */
-               QList<ChemicalDataObject*> data()const{
+               QList<ChemicalDataObject> data()const{
                        return dataList;
                }
 
@@ -88,7 +88,7 @@ class EDUSCIENCE_EXPORT Element
                /**
                 * this QList stores all information about an element
                 */
-               QList<ChemicalDataObject*> dataList;
+               QList<ChemicalDataObject> dataList;
 
     Spectrum *m_spectrum;
 };
index 8a5d02ab3c63942a89f472682b2b70307f633079..e18cf41806da1036eb7ec95e161a3ecee1f56b33 100644 (file)
@@ -21,8 +21,7 @@ class ElementSaxParser::Private
 {
     public:
         Private()
-            : currentDataObject(0),
-            currentUnit(ChemicalDataObject::noUnit),
+            : currentUnit(ChemicalDataObject::noUnit),
             currentElement(0),
             inElement(false),
             inName(false),
@@ -56,12 +55,11 @@ class ElementSaxParser::Private
 
         ~Private()
         {
-            delete currentDataObject;
             delete currentElement;
             //qDeleteAll(elements);
         }
 
-        ChemicalDataObject *currentDataObject;
+        ChemicalDataObject currentDataObject;
         ChemicalDataObject::BlueObeliskUnit currentUnit;
         Element *currentElement;
 
@@ -187,8 +185,8 @@ bool ElementSaxParser::startElement(const QString&, const QString &localName, co
                 for (int i = 0; i < attrs.length(); ++i) 
                 {
                     if (attrs.localName(i) == "value") {
-                        d->currentDataObject->setData( attrs.value(i) );
-                        d->currentDataObject->setType( ChemicalDataObject::symbol );
+                        d->currentDataObject.setData( attrs.value(i) );
+                        d->currentDataObject.setType( ChemicalDataObject::symbol );
                         
                         if ( d->currentElement )
                             d->currentElement->addData( d->currentDataObject );
@@ -199,8 +197,8 @@ bool ElementSaxParser::startElement(const QString&, const QString &localName, co
                 for (int i = 0; i < attrs.length(); ++i) 
                 {
                     if (attrs.localName(i) == "value") {
-                        d->currentDataObject->setData( attrs.value(i) );
-                        d->currentDataObject->setType( ChemicalDataObject::name );
+                        d->currentDataObject.setData( attrs.value(i) );
+                        d->currentDataObject.setType( ChemicalDataObject::name );
     
                         if ( d->currentElement )
                             d->currentElement->addData( d->currentDataObject );
@@ -220,19 +218,18 @@ bool ElementSaxParser::endElement( const QString &, const QString& localName, co
             d->elements.append(d->currentElement);
 
         d->currentElement = 0;
-        d->currentDataObject = 0;
         d->inElement = false;
     }
     else if ( localName == "scalar" || localName == "label" || localName == "array" )
     {
-        d->currentDataObject->setUnit( d->currentUnit );
+        d->currentDataObject.setUnit( d->currentUnit );
     }
     return true;
 }
 
 bool ElementSaxParser::characters(const QString &ch)
 {
-    d->currentDataObject = new ChemicalDataObject();
+    d->currentDataObject = ChemicalDataObject();
     ChemicalDataObject::BlueObelisk type;
     QVariant value;
 
@@ -364,8 +361,8 @@ bool ElementSaxParser::characters(const QString &ch)
     else//it is a non known value. Do not create a wrong object but return
         return true;
 
-    d->currentDataObject->setData( value );
-    d->currentDataObject->setType( type );
+    d->currentDataObject.setData( value );
+    d->currentDataObject.setType( type );
 
     if ( d->currentElement )
         d->currentElement->addData( d->currentDataObject );
index 85bb3cc5ef3aef6fddfde9f050045f8b4108bd6a..f813a0910877baa72e66516908bd11d330ea6ff1 100644 (file)
 #include <kdebug.h>
 
 Isotope::Isotope()
-: m_parentElementSymbol( 0 ), m_mass( 0 ), m_identifier( 0 ),
-       m_spin( 0 ), m_magmoment( 0 ), m_abundance( 0 ), m_halflife( 0 ), m_ecdecay( 0 ), m_eclikeliness( 0 ),  m_betaplusdecay( 0 ), m_betapluslikeliness( 0 ), m_betaminusdecay( 0 ), m_betaminuslikeliness( 0 ), m_alphadecay( 0 ), m_alphalikeliness( 0 )
 { 
 }
 
 Isotope::~Isotope()
 {
-               delete m_parentElementSymbol;
-               delete m_mass;
-               delete m_identifier;
-               delete m_spin;
-               delete m_magmoment;
-               delete m_abundance; 
-               delete m_halflife;
-               delete m_ecdecay;
-               delete m_betaplusdecay;
-               delete m_betaminusdecay; 
-               delete m_alphadecay;
-               delete m_eclikeliness;
-               delete m_betapluslikeliness;
-               delete m_betaminuslikeliness; 
-               delete m_alphalikeliness;
-}
-
-void Isotope::addData( ChemicalDataObject* o )
-{
-       if ( o->type() == ChemicalDataObject::exactMass )
+}
+
+void Isotope::addData( ChemicalDataObject o )
+{
+       if ( o.type() == ChemicalDataObject::exactMass )
                m_mass = o;
-       else if ( o->type() == ChemicalDataObject::atomicNumber )
+       else if ( o.type() == ChemicalDataObject::atomicNumber )
                m_identifier = o;
-       else if ( o->type() == ChemicalDataObject::symbol )
+       else if ( o.type() == ChemicalDataObject::symbol )
                m_parentElementSymbol = o;
-       else if ( o->type() == ChemicalDataObject::spin )
+       else if ( o.type() == ChemicalDataObject::spin )
                m_spin = o;
-       else if ( o->type() == ChemicalDataObject::magneticMoment )
+       else if ( o.type() == ChemicalDataObject::magneticMoment )
                m_magmoment = o;
-       else if ( o->type() == ChemicalDataObject::relativeAbundance )
+       else if ( o.type() == ChemicalDataObject::relativeAbundance )
                m_abundance = o;
-       else if ( o->type() == ChemicalDataObject::halfLife )
+       else if ( o.type() == ChemicalDataObject::halfLife )
                m_halflife = o;
-       else if ( o->type() == ChemicalDataObject::ecDecay )
+       else if ( o.type() == ChemicalDataObject::ecDecay )
                m_ecdecay = o;
-       else if ( o->type() == ChemicalDataObject::ecDecayLikeliness )
+       else if ( o.type() == ChemicalDataObject::ecDecayLikeliness )
                m_eclikeliness = o;
-       else if ( o->type() == ChemicalDataObject::betaplusDecay )
+       else if ( o.type() == ChemicalDataObject::betaplusDecay )
                m_betaplusdecay = o;
-       else if ( o->type() == ChemicalDataObject::betaplusDecayLikeliness )
+       else if ( o.type() == ChemicalDataObject::betaplusDecayLikeliness )
                m_betapluslikeliness = o;
-       else if (  o->type() == ChemicalDataObject::betaminusDecay )
+       else if (  o.type() == ChemicalDataObject::betaminusDecay )
                m_betaminusdecay = o;
-       else if (  o->type() == ChemicalDataObject::betaminusDecayLikeliness )
+       else if (  o.type() == ChemicalDataObject::betaminusDecayLikeliness )
                m_betaminuslikeliness = o;
-       else if ( o->type() == ChemicalDataObject::alphaDecay )
+       else if ( o.type() == ChemicalDataObject::alphaDecay )
                m_alphadecay = o;
-       else if ( o->type() == ChemicalDataObject::alphaDecayLikeliness )
+       else if ( o.type() == ChemicalDataObject::alphaDecayLikeliness )
                m_alphalikeliness = o;
        
 }
 
 double Isotope::mass() const
 {
-       return m_mass ? m_mass->value().toDouble() : -1.0;
+       //return m_mass ? m_mass.value().toDouble() : -1.0;
 }
 
 QString Isotope::errorMargin() const
 {
-       return m_mass ? m_mass->errorValue().toString() : QString();
+       //return m_mass ? m_mass.errorValue().toString() : QString();
 }
 
 int Isotope::parentElementNumber() const
 {
-       return m_identifier ? m_identifier->value().toInt() : -1;
+//     return m_identifier ? m_identifier.value().toInt() : -1;
 }
 
 QString Isotope::spin() const
 {
-       return m_spin ? m_spin->value().toString() : QString();
+       //return m_spin ? m_spin.value().toString() : QString();
 }
 
 QString Isotope::magmoment() const
 {
-       return m_magmoment ? m_magmoment->value().toString() : QString();
+       //return m_magmoment ? m_magmoment.value().toString() : QString();
 }
 
 QString Isotope::abundance() const
 {
-       return m_abundance ? m_abundance->value().toString() : QString();
+       //return m_abundance ? m_abundance.value().toString() : QString();
 }
 
 double Isotope::halflife() const
 {
-       return m_halflife ? m_halflife->value().toDouble() : -1.0;
+       //return m_halflife ? m_halflife.value().toDouble() : -1.0;
 }
 double Isotope::ecdecay() const
 {
-       return m_ecdecay ? m_ecdecay->value().toDouble() : -1.0;
+       //return m_ecdecay ? m_ecdecay.value().toDouble() : -1.0;
 }
 double Isotope::eclikeliness() const
 {
-       return m_eclikeliness ? m_eclikeliness->value().toDouble() : -1.0;
+       //return m_eclikeliness ? m_eclikeliness.value().toDouble() : -1.0;
 }
 double Isotope::betaplusdecay() const
 {
-       return m_betaplusdecay ? m_betaplusdecay->value().toDouble() : -1.0;
+       //return m_betaplusdecay ? m_betaplusdecay.value().toDouble() : -1.0;
 }
 double Isotope::betapluslikeliness() const
 {
-       return m_betapluslikeliness ? m_betapluslikeliness->value().toDouble() : -1.0;
+       //return m_betapluslikeliness ? m_betapluslikeliness.value().toDouble() : -1.0;
 }
 double Isotope::betaminusdecay() const
 {
-       return m_betaminusdecay ? m_betaminusdecay->value().toDouble() : -1.0;
+       //return m_betaminusdecay ? m_betaminusdecay.value().toDouble() : -1.0;
 }
 double Isotope::betaminuslikeliness() const
 {
-       return m_betaminuslikeliness ? m_betaminuslikeliness->value().toDouble() : -1.0;
+       //return m_betaminuslikeliness ? m_betaminuslikeliness.value().toDouble() : -1.0;
 }
 double Isotope::alphadecay() const
 {
-       return m_alphadecay ? m_alphadecay->value().toDouble() : -1.0;
+       //return m_alphadecay ? m_alphadecay.value().toDouble() : -1.0;
 }
 double Isotope::alphalikeliness() const
 {
-       return m_alphalikeliness ? m_alphalikeliness->value().toDouble() : -1.0;
+       //return m_alphalikeliness ? m_alphalikeliness.value().toDouble() : -1.0;
 }
 QString Isotope::parentElementSymbol() const
 {
-       return m_parentElementSymbol ? m_parentElementSymbol->value().toString() : QString();
+       //return m_parentElementSymbol ? m_parentElementSymbol.value().toString() : QString();
 }
 
 void Isotope::setNucleons( int number )
 {
-       m_numberOfNucleons = number;
+       //m_numberOfNucleons = number;
 }
 
 int Isotope::nucleons() const
 {
-       return m_numberOfNucleons;
+       //return m_numberOfNucleons;
 }
 
 Isotope::Nucleons Isotope::nucleonsAfterDecay( Decay kind )
 {
        Isotope::Nucleons n;
-       int protons = m_identifier->value().toInt();
+       int protons = m_identifier.value().toInt();
        int neutrons = m_numberOfNucleons - protons;
        n.protons = protons;
        n.neutrons = neutrons;
index 8b12afaf397510cbaf0197283447536f29d2ba32..9a51bee2d3810f9d72fecdc6f6d649ad9212e795 100644 (file)
@@ -20,8 +20,7 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.          *
  ***************************************************************************/
 
-class ChemicalDataObject;
-
+#include "chemicaldataobject.h"
 #include <libkdeedu_science_export.h>
 
 #include <QString>
@@ -94,7 +93,7 @@ class EDUSCIENCE_EXPORT Isotope
                /**
                 * add the ChemicalDataObject @p o
                 */
-               void addData( ChemicalDataObject* o );
+               void addData( ChemicalDataObject o );
 
                void setNucleons( int number );
                
@@ -164,53 +163,53 @@ class EDUSCIENCE_EXPORT Isotope
                /**
                 * the symbol of the element the isotope belongs to
                 */
-               ChemicalDataObject* m_parentElementSymbol;
+               ChemicalDataObject m_parentElementSymbol;
                
                /**
                 * stores the information about the mass of the Isotope
                 */
-               ChemicalDataObject* m_mass;
+               ChemicalDataObject m_mass;
 
                /**
                 * stores the atomicNumber of the Isotope
                 */
-               ChemicalDataObject* m_identifier;
+               ChemicalDataObject m_identifier;
                
                /**
                 * stores the spin of the Isotope
                 */
-               ChemicalDataObject* m_spin;
+               ChemicalDataObject m_spin;
                
                /**
                 * stores the magneticMoment of the Isotope
                 */
-               ChemicalDataObject* m_magmoment;
+               ChemicalDataObject m_magmoment;
                
                /**
                 * stores the relative abundance of the Isotope
                 */
-               ChemicalDataObject* m_abundance; 
+               ChemicalDataObject m_abundance; 
 
                /**
                 * stores the halfLife of the Isotope
                 */
-               ChemicalDataObject* m_halflife;
+               ChemicalDataObject m_halflife;
                
                /**
                 * stores decay energy of the isotope
                 */
-               ChemicalDataObject* m_ecdecay;
-               ChemicalDataObject* m_betaplusdecay;
-               ChemicalDataObject* m_betaminusdecay; 
-               ChemicalDataObject* m_alphadecay;
+               ChemicalDataObject m_ecdecay;
+               ChemicalDataObject m_betaplusdecay;
+               ChemicalDataObject m_betaminusdecay; 
+               ChemicalDataObject m_alphadecay;
 
                /**
                 * stores the likeliness of a decay of the isotope
                 */
-               ChemicalDataObject* m_eclikeliness;
-               ChemicalDataObject* m_betapluslikeliness;
-               ChemicalDataObject* m_betaminuslikeliness; 
-               ChemicalDataObject* m_alphalikeliness;
+               ChemicalDataObject m_eclikeliness;
+               ChemicalDataObject m_betapluslikeliness;
+               ChemicalDataObject m_betaminuslikeliness; 
+               ChemicalDataObject m_alphalikeliness;
        
                int m_numberOfNucleons;
 };
index 8b393e9a2db8b74af19ad3c94ffcb5595dca825f..38bf616490c674a00d077fd5414020c64c334c21 100644 (file)
@@ -22,8 +22,7 @@ class IsotopeParser::Private
 {
 public:
        Private()
-       : currentDataObject(0),
-       currentUnit(ChemicalDataObject::noUnit),
+       :       currentUnit(ChemicalDataObject::noUnit),
        currentErrorValue(QVariant()),
        currentElementSymbol(QString()),
        currentIsotope(0),
@@ -48,11 +47,10 @@ public:
 
   ~Private(){
     delete currentIsotope;
-    delete currentDataObject;
     //qDeleteAll(isotopes);
   }
 
-       ChemicalDataObject *currentDataObject;
+       ChemicalDataObject currentDataObject;
        ChemicalDataObject::BlueObeliskUnit currentUnit;
        QVariant currentErrorValue;
        QString currentElementSymbol;
@@ -106,7 +104,7 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const
     {
         //X            kDebug() << "setting inIsotope true!" << endl;
         d->currentIsotope = new Isotope();
-        d->currentIsotope->addData( new ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) );
+        d->currentIsotope->addData( ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) );
         d->inIsotope = true;
         for (int i = 0; i < attrs.length(); ++i) 
         {
@@ -132,7 +130,7 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const
                 {
                     if ( attrs.localName( i ) == "unit" )
                     {
-                        d->currentDataObject->setUnit( d->currentUnit );
+                        d->currentDataObject.setUnit( d->currentUnit );
                     }
                     else
                     {
@@ -174,7 +172,6 @@ bool IsotopeParser::endElement( const QString&, const QString& localName, const
        {
                d->isotopes.append(d->currentIsotope);
                
-               d->currentDataObject = 0;
                d->currentIsotope = 0;
                d->inIsotope = false;
        }
@@ -189,7 +186,7 @@ bool IsotopeParser::endElement( const QString&, const QString& localName, const
 
 bool IsotopeParser::characters(const QString &ch)
 {
-       d->currentDataObject = new ChemicalDataObject();
+       d->currentDataObject = ChemicalDataObject();
        ChemicalDataObject::BlueObelisk type;
        QVariant value;
 
@@ -269,16 +266,15 @@ bool IsotopeParser::characters(const QString &ch)
 
        if ( type == ChemicalDataObject::exactMass )
        {
-               d->currentDataObject->setErrorValue( d->currentErrorValue );
+               d->currentDataObject.setErrorValue( d->currentErrorValue );
        }
 
-       d->currentDataObject->setData( value );
-       d->currentDataObject->setType( type );
+       d->currentDataObject.setData( value );
+       d->currentDataObject.setType( type );
 
        if ( d->currentIsotope )
        {
                d->currentIsotope->addData( d->currentDataObject );
-               d->currentDataObject = 0;
        }
 
        return true;
index 2dd5df00631b1f73271681fd42aa471305dba601..ca941bedaade968845e895efd63eaf12acf4806c 100644 (file)
@@ -63,13 +63,12 @@ bool SpectrumParser::endElement( const QString&, const QString& localName, const
 //X            isotopes_.append(currentSpectrum_);
 //X            
 //X            currentSpectrum_ = 0;
-//X            currentDataObject_ = 0;
 //X            inSpectrum_ = false;
        }
        else if ( localName == "scalar" )
        {
-//X            if ( currentDataObject_->type() == ChemicalDataObject::exactMass ){
-//X                    currentDataObject_->setErrorValue( currentErrorValue_ );
+//X            if ( currentDataObject_.type() == ChemicalDataObject::exactMass ){
+//X                    currentDataObject_.setErrorValue( currentErrorValue_ );
 //X            }
        }
 
@@ -78,7 +77,7 @@ bool SpectrumParser::endElement( const QString&, const QString& localName, const
 
 bool SpectrumParser::characters(const QString &ch)
 {
-       currentDataObject_ = new ChemicalDataObject();
+       ChemicalDataObject currentDataObject_;
        ChemicalDataObject::BlueObelisk type;
        QVariant value;
 
@@ -95,8 +94,8 @@ bool SpectrumParser::characters(const QString &ch)
        else//it is a non known value. Do not create a wrong object but return
                return true;
 
-       currentDataObject_->setData( value );
-       currentDataObject_->setType( type );
+       currentDataObject_.setData( value );
+       currentDataObject_.setType( type );
 
 //X    if ( currentSpectrum_ )
 //X            currentSpectrum_->addData( currentDataObject_ );
index b3797d36dc879f07730d20ac7afd194b360b8c66..ca8515c9a34501c6b59f37c24b29c7b0d7aec03f 100644 (file)
@@ -43,7 +43,7 @@ class EDUSCIENCE_EXPORT SpectrumParser : public QXmlDefaultHandler
                QList<Spectrum*> getSpectrums();
 
        private:
-               ChemicalDataObject *currentDataObject_;
+               ChemicalDataObject currentDataObject_;
                ChemicalDataObject::BlueObeliskUnit currentUnit_;
 
                QVariant currentErrorValue_;
index bd979f3061463c2f8cbf6aa7459148142e19a3d2..4d0539282e3623b72247db1dffe57f10f9acb068 100644 (file)
@@ -28,17 +28,14 @@ int main(int argc, char *argv[])
     foreach( Element* e, v ){
         if ( e )
         {
-            QList<ChemicalDataObject*> list = e->data();
+            QList<ChemicalDataObject> list = e->data();
 
             //Test: give me all data available
-            foreach( ChemicalDataObject*o, list ){
-                if ( o )
-                {
-                    QString unit = o->unitAsString();
+            foreach( ChemicalDataObject o, list ){
+                    QString unit = o.unitAsString();
                     if ( unit == "bo:noUnit" )
                         unit = "";
-                    kDebug() << "Name: " << o->dictRef() << " " << o->valueAsString()  <<" "  << unit << endl;
-                }
+                    kDebug() << "Name: " << o.dictRef() << " " << o.valueAsString()  <<" "  << unit << endl;
             }
         }
     }