00001 /* 00002 * kmolelements.h 00003 * 00004 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com> 00005 */ 00006 00007 // classes that store and manipulate chemical formulas represented as 00008 // lists of elements 00009 00010 #ifndef KMOLELEMENTS_H 00011 #define KMOLELEMENTS_H 00012 00013 00014 #ifdef HAVE_CONFIG_H 00015 #include <config.h> 00016 #endif 00017 00018 00019 #include <qlist.h> 00020 #include <qdict.h> 00021 #include <qstring.h> 00022 #include <qtextstream.h> 00023 00024 class ElementCoef; 00025 class ElementList; 00026 00030 class SubUnit { 00031 public: 00032 00033 SubUnit(); 00034 00035 virtual ~SubUnit(); 00036 00041 static SubUnit* makeSubUnit(QString line); 00042 00046 virtual double getWeight(QDict<SubUnit>* elstable) const; 00047 00051 virtual void addTo(ElementList& els, double coef) = 0; 00052 00053 virtual QString getName() const; 00054 00058 virtual void writeOut(QString& line) = 0; 00059 }; 00060 00061 00065 class ElementList : public SubUnit { 00066 public: 00067 ElementList (); 00068 ElementList (QString name); 00069 virtual ~ElementList(); 00070 double getWeight(QDict<SubUnit>* elstable) const; 00071 00076 QString getEA(QDict<SubUnit>* elstable, double mw = 0) const; 00077 00081 QString getEmpFormula() const; 00082 00086 void multiplyBy(double coef); 00087 00091 void addTo(ElementList& els, double coef); 00092 00096 void addElement(const QString& name, double coef); 00097 00101 bool contains(const QString& name); 00102 00103 00104 bool isEmpty(); 00105 00109 QString getName() const; 00110 00114 void writeOut(QString& line); 00115 00116 private: 00117 QString name; 00118 QList<ElementCoef>* elements; 00119 }; 00120 00124 class Element : public SubUnit { 00125 public: 00126 Element(const QString& name, double weight); 00127 virtual ~Element(); 00128 double getWeight(QDict<SubUnit>* elstable) const; 00129 00133 void addTo(ElementList& els, double coef); 00134 00135 QString getName() const; 00136 00137 void writeOut(QString& line); 00138 00139 private: 00140 double weight; 00141 QString name; 00142 }; 00143 00144 00149 class ElementCoef { 00150 friend class ElementList; 00151 public: 00152 ElementCoef(const QString& name, double coef = 1.0); 00153 private: 00154 QString name; 00155 double coef; 00156 }; 00157 00158 00159 #endif 00160 00161
1.4.2