summaryrefslogtreecommitdiff
authorzecke <zecke>2003-12-09 20:58:41 (UTC)
committer zecke <zecke>2003-12-09 20:58:41 (UTC)
commitafa2a1983fba363bc1d4f692fefc7fc26965de8d (patch) (unidiff)
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) (ignore 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,83 +1,82 @@
1/* 1/*
2 * kmolcalc.cpp 2 * kmolcalc.cpp
3 * 3 *
4 * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> 4 * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com>
5 * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org> 5 * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org>
6 */ 6 */
7 7
8/** 8/**
9 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic 9 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
10 * weights and group definitions ELSTABLE, and the currently processed formula, stored 10 * weights and group definitions ELSTABLE, and the currently processed formula, stored
11 * as a list of elements and their coefficients, ELEMENTS. 11 * as a list of elements and their coefficients, ELEMENTS.
12 */ 12 */
13 13
14#include "kmolcalc.h" 14#include "kmolcalc.h"
15#include <qdict.h> 15#include <qdict.h>
16#include <qdir.h> 16#include <qdir.h>
17#include <qfile.h> 17#include <qfile.h>
18#include <qpe/qpeapplication.h> 18#include <qpe/qpeapplication.h>
19#include <iostream>
20 19
21 20
22/** 21/**
23 * Construct a new calculator object. 22 * Construct a new calculator object.
24 */ 23 */
25KMolCalc::KMolCalc() { 24KMolCalc::KMolCalc() {
26 elements = new ElementList; 25 elements = new ElementList;
27 elstable = NULL; 26 elstable = NULL;
28 readElstable(); 27 readElstable();
29} 28}
30 29
31KMolCalc::~KMolCalc() { 30KMolCalc::~KMolCalc() {
32 delete elements; 31 delete elements;
33} 32}
34 33
35void KMolCalc::readElstable() { 34void KMolCalc::readElstable() {
36 weight = -1; // not calculated yet 35 weight = -1; // not calculated yet
37 if (elstable) delete elstable; 36 if (elstable) delete elstable;
38 elstable = new QDict<SubUnit> (197, TRUE); 37 elstable = new QDict<SubUnit> (197, TRUE);
39 elstable->setAutoDelete(TRUE); 38 elstable->setAutoDelete(TRUE);
40 mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights"; 39 mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights";
41 QFile f(mwfile); 40 QFile f(mwfile);
42 if (f.exists()) readMwfile(f); 41 if (f.exists()) readMwfile(f);
43} 42}
44 43
45 44
46/** 45/**
47 * Parse a string S and construct the ElementList this->ELEMENTS, representing the 46 * Parse a string S and construct the ElementList this->ELEMENTS, representing the
48 * composition of S. Returns 0 if successful, or an error code (currently -1) if 47 * composition of S. Returns 0 if successful, or an error code (currently -1) if
49 * parsing failed. 48 * parsing failed.
50 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. 49 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE.
51 * See help files for correct formula syntax. 50 * See help files for correct formula syntax.
52 */ 51 */
53QString KMolCalc::readFormula(const QString& s) { 52QString KMolCalc::readFormula(const QString& s) {
54 weight = -1; 53 weight = -1;
55 if (elements) delete elements; 54 if (elements) delete elements;
56 elements = new ElementList; 55 elements = new ElementList;
57 return KMolCalc::readGroup(s, elements); 56 return KMolCalc::readGroup(s, elements);
58} 57}
59 58
60// read a formula group recursively. Called by readFormula. 59// read a formula group recursively. Called by readFormula.
61QString KMolCalc::readGroup(const QString& s, ElementList* els) { 60QString KMolCalc::readGroup(const QString& s, ElementList* els) {
62 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR 61 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR
63 int sl = s.length(); 62 int sl = s.length();
64 int i = 0; 63 int i = 0;
65 QString errors ("OK"); 64 QString errors ("OK");
66 bool ok = TRUE; 65 bool ok = TRUE;
67 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; 66 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
68 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); 67 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok));
69 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR 68 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR
70 ElementList* elstemp = new ElementList; 69 ElementList* elstemp = new ElementList;
71 while (i < sl) { 70 while (i < sl) {
72 int j = i; 71 int j = i;
73 if (s[i] == '(') { 72 if (s[i] == '(') {
74 ElementList* inner = new ElementList; 73 ElementList* inner = new ElementList;
75 int level = 1; // count levels of nested ( ). 74 int level = 1; // count levels of nested ( ).
76 while (1) { 75 while (1) {
77 if (i++ == sl) { 76 if (i++ == sl) {
78 delete inner; 77 delete inner;
79 delete elstemp; 78 delete elstemp;
80 return QString ("Bad formula."); //ERROR 79 return QString ("Bad formula."); //ERROR
81 } 80 }
82 if (s[i] == '(') level++; 81 if (s[i] == '(') level++;
83 if (s[i] == ')') level--; 82 if (s[i] == ')') level--;