summaryrefslogtreecommitdiff
authorzecke <zecke>2003-12-09 20:58:41 (UTC)
committer zecke <zecke>2003-12-09 20:58:41 (UTC)
commitafa2a1983fba363bc1d4f692fefc7fc26965de8d (patch) (side-by-side diff)
tree89f148a1417e6cdc0dac8e28cbadf187338d6d6f
parent31ba7b6bf273889f9486bb2df44d9a8a5381f579 (diff)
downloadopie-afa2a1983fba363bc1d4f692fefc7fc26965de8d.zip
opie-afa2a1983fba363bc1d4f692fefc7fc26965de8d.tar.gz
opie-afa2a1983fba363bc1d4f692fefc7fc26965de8d.tar.bz2
Do not include stl if you don't use it
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/oxygen/kmolcalc.cpp1
1 files changed, 0 insertions, 1 deletions
diff --git a/noncore/apps/oxygen/kmolcalc.cpp b/noncore/apps/oxygen/kmolcalc.cpp
index 1d41b0f..7a47942 100644
--- a/noncore/apps/oxygen/kmolcalc.cpp
+++ b/noncore/apps/oxygen/kmolcalc.cpp
@@ -1,115 +1,114 @@
/*
* kmolcalc.cpp
*
* Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com>
* Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org>
*/
/**
* KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
* weights and group definitions ELSTABLE, and the currently processed formula, stored
* as a list of elements and their coefficients, ELEMENTS.
*/
#include "kmolcalc.h"
#include <qdict.h>
#include <qdir.h>
#include <qfile.h>
#include <qpe/qpeapplication.h>
-#include <iostream>
/**
* Construct a new calculator object.
*/
KMolCalc::KMolCalc() {
elements = new ElementList;
elstable = NULL;
readElstable();
}
KMolCalc::~KMolCalc() {
delete elements;
}
void KMolCalc::readElstable() {
weight = -1; // not calculated yet
if (elstable) delete elstable;
elstable = new QDict<SubUnit> (197, TRUE);
elstable->setAutoDelete(TRUE);
mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights";
QFile f(mwfile);
if (f.exists()) readMwfile(f);
}
/**
* Parse a string S and construct the ElementList this->ELEMENTS, representing the
* composition of S. Returns 0 if successful, or an error code (currently -1) if
* parsing failed.
* The elements is S must be valid element or group symbols, as stored in this->ELSTABLE.
* See help files for correct formula syntax.
*/
QString KMolCalc::readFormula(const QString& s) {
weight = -1;
if (elements) delete elements;
elements = new ElementList;
return KMolCalc::readGroup(s, elements);
}
// read a formula group recursively. Called by readFormula.
QString KMolCalc::readGroup(const QString& s, ElementList* els) {
if (s.isEmpty()) return QString ("Enter a formula."); //ERROR
int sl = s.length();
int i = 0;
QString errors ("OK");
bool ok = TRUE;
while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok));
if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR
ElementList* elstemp = new ElementList;
while (i < sl) {
int j = i;
if (s[i] == '(') {
ElementList* inner = new ElementList;
int level = 1; // count levels of nested ( ).
while (1) {
if (i++ == sl) {
delete inner;
delete elstemp;
return QString ("Bad formula."); //ERROR
}
if (s[i] == '(') level++;
if (s[i] == ')') level--;
if (level == 0) break;
}
errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner);
j = ++i;
while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
if (! ok || suffix == 0) {
delete inner;
delete elstemp;
return QString ("Bad formula."); // ERROR
}
inner->addTo(*elstemp, suffix);
delete inner;
inner = NULL;
} else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' ||
s[i] == '\''));
QString elname = s.mid(j, i-j);
j = i;
while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
if (! ok || suffix == 0) {
delete elstemp;
return QString ("Bad formula."); // ERROR
}
SubUnit* group = elstable->find(elname);
if (group == 0) {
delete elstemp;
return QString ("Undefined symbol: ") + elname; //ERROR
}
group->addTo(*elstemp, suffix);
} else if (s[i] == '+') {