[80a6a52] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | #include <map>
|
---|
| 4 | #include <vector>
|
---|
| 5 | #include <string>
|
---|
| 6 | #include <exception>
|
---|
| 7 |
|
---|
| 8 | namespace geoworld
|
---|
| 9 | {
|
---|
| 10 | enum AtomicNumber
|
---|
| 11 | {
|
---|
| 12 | H = 1,
|
---|
| 13 | He = 2,
|
---|
| 14 | Li = 3,
|
---|
| 15 | Be = 4,
|
---|
| 16 | B = 5,
|
---|
| 17 | C = 6,
|
---|
| 18 | N = 7,
|
---|
| 19 | O = 8,
|
---|
| 20 | F = 9,
|
---|
| 21 | Ne = 10,
|
---|
| 22 | Na = 11,
|
---|
| 23 | Mg = 12,
|
---|
| 24 | Al = 13,
|
---|
| 25 | Si = 14,
|
---|
| 26 | P = 15,
|
---|
| 27 | S = 16,
|
---|
| 28 | Cl = 17,
|
---|
| 29 | Ar = 18,
|
---|
| 30 | K = 19,
|
---|
| 31 | Ca = 20,
|
---|
| 32 | Sc = 21,
|
---|
| 33 | Ti = 22,
|
---|
| 34 | V = 23,
|
---|
| 35 | Cr = 24,
|
---|
| 36 | Mn = 25,
|
---|
| 37 | Fe = 26,
|
---|
| 38 | Co = 27,
|
---|
| 39 | Ni = 28,
|
---|
| 40 | Cu = 29,
|
---|
| 41 | Zn = 30,
|
---|
| 42 | Ga = 31,
|
---|
| 43 | Ge = 32,
|
---|
| 44 | As = 33,
|
---|
| 45 | Se = 34,
|
---|
| 46 | Br = 35,
|
---|
| 47 | Kr = 36,
|
---|
| 48 | Rb = 37,
|
---|
| 49 | Sr = 38,
|
---|
| 50 | Y = 39,
|
---|
| 51 | Zr = 40,
|
---|
| 52 | Nb = 41,
|
---|
| 53 | Mo = 42,
|
---|
| 54 | Tc = 43,
|
---|
| 55 | Ru = 44,
|
---|
| 56 | Rh = 45,
|
---|
| 57 | Pd = 46,
|
---|
| 58 | Ag = 47,
|
---|
| 59 | Cd = 48,
|
---|
| 60 | In = 49,
|
---|
| 61 | Sn = 50,
|
---|
| 62 | Sb = 51,
|
---|
| 63 | Te = 52,
|
---|
| 64 | I = 53,
|
---|
| 65 | Xe = 54,
|
---|
| 66 | Cs = 55,
|
---|
| 67 | Ba = 56,
|
---|
| 68 | La = 57,
|
---|
| 69 | Ce = 58,
|
---|
| 70 | Pr = 59,
|
---|
| 71 | Nd = 60,
|
---|
| 72 | Pm = 61,
|
---|
| 73 | Sm = 62,
|
---|
| 74 | Eu = 63,
|
---|
| 75 | Gd = 64,
|
---|
| 76 | Tb = 65,
|
---|
| 77 | Dy = 66,
|
---|
| 78 | Ho = 67,
|
---|
| 79 | Er = 68,
|
---|
| 80 | Tm = 69,
|
---|
| 81 | Yb = 70,
|
---|
| 82 | Lu = 71,
|
---|
| 83 | Hf = 72,
|
---|
| 84 | Ta = 73,
|
---|
| 85 | W = 74,
|
---|
| 86 | Re = 75,
|
---|
| 87 | Os = 76,
|
---|
| 88 | Ir = 77,
|
---|
| 89 | Pt = 78,
|
---|
| 90 | Au = 79,
|
---|
| 91 | Hg = 80,
|
---|
| 92 | Tl = 81,
|
---|
| 93 | Pb = 82,
|
---|
| 94 | Bi = 83,
|
---|
| 95 | Po = 84,
|
---|
| 96 | At = 85,
|
---|
| 97 | Rn = 86,
|
---|
| 98 | Fr = 87,
|
---|
| 99 | Ra = 88,
|
---|
| 100 | Ac = 89,
|
---|
| 101 | Th = 90,
|
---|
| 102 | Pa = 91,
|
---|
| 103 | U = 92,
|
---|
| 104 | Np = 93,
|
---|
| 105 | Pu = 94,
|
---|
| 106 | Am = 95,
|
---|
| 107 | Cm = 96,
|
---|
| 108 | Bk = 97,
|
---|
| 109 | Cf = 98,
|
---|
| 110 | Es = 99,
|
---|
| 111 | Fm = 100,
|
---|
| 112 | Md = 101,
|
---|
| 113 | No = 102,
|
---|
| 114 | Lr = 103,
|
---|
| 115 | Rf = 104,
|
---|
| 116 | Db = 105,
|
---|
| 117 | Sg = 106,
|
---|
| 118 | Bh = 107,
|
---|
| 119 | Hs = 108,
|
---|
| 120 | Mt = 109,
|
---|
| 121 | Ds = 110,
|
---|
| 122 | Rg = 111,
|
---|
| 123 | Uub = 112,
|
---|
| 124 | Uut = 113,
|
---|
| 125 | Uuq = 114,
|
---|
| 126 | Uup = 115,
|
---|
| 127 | Uuh = 116,
|
---|
| 128 | Uus = 117,
|
---|
| 129 | Uuo = 118
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 | extern class PeriodicTable
|
---|
| 133 | {
|
---|
| 134 | private:
|
---|
| 135 | std::map <std::string, AtomicNumber> _name2num;
|
---|
| 136 |
|
---|
| 137 | public:
|
---|
| 138 | PeriodicTable ();
|
---|
| 139 |
|
---|
| 140 | inline AtomicNumber operator [] (const std::string & s) { return _name2num[s]; }
|
---|
| 141 | } periodicity;
|
---|
| 142 |
|
---|
| 143 | static const int NUM_CHEM_ELEMENTS = Uuo + 1;
|
---|
| 144 |
|
---|
| 145 | class PhasePoint
|
---|
| 146 | {
|
---|
| 147 | public:
|
---|
| 148 | float temperature, pressure;
|
---|
| 149 |
|
---|
| 150 | inline PhasePoint () {}
|
---|
| 151 | inline PhasePoint (float temp, float pressure)
|
---|
| 152 | : temperature(temperature), pressure(pressure) {}
|
---|
| 153 | };
|
---|
| 154 |
|
---|
| 155 | class ChemicalFormulaParser
|
---|
| 156 | {
|
---|
| 157 | private:
|
---|
| 158 | enum TokenType
|
---|
| 159 | {
|
---|
| 160 | TWord,
|
---|
| 161 | TNum,
|
---|
| 162 | TOpen,
|
---|
| 163 | TClose,
|
---|
| 164 | TSep,
|
---|
| 165 | TAlt
|
---|
| 166 | };
|
---|
| 167 |
|
---|
| 168 | class Ex : public std::exception {};
|
---|
| 169 |
|
---|
| 170 | class Token
|
---|
| 171 | {
|
---|
| 172 | private:
|
---|
| 173 | unsigned _s0, _s;
|
---|
| 174 |
|
---|
| 175 | const std::string & _formula;
|
---|
| 176 |
|
---|
| 177 | public:
|
---|
| 178 | const TokenType type;
|
---|
| 179 |
|
---|
| 180 | Token (const std::string & formula, const unsigned s0);
|
---|
| 181 | Token & operator = (const Token & a);
|
---|
| 182 |
|
---|
| 183 | static TokenType typeOf (const char ch);
|
---|
| 184 |
|
---|
| 185 | void operator >> (unsigned & num) const;
|
---|
| 186 | void operator >> (AtomicNumber & atom) const;
|
---|
| 187 | void operator >> (float & f) const;
|
---|
| 188 |
|
---|
| 189 | unsigned length () const;
|
---|
| 190 | };
|
---|
| 191 |
|
---|
| 192 | std::vector <Token> _tokens;
|
---|
| 193 | const std::string & _formula;
|
---|
| 194 |
|
---|
| 195 | bool lookAhead (const std::vector <Token>::const_iterator & i, const TokenType tok) const;
|
---|
| 196 | bool lookBehind (const std::vector <Token>::const_iterator & i, const TokenType tok) const;
|
---|
| 197 |
|
---|
| 198 | public:
|
---|
| 199 | class IQuantityCallback
|
---|
| 200 | {
|
---|
| 201 | public:
|
---|
| 202 | virtual void setChemicalQuantity (const AtomicNumber atom, const float amt) = 0;
|
---|
| 203 | };
|
---|
| 204 |
|
---|
| 205 | ChemicalFormulaParser (const std::string & formula);
|
---|
| 206 |
|
---|
| 207 | void quantities (IQuantityCallback * cb);
|
---|
| 208 | };
|
---|
| 209 | }
|
---|