void Element::addData( ChemicalDataObject*o )
{
+ // skip null pointers
+ if ( !o ) return;
dataList.append( o );
}
* *
***************************************************************************/
#include "elementparser.h"
-#include "element.h"
-#include <qdom.h>
-#include <QList>
-#include <QFile>
-#include <QStringList>
+#include "chemicaldataobject.h"
+#include "element.h"
#include <kdebug.h>
+class ElementSaxParser::Private
+{
+public:
+ Private()
+ : currentDataObject(0),
+ currentUnit(ChemicalDataObject::noUnit),
+ currentElement(0),
+ inElement(false),
+ inName(false),
+ inMass(false),
+ inExactMass(false),
+ inAtomicNumber(false),
+ inSymbol(false),
+ inIonization(false),
+ inElectronAffinity(false),
+ inElectronegativityPauling(false),
+ inRadiusCovalent(false),
+ inRadiusVDW(false),
+ inBoilingPoint(false),
+ inMeltingPoint(false),
+ inPeriodTableBlock(false),
+ inNameOrigin(false),
+ inDiscoveryDate(false),
+ inDiscoverers(false),
+ inPeriod(false)
+ {
+ }
+
+ ChemicalDataObject *currentDataObject;
+ ChemicalDataObject::BlueObeliskUnit currentUnit;
+ Element *currentElement;
+
+ QList<Element*> elements;
+
+ bool inElement;
+ bool inName;
+ bool inMass;
+ bool inExactMass;
+ bool inAtomicNumber;
+ bool inSymbol;
+ bool inIonization;
+ bool inElectronAffinity;
+ bool inElectronegativityPauling;
+ bool inRadiusCovalent;
+ bool inRadiusVDW;
+ bool inBoilingPoint;
+ bool inMeltingPoint;
+ bool inPeriodTableBlock;
+ bool inNameOrigin;
+ bool inDiscoveryDate;
+ bool inDiscoverers;
+ bool inPeriod;
+};
+
ElementSaxParser::ElementSaxParser()
- : QXmlDefaultHandler(),
- currentDataObject_(0),
- currentUnit_(ChemicalDataObject::noUnit),
- currentElement_(0),
- inElement_(false),
- inName_(false),
- inMass_(false),
- inExactMass_(false),
- inAtomicNumber_(false),
- inSymbol_(false),
- inIonization_(false),
- inElectronAffinity_(false),
- inElectronegativityPauling_(false),
- inRadiusCovalent_(false),
- inRadiusVDW_(false),
- inBoilingPoint_(false),
- inMeltingPoint_(false),
- inPeriodTableBlock_(false),
- inNameOrigin_(false),
- inDiscoveryDate_(false),
- inDiscoverers_(false),
- inPeriod_(false)
+ : QXmlDefaultHandler(), d( new Private )
+{
+}
+
+ElementSaxParser::~ElementSaxParser()
{
+ delete d;
}
bool ElementSaxParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs)
{
if (localName == "elementType")
{
- currentElement_ = new Element();
- inElement_ = true;
- } else if (inElement_ && localName == "scalar")
+ d->currentElement = new Element();
+ d->inElement = true;
+ } else if (d->inElement && localName == "scalar")
{
for (int i = 0; i < attrs.length(); ++i)
{
if ( attrs.localName( i ) == "unit" )
{
- currentUnit_ = ChemicalDataObject::unit( attrs.value( i ) );
+ d->currentUnit = ChemicalDataObject::unit( attrs.value( i ) );
continue;
}
if (attrs.value(i) == "bo:atomicNumber")
- inAtomicNumber_ = true;
+ d->inAtomicNumber = true;
else if (attrs.value(i) == "bo:symbol")
- inSymbol_ = true;
+ d->inSymbol = true;
else if (attrs.value(i) == "bo:name")
- inName_ = true;
+ d->inName = true;
else if (attrs.value(i) == "bo:mass")
- inMass_ = true;
+ d->inMass = true;
else if (attrs.value(i) == "bo:exactMass")
- inExactMass_ = true;
+ d->inExactMass = true;
else if (attrs.value(i) == "bo:ionization")
- inIonization_ = true;
+ d->inIonization = true;
else if (attrs.value(i) == "bo:electronAffinity")
- inElectronAffinity_ = true;
+ d->inElectronAffinity = true;
else if (attrs.value(i) == "bo:electronegativityPauling")
- inElectronegativityPauling_ = true;
+ d->inElectronegativityPauling = true;
else if (attrs.value(i) == "bo:radiusCovalent")
- inRadiusCovalent_ = true;
+ d->inRadiusCovalent = true;
else if (attrs.value(i) == "bo:radiusVDW")
- inRadiusVDW_ = true;
+ d->inRadiusVDW = true;
else if (attrs.value(i) == "bo:meltingpoint")
- inMeltingPoint_ = true;
+ d->inMeltingPoint = true;
else if (attrs.value(i) == "bo:boilingpoint")
- inBoilingPoint_ = true;
+ d->inBoilingPoint = true;
else if (attrs.value(i) == "bo:periodTableBlock")
- inPeriodTableBlock_ = true;
+ d->inPeriodTableBlock = true;
else if (attrs.value(i) == "bo:nameOrigin")
- inNameOrigin_ = true;
+ d->inNameOrigin = true;
else if (attrs.value(i) == "bo:discoveryDate")
- inDiscoveryDate_ = true;
+ d->inDiscoveryDate = true;
else if (attrs.value(i) == "bo:discoverers")
- inDiscoverers_ = true;
+ d->inDiscoverers = true;
else if (attrs.value(i) == "bo:period")
- inPeriod_ = true;
+ d->inPeriod = true;
}
}
return true;
{
if ( localName == "elementType" )
{
- if ( currentElement_->dataAsString( ChemicalDataObject::symbol ) != "Xx" )
- elements_.append(currentElement_);
+ if ( d->currentElement->dataAsString( ChemicalDataObject::symbol ) != "Xx" )
+ d->elements.append(d->currentElement);
- currentElement_ = 0;
- currentDataObject_ = 0;
- inElement_ = false;
+ d->currentElement = 0;
+ d->currentDataObject = 0;
+ d->inElement = false;
}
else if ( localName == "scalar" )
{
- if ( currentUnit_ != ChemicalDataObject::noUnit )
- currentDataObject_->setUnit( currentUnit_ );
+ if ( d->currentUnit != ChemicalDataObject::noUnit )
+ d->currentDataObject->setUnit( d->currentUnit );
- currentUnit_ = ChemicalDataObject::noUnit;
+ d->currentUnit = ChemicalDataObject::noUnit;
}
return true;
}
bool ElementSaxParser::characters(const QString &ch)
{
- currentDataObject_ = new ChemicalDataObject();
+ d->currentDataObject = new ChemicalDataObject();
ChemicalDataObject::BlueObelisk type;
QVariant value;
- if (inName_) {
+ if (d->inName) {
value = ch;
type = ChemicalDataObject::name;
- inName_ = false;
+ d->inName = false;
}
- else if ( inMass_ ){
+ else if (d->inMass){
value = ch.toDouble();
type = ChemicalDataObject::mass;
- inMass_ = false;
+ d->inMass = false;
}
- else if ( inExactMass_ ){
+ else if (d->inExactMass){
value = ch.toDouble();
type = ChemicalDataObject::exactMass;
- inExactMass_ = false;
+ d->inExactMass = false;
}
- else if (inSymbol_) {
+ else if (d->inSymbol) {
value = ch;
type = ChemicalDataObject::symbol;
- inSymbol_ = false;
+ d->inSymbol = false;
}
- else if (inAtomicNumber_) {
+ else if (d->inAtomicNumber) {
value = ch.toInt();
type = ChemicalDataObject::atomicNumber;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inIonization_) {
+ else if (d->inIonization) {
value = ch.toDouble();;
type = ChemicalDataObject::ionization;
- inIonization_ = false;
+ d->inIonization = false;
}
- else if (inElectronAffinity_) {
+ else if (d->inElectronAffinity) {
value = ch.toDouble();
type = ChemicalDataObject::electronAffinity;
- inElectronAffinity_ = false;
+ d->inElectronAffinity = false;
}
- else if (inElectronegativityPauling_) {
+ else if (d->inElectronegativityPauling) {
value = ch.toDouble();
type = ChemicalDataObject::electronegativityPauling;
- inElectronegativityPauling_ = false;
+ d->inElectronegativityPauling = false;
}
- else if (inRadiusCovalent_) {
+ else if (d->inRadiusCovalent) {
value = ch.toDouble();
type = ChemicalDataObject::radiusCovalent;
- inRadiusCovalent_ = false;
+ d->inRadiusCovalent = false;
}
- else if (inRadiusVDW_) {
+ else if (d->inRadiusVDW) {
value = ch.toDouble();
type = ChemicalDataObject::radiusVDW;
- inRadiusVDW_ = false;
+ d->inRadiusVDW = false;
}
- else if (inMeltingPoint_) {
+ else if (d->inMeltingPoint) {
value = ch.toDouble();
type = ChemicalDataObject::meltingpoint;
- inMeltingPoint_ = false;
+ d->inMeltingPoint = false;
}
- else if (inBoilingPoint_) {
+ else if (d->inBoilingPoint) {
value = ch.toDouble();
type = ChemicalDataObject::boilingpoint;
- inBoilingPoint_ = false;
+ d->inBoilingPoint = false;
}
- else if (inPeriodTableBlock_) {
+ else if (d->inPeriodTableBlock) {
value = ch;
type = ChemicalDataObject::periodTableBlock;
- inPeriodTableBlock_ = false;
+ d->inPeriodTableBlock = false;
}
- else if (inNameOrigin_) {
+ else if (d->inNameOrigin) {
value = ch;
type = ChemicalDataObject::nameOrigin;
- inNameOrigin_ = false;
+ d->inNameOrigin = false;
}
- else if (inDiscoveryDate_) {
+ else if (d->inDiscoveryDate) {
value = ch.toInt();
type = ChemicalDataObject::date;
- inDiscoveryDate_ = false;
+ d->inDiscoveryDate = false;
}
- else if (inDiscoverers_) {
+ else if (d->inDiscoverers) {
value = ch;
type = ChemicalDataObject::discoverers;
- inDiscoverers_ = false;
+ d->inDiscoverers = false;
}
- else if (inPeriod_) {
+ else if (d->inPeriod) {
value = ch.toInt();
type = ChemicalDataObject::period;
- inPeriod_ = false;
+ d->inPeriod = false;
}
else//it is a non known value. Do not create a wrong object but return
return true;
- currentDataObject_->setData( value );
- currentDataObject_->setType( type );
+ d->currentDataObject->setData( value );
+ d->currentDataObject->setType( type );
- if ( currentElement_ )
- currentElement_->addData( currentDataObject_ );
+ if ( d->currentElement )
+ d->currentElement->addData( d->currentDataObject );
return true;
}
QList<Element*> ElementSaxParser::getElements()
{
- return elements_;
+ return d->elements;
}
#include <qxml.h>
-#include "chemicaldataobject.h"
-
class Element;
-
/**
* @author Carsten Niehaus <cniehaus@kde.org>
*/
* Constructor
*/
ElementSaxParser();
+ ~ElementSaxParser();
bool startElement( const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs );
bool endElement( const QString& namespaceURI, const QString &localName, const QString& qName );
QList<Element*> getElements();
private:
- ChemicalDataObject *currentDataObject_;
- ChemicalDataObject::BlueObeliskUnit currentUnit_;
-
- Element *currentElement_;
- QList<Element*> elements_;
- bool inElement_;
- bool inName_,
- inMass_,
- inExactMass_,
- inAtomicNumber_,
- inSymbol_,
- inIonization_,
- inElectronAffinity_,
- inElectronegativityPauling_,
- inRadiusCovalent_,
- inRadiusVDW_,
- inBoilingPoint_,
- inMeltingPoint_,
- inPeriodTableBlock_,
- inNameOrigin_,
- inDiscoveryDate_,
- inDiscoverers_,
- inPeriod_;
+ class Private;
+ Private *d;
};
#endif // ELEMENTPARSER_H
* *
***************************************************************************/
#include "isotopeparser.h"
-#include "isotope.h"
-#include <qdom.h>
-#include <QList>
-#include <QFile>
-#include <QStringList>
+#include "chemicaldataobject.h"
+#include "isotope.h"
#include <kdebug.h>
+class IsotopeParser::Private
+{
+public:
+ Private()
+ : currentDataObject(0),
+ currentUnit(ChemicalDataObject::noUnit),
+ currentErrorValue(QVariant()),
+ currentElementSymbol(QString()),
+ currentIsotope(0),
+ inIsotope(false),
+ inAtomicNumber(false),
+ inExactMass(false),
+ inAlphaPercentage(false),
+ inAlphaDecay(false),
+ inBetaplusPercentage(false),
+ inBetaplusDecay(false),
+ inBetaminusPercentage(false),
+ inBetaminusDecay(false),
+ inECPercentage(false),
+ inECDecay(false),
+ inAbundance(false)
+ {
+ }
+
+ ChemicalDataObject *currentDataObject;
+ ChemicalDataObject::BlueObeliskUnit currentUnit;
+ QVariant currentErrorValue;
+ QString currentElementSymbol;
+ Isotope* currentIsotope;
+
+ QList<Isotope*> isotopes;
+
+ bool inIsotope;
+ bool inAtomicNumber;
+ bool inExactMass;
+ bool inAlphaPercentage;
+ bool inAlphaDecay;
+ bool inBetaplusPercentage;
+ bool inBetaplusDecay;
+ bool inBetaminusPercentage;
+ bool inBetaminusDecay;
+ bool inECPercentage;
+ bool inECDecay;
+ bool inAbundance;
+};
+
IsotopeParser::IsotopeParser()
- : QXmlDefaultHandler(),
- currentIsotope_(0),
- inAtomicNumber_(false),
- inAlphaPercentage_(false),
- inAlphaDecay_(false),
- inBetaplusPercentage_(false),
- inBetaplusDecay_(false),
- inBetaminusPercentage_(false),
- inBetaminusDecay_(false),
- inECPercentage_(false),
- inECDecay_(false),
- inExactMass_(false),
- inAbundance_(false)
+ : QXmlDefaultHandler(), d( new Private )
+{
+}
+
+IsotopeParser::~IsotopeParser()
{
- currentElementSymbol_ = "";
+ delete d;
}
bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs)
{
if (localName == "isotope")
{
- currentIsotope_ = new Isotope();
- inIsotope_ = true;
+ d->currentIsotope = new Isotope();
+ d->inIsotope = true;
//now save the symbol of the current element
for (int i = 0; i < attrs.length(); ++i)
{
if ( attrs.localName( i ) == "elementType" )
- currentElementSymbol_ = attrs.value( i );
+ d->currentElementSymbol = attrs.value( i );
}
- } else if (inIsotope_ && localName == "scalar")
+ } else if (d->inIsotope && localName == "scalar")
{
for (int i = 0; i < attrs.length(); ++i)
{
if ( attrs.localName( i ) == "errorValue" )
{
- currentErrorValue_ = QVariant( attrs.value( i ) );
+ d->currentErrorValue = QVariant( attrs.value( i ) );
continue;
}
if (attrs.value(i) == "bo:atomicNumber")
- inAtomicNumber_ = true;
+ d->inAtomicNumber = true;
else if (attrs.value(i) == "bo:alphapercentage")
- inAlphaPercentage_ = true;
+ d->inAlphaPercentage = true;
else if (attrs.value(i) == "bo:alphadecay")
- inAlphaDecay_ = true;
+ d->inAlphaDecay = true;
else if (attrs.value(i) == "bo:betapluspercentage")
- inBetaplusPercentage_ = true;
+ d->inBetaplusPercentage = true;
else if (attrs.value(i) == "bo:betaplusdecay")
- inBetaplusDecay_ = true;
+ d->inBetaplusDecay = true;
else if (attrs.value(i) == "bo:betaminuspercentage")
- inBetaminusPercentage_ = true;
+ d->inBetaminusPercentage = true;
else if (attrs.value(i) == "bo:betaminusdecay")
- inBetaminusDecay_ = true;
+ d->inBetaminusDecay = true;
else if (attrs.value(i) == "bo:ecpercentage")
- inECPercentage_ = true;
+ d->inECPercentage = true;
else if (attrs.value(i) == "bo:ecdecay")
- inECDecay_ = true;
+ d->inECDecay = true;
else if (attrs.value(i) == "bo:exactMass")
- inExactMass_ = true;
+ d->inExactMass = true;
}
- } else if (inIsotope_ && localName == "bo:relativeAbundance") {
+ } else if (d->inIsotope && localName == "bo:relativeAbundance") {
kdDebug() << "bo:relativeAbundance" << endl;
- inAbundance_ = true;
+ d->inAbundance = true;
}
return true;
}
{
if ( localName == "isotope" )
{
- currentIsotope_->addData( new ChemicalDataObject( QVariant( currentElementSymbol_ ), ChemicalDataObject::symbol ) );
- isotopes_.append(currentIsotope_);
+ d->currentIsotope->addData( new ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) );
+ d->isotopes.append(d->currentIsotope);
- currentIsotope_ = 0;
- currentDataObject_ = 0;
- inIsotope_ = false;
+ d->currentIsotope = 0;
+ d->currentDataObject = 0;
+ d->inIsotope = false;
}
else if ( localName == "scalar" )
{
- if ( currentDataObject_->type() == ChemicalDataObject::exactMass ){
- currentDataObject_->setErrorValue( currentErrorValue_ );
+ if ( d->currentDataObject->type() == ChemicalDataObject::exactMass ){
+ d->currentDataObject->setErrorValue( d->currentErrorValue );
}
}
bool IsotopeParser::characters(const QString &ch)
{
- currentDataObject_ = new ChemicalDataObject();
+ d->currentDataObject = new ChemicalDataObject();
ChemicalDataObject::BlueObelisk type;
QVariant value;
- if ( inExactMass_ ){
+ if (d->inExactMass){
value = ch.toDouble();
type = ChemicalDataObject::exactMass;
- inExactMass_ = false;
+ d->inExactMass = false;
}
- else if (inAtomicNumber_) {
+ else if (d->inAtomicNumber) {
value = ch.toInt();
type = ChemicalDataObject::atomicNumber;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inAlphaPercentage_) {
+ else if (d->inAlphaPercentage) {
value = ch.toDouble();
type = ChemicalDataObject::alphapercentage;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inAlphaDecay_) {
+ else if (d->inAlphaDecay) {
value = ch.toDouble();
type = ChemicalDataObject::alphadecay;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inBetaplusPercentage_) {
+ else if (d->inBetaplusPercentage) {
value = ch.toDouble();
type = ChemicalDataObject::betapluspercentage;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inBetaplusDecay_) {
+ else if (d->inBetaplusDecay) {
value = ch.toDouble();
type = ChemicalDataObject::betaplusdecay;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inBetaminusPercentage_) {
+ else if (d->inBetaminusPercentage) {
value = ch.toDouble();
type = ChemicalDataObject::betaminuspercentage;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inBetaminusDecay_) {
+ else if (d->inBetaminusDecay) {
value = ch.toDouble();
type = ChemicalDataObject::betaminusdecay;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inECPercentage_) {
+ else if (d->inECPercentage) {
value = ch.toDouble();
type = ChemicalDataObject::ecpercentage;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if (inECDecay_) {
+ else if (d->inECDecay) {
value = ch.toDouble();
type = ChemicalDataObject::ecdecay;
- inAtomicNumber_ = false;
+ d->inAtomicNumber = false;
}
- else if ( inAbundance_ ){
+ else if (d->inAbundance){
value = ch;
type = ChemicalDataObject::relativeAbundance;
- inAbundance_ = false;
+ d->inAbundance = false;
}
else//it is a non known value. Do not create a wrong object but return
return true;
- currentDataObject_->setData( value );
- currentDataObject_->setType( type );
+ d->currentDataObject->setData( value );
+ d->currentDataObject->setType( type );
- if ( currentIsotope_ )
- currentIsotope_->addData( currentDataObject_ );
+ if ( d->currentIsotope )
+ d->currentIsotope->addData( d->currentDataObject );
return true;
}
QList<Isotope*> IsotopeParser::getIsotopes()
{
- return isotopes_;
+ return d->isotopes;
}
#include <qxml.h>
-#include "chemicaldataobject.h"
-
class Isotope;
/**
* Constructor
*/
IsotopeParser();
+ ~IsotopeParser();
bool startElement( const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs );
bool endElement( const QString& namespaceURI, const QString &localName, const QString& qName );
QList<Isotope*> getIsotopes();
private:
- ChemicalDataObject *currentDataObject_;
- ChemicalDataObject::BlueObeliskUnit currentUnit_;
-
- QVariant currentErrorValue_;
-
- QString currentElementSymbol_;
-
- Isotope* currentIsotope_;
- QList<Isotope*> isotopes_;
- bool inIsotope_;
- bool inAtomicNumber_,
- inExactMass_;
- bool inAlphaPercentage_;
- bool inAlphaDecay_;
- bool inBetaplusPercentage_;
- bool inBetaplusDecay_;
- bool inBetaminusPercentage_;
- bool inBetaminusDecay_;
- bool inECPercentage_;
- bool inECDecay_;
- bool inAbundance_;
+ class Private;
+ Private *d;
};
#endif // ISOTOPEPARSER_H