1 | /******************************************************************* |
2 | * |
3 | * Copyright (C) 1999 Stephan Kulow <coolo@kde.org> |
4 | * |
5 | * This file is part of the KDE project "KAtomic" |
6 | * |
7 | * KAtomic is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2, or (at your option) |
10 | * any later version. |
11 | * |
12 | * KAtomic is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with KAtomic; see the file COPYING. If not, write to |
19 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
20 | * Boston, MA 02110-1301, USA. |
21 | * |
22 | ********************************************************************/ |
23 | #ifndef ATOM_H |
24 | #define ATOM_H |
25 | |
26 | #define MAX_CONNS_PER_ATOM 8 |
27 | |
28 | class atom { |
29 | public: |
30 | char obj; |
31 | char conn[MAX_CONNS_PER_ATOM + 1]; |
32 | |
33 | bool operator==(const atom& rhs) const { return (rhs.obj == obj && !strcmp(rhs.conn,conn)); } |
34 | bool isEmpty() const { return (obj == 0 || obj == '.'); } |
35 | double weight() const { |
36 | switch (obj) { |
37 | case '1': return 1.00797; // H |
38 | case '2': return 12.0107; // C |
39 | case '3': return 15.9994; // O |
40 | case '4': return 14.0067; // N |
41 | case '5': return 32.065; // S |
42 | case '6': return 18.9984; // Fl |
43 | case '7': return 35.453; // Cl |
44 | case '9': return 30.97; // P |
45 | default: return 0.0; |
46 | } |
47 | } |
48 | }; |
49 | |
50 | inline char int2atom(int i) { |
51 | if (!i) |
52 | return '.'; |
53 | if (i == 254) |
54 | return '#'; |
55 | if (i <= 9) |
56 | return i + '0'; |
57 | return i + 'a' - 10; |
58 | } |
59 | |
60 | inline int atom2int(char ch) { |
61 | if (ch == '.' || ch == 0) |
62 | return 0; |
63 | if (ch == '#') |
64 | return 254; |
65 | if (ch >= '0' && ch <= '9') |
66 | return ch - '0'; |
67 | return ch - 'a' + 10; |
68 | } |
69 | |
70 | #endif |
71 | |