From: Carsten Niehaus Date: Mon, 24 Oct 2005 12:28:23 +0000 (+0000) Subject: * First version of the IsotopeParser X-Git-Tag: v3.80.2~258 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=ad65a525026229f8ddb7a0d382b8ed6b340d306d;p=libqmvoc.git * First version of the IsotopeParser ** Missing: errorValue-support svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=473670 --- diff --git a/libscience/Makefile.am b/libscience/Makefile.am index a79ce23..6e34644 100644 --- a/libscience/Makefile.am +++ b/libscience/Makefile.am @@ -10,6 +10,7 @@ libscience_la_SOURCES = \ isotope.cpp \ spectrumparser.cpp \ elementparser.cpp \ + isotopeparser.cpp \ tempunit.cpp \ chemicaldataobject.cpp diff --git a/libscience/element.cpp b/libscience/element.cpp index d67bde2..4d47414 100644 --- a/libscience/element.cpp +++ b/libscience/element.cpp @@ -19,8 +19,6 @@ ***************************************************************************/ #include "element.h" -#include "spectrum.h" -#include "isotope.h" #include "tempunit.h" #include "chemicaldataobject.h" diff --git a/libscience/isotope.cpp b/libscience/isotope.cpp index 40f5bab..34d1b56 100644 --- a/libscience/isotope.cpp +++ b/libscience/isotope.cpp @@ -37,3 +37,38 @@ Isotope::Isotope( ChemicalDataObject* mass, Isotope::~Isotope(){} + +ChemicalDataObject* Isotope::data() const +{ + return m_mass; +} + +void Isotope::addData( ChemicalDataObject* o ) +{ + if ( o->type() == ChemicalDataObject::exactMass ) + m_mass = o; + else if ( o->type() == ChemicalDataObject::atomicNumber ) + m_identifier = o; + + return; +} + +double Isotope::mass() const +{ + return m_mass->value().toDouble(); +} + +double Isotope::errorMargin() const +{ + return m_mass->errorValue().toDouble(); +} + +int Isotope::parentElementNumber() const +{ + return m_identifier->value().toInt(); +} + +QString Isotope::parentElementSymbol() const +{ + return m_parentElementSymbol; +} diff --git a/libscience/isotope.h b/libscience/isotope.h index 3213ed1..a8cd963 100644 --- a/libscience/isotope.h +++ b/libscience/isotope.h @@ -36,13 +36,32 @@ class Isotope Isotope(ChemicalDataObject* mass, ChemicalDataObject* ID); virtual ~Isotope(); + ChemicalDataObject* data() const; + + double mass() const; + + double errorMargin() const; + + int parentElementNumber() const; + + QString parentElementSymbol() const; + + void addData( ChemicalDataObject* o ); + private: /** * the symbol of the element the isotope belongs to */ QString m_parentElementSymbol; + /** + * stores the infomation about the mass of the Isotope + */ ChemicalDataObject* m_mass; + + /** + * stores the atomicNumber of the Isotope + */ ChemicalDataObject* m_identifier; }; diff --git a/libscience/isotopeparser.cpp b/libscience/isotopeparser.cpp new file mode 100644 index 0000000..ab23acd --- /dev/null +++ b/libscience/isotopeparser.cpp @@ -0,0 +1,95 @@ +/*************************************************************************** +copyright : (C) 2005 by Carsten Niehaus +email : cniehaus@kde.org + ***************************************************************************/ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "isotopeparser.h" +#include "isotope.h" + +#include +#include +#include +#include + +#include + +IsotopeParser::IsotopeParser() + : QXmlDefaultHandler(), + currentIsotope_(0), + inAtomicNumber_(false), + inExactMass_(false) +{ +} + +bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs) +{ + if (localName == "isotope") + { + currentIsotope_ = new Isotope(); + inIsotope_ = true; + } else if (inIsotope_ && localName == "scalar") + { + for (int i = 0; i < attrs.length(); ++i) + { + if (attrs.value(i) == "bo:atomicNumber") + inAtomicNumber_ = true; + else if (attrs.value(i) == "bo:exactMass") + inExactMass_ = true; + } + } + return true; +} + +bool IsotopeParser::endElement ( const QString & namespaceURI, const QString & localName, const QString & qName ) +{ + if ( localName == "isotope" ) + { + isotopes_.append(currentIsotope_); + + currentIsotope_ = 0; + currentDataObject_ = 0; + inIsotope_ = false; + } + + return true; +} + +bool IsotopeParser::characters(const QString &ch) +{ + currentDataObject_ = new ChemicalDataObject(); + ChemicalDataObject::BlueObelisk type; + QVariant value; + + if ( inExactMass_ ){ + value = ch.toDouble(); + type = ChemicalDataObject::exactMass; + inExactMass_ = false; + } + else if (inAtomicNumber_) { + value = ch.toInt(); + type = ChemicalDataObject::atomicNumber; + inAtomicNumber_ = false; + } + else//it is a non known value. Do not create a wrong object but return + return true; + + currentDataObject_->setData( value ); + currentDataObject_->setType( type ); + + if ( currentIsotope_ ) + currentIsotope_->addData( currentDataObject_ ); + + return true; +} + +QList IsotopeParser::getIsotopes() +{ + return isotopes_; +} diff --git a/libscience/isotopeparser.h b/libscience/isotopeparser.h new file mode 100644 index 0000000..c34b509 --- /dev/null +++ b/libscience/isotopeparser.h @@ -0,0 +1,53 @@ +#ifndef ISOTOPEPARSER_H +#define ISOTOPEPARSER_H +/*************************************************************************** + copyright : (C) 2005 by Carsten Niehaus + email : cniehaus@kde.org + ***************************************************************************/ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include + +#include + +#include "chemicaldataobject.h" + +class Isotope; + +/** + * @author Carsten Niehaus + */ +class IsotopeParser : public QXmlDefaultHandler +{ + public: + /** + * Constructor + */ + IsotopeParser(); + bool startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs); + + bool endElement ( const QString & namespaceURI, const QString & localName, const QString & qName ); + + bool characters(const QString &ch); + + QList getIsotopes(); + + private: + ChemicalDataObject *currentDataObject_; + ChemicalDataObject::BlueObeliskUnit currentUnit_; + + Isotope* currentIsotope_; + QList isotopes_; + bool inIsotope_; + bool inAtomicNumber_, + inExactMass_; +}; +#endif // ISOTOPEPARSER_H +