File indexing completed on 2024-05-12 05:46:33
0001 /******************************************************************* 0002 * 0003 * Copyright (C) 1999 Stephan Kulow <coolo@kde.org> 0004 * 0005 * This file is part of the KDE project "KAtomic" 0006 * 0007 * This program is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU General Public License as published by 0009 * the Free Software Foundation; either version 2, or (at your option) 0010 * any later version. 0011 * 0012 * This progran is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program; see the file COPYING. If not, write to 0019 * the Free Software Foundation, 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 * 0022 ********************************************************************/ 0023 #ifndef ATOM_H 0024 #define ATOM_H 0025 0026 #define MAX_CONNS_PER_ATOM 8 0027 0028 class atom { 0029 public: 0030 char obj; 0031 char conn[MAX_CONNS_PER_ATOM + 1]; 0032 0033 bool operator==(atom rhs) const { return (rhs.obj == obj && !strcmp(rhs.conn,conn)); } 0034 bool isEmpty() const { return (obj == 0 || obj == '.'); } 0035 double weight() const { 0036 switch (obj) { 0037 case '1': return 1.00797; // H 0038 case '2': return 12.0107; // C 0039 case '3': return 15.9994; // O 0040 case '4': return 14.0067; // N 0041 case '5': return 32.065; // S 0042 case '6': return 18.9984; // Fl 0043 case '7': return 35.453; // Cl 0044 case '9': return 30.97; // P 0045 default: return 0.0; 0046 } 0047 } 0048 }; 0049 0050 inline char int2atom(int i) { 0051 if (!i) 0052 return '.'; 0053 if (i == 254) 0054 return '#'; 0055 if (i <= 9) 0056 return i + '0'; 0057 return i + 'a' - 10; 0058 } 0059 0060 inline int atom2int(char ch) { 0061 if (ch == '.' || ch == 0) 0062 return 0; 0063 if (ch == '#') 0064 return 254; 0065 if (ch >= '0' && ch <= '9') 0066 return ch - '0'; 0067 return ch - 'a' + 10; 0068 } 0069 0070 #endif