File indexing completed on 2024-04-21 04:01:58
0001 /* 0002 This file is part of the KDE project "KAtomic" 0003 0004 SPDX-FileCopyrightText: 1999 Stephan Kulow <coolo@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef ATOM_H 0010 #define ATOM_H 0011 0012 #include <cstring> 0013 0014 #define MAX_CONNS_PER_ATOM 8 0015 0016 class atom { 0017 public: 0018 char obj; 0019 char conn[MAX_CONNS_PER_ATOM + 1]; 0020 0021 bool operator==(atom rhs) const { return (rhs.obj == obj && !strcmp(rhs.conn,conn)); } 0022 bool isEmpty() const { return (obj == 0 || obj == '.'); } 0023 double weight() const { 0024 switch (obj) { 0025 case '1': return 1.00797; // H 0026 case '2': return 12.0107; // C 0027 case '3': return 15.9994; // O 0028 case '4': return 14.0067; // N 0029 case '5': return 32.065; // S 0030 case '6': return 18.9984; // Fl 0031 case '7': return 35.453; // Cl 0032 case '9': return 30.97; // P 0033 default: return 0.0; 0034 } 0035 } 0036 }; 0037 0038 inline char int2atom(int i) { 0039 if (!i) 0040 return '.'; 0041 if (i == 254) 0042 return '#'; 0043 if (i <= 9) 0044 return i + '0'; 0045 return i + 'a' - 10; 0046 } 0047 0048 inline int atom2int(char ch) { 0049 if (ch == '.' || ch == 0) 0050 return 0; 0051 if (ch == '#') 0052 return 254; 0053 if (ch >= '0' && ch <= '9') 0054 return ch - '0'; 0055 return ch - 'a' + 10; 0056 } 0057 0058 #endif