summaryrefslogtreecommitdiff
path: root/noncore/apps/oxygen/kmolelements.h
authorcniehaus <cniehaus>2002-09-15 17:09:54 (UTC)
committer cniehaus <cniehaus>2002-09-15 17:09:54 (UTC)
commit33ec9ead7ce30bf9450b9048506f0bda49ba4791 (patch) (unidiff)
tree1683b16a3cb06d7773427193fc4ea5284bf3bdaa /noncore/apps/oxygen/kmolelements.h
parent7a8dc6b0a16db160a1e50fde8f298eb9e3cb0099 (diff)
downloadopie-33ec9ead7ce30bf9450b9048506f0bda49ba4791.zip
opie-33ec9ead7ce30bf9450b9048506f0bda49ba4791.tar.gz
opie-33ec9ead7ce30bf9450b9048506f0bda49ba4791.tar.bz2
Fell free to shoot me if I messed up CVS again... *fingercrossed*
Diffstat (limited to 'noncore/apps/oxygen/kmolelements.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/oxygen/kmolelements.h161
1 files changed, 161 insertions, 0 deletions
diff --git a/noncore/apps/oxygen/kmolelements.h b/noncore/apps/oxygen/kmolelements.h
new file mode 100644
index 0000000..06d1469
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolelements.h
@@ -0,0 +1,161 @@
1/*
2 * kmolelements.h
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7// classes that store and manipulate chemical formulas represented as
8// lists of elements
9
10#ifndef KMOLELEMENTS_H
11#define KMOLELEMENTS_H
12
13
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18
19#include <qlist.h>
20#include <qdict.h>
21#include <qstring.h>
22#include <qtextstream.h>
23
24class ElementCoef;
25class ElementList;
26
27/**
28 * A generic chemical entity. Can be an element or a group.
29 */
30class SubUnit {
31 public:
32
33 SubUnit();
34
35 virtual ~SubUnit();
36
37 /**
38 * Construct a subunit and return a pointer to it. The syntax of LINE is
39 * the one used in the element definition file.
40 */
41 static SubUnit* makeSubUnit(QString line);
42
43 /**
44 * Get the molecular weight of THIS, based on the data from ELSTABLE.
45 */
46 virtual double getWeight(QDict<SubUnit>* elstable) const;
47
48 /**
49 * Add THIS to ELS.
50 */
51 virtual void addTo(ElementList& els, double coef) = 0;
52
53 virtual QString getName() const;
54
55 /**
56 * Write THIS to LINE, in the format used in the definition file.
57 */
58 virtual void writeOut(QString& line) = 0;
59};
60
61
62/**
63 * A group of elements.
64 */
65class ElementList : public SubUnit {
66 public:
67 ElementList ();
68 ElementList (QString name);
69 virtual ~ElementList();
70 double getWeight(QDict<SubUnit>* elstable) const;
71
72 /**
73 * Return a string representing the elemental composition of THIS, as
74 * a tab-separated element - percentage pairs, separated by newlines.
75 */
76 QString getEA(QDict<SubUnit>* elstable, double mw = 0) const;
77
78 /**
79 * Return a string representing THIS as an empirical chemical formula.
80 */
81 QString getEmpFormula() const;
82
83 /**
84 * Multiply THIS (i.e. the coefficient of each element) by coef.
85 */
86 void multiplyBy(double coef);
87
88 /**
89 * Add THIS to ELS. THIS is not modified; ELS is.
90 */
91 void addTo(ElementList& els, double coef);
92
93 /**
94 * Add an element to THIS, with a coefficient COEF.
95 */
96 void addElement(const QString& name, double coef);
97
98 /**
99 * True iff THIS contains element named NAME.
100 */
101 bool contains(const QString& name);
102
103
104 bool isEmpty();
105
106 /**
107 * The name of THIS, as a chemical group.
108 */
109 QString getName() const;
110
111 /**
112 * Write THIS to LINE, in a format suitable for the element definition file.
113 */
114 void writeOut(QString& line);
115
116 private:
117 QString name;
118 QList<ElementCoef>* elements;
119};
120
121/**
122 * A chemical element.
123 */
124class Element : public SubUnit {
125 public:
126 Element(const QString& name, double weight);
127 virtual ~Element();
128 double getWeight(QDict<SubUnit>* elstable) const;
129
130 /**
131 * Add THIS to ELS, with a coefficient COEF.
132 */
133 void addTo(ElementList& els, double coef);
134
135 QString getName() const;
136
137 void writeOut(QString& line);
138
139 private:
140 double weight;
141 QString name;
142};
143
144
145/**
146 * An element - coefficient pair. Used to represent elements within an
147 * element list.
148 */
149class ElementCoef {
150 friend class ElementList;
151 public:
152 ElementCoef(const QString& name, double coef = 1.0);
153 private:
154 QString name;
155 double coef;
156};
157
158
159#endif
160
161