1 |
tim |
1961 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
|
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
|
|
* 1. Acknowledgement of the program authors must be made in any |
10 |
|
|
* publication of scientific results based in part on use of the |
11 |
|
|
* program. An acceptable form of acknowledgement is citation of |
12 |
|
|
* the article in which the program was described (Matthew |
13 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
|
|
* |
18 |
|
|
* 2. Redistributions of source code must retain the above copyright |
19 |
|
|
* notice, this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the |
24 |
|
|
* distribution. |
25 |
|
|
* |
26 |
|
|
* This software is provided "AS IS," without a warranty of any |
27 |
|
|
* kind. All express or implied conditions, representations and |
28 |
|
|
* warranties, including any implied warranty of merchantability, |
29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
31 |
|
|
* be liable for any damages suffered by licensee as a result of |
32 |
|
|
* using, modifying or distributing the software or its |
33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
36 |
|
|
* damages, however caused and regardless of the theory of liability, |
37 |
|
|
* arising out of the use of or inability to use software, even if the |
38 |
|
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
|
* such damages. |
40 |
|
|
*/ |
41 |
|
|
|
42 |
|
|
#ifndef SELECTION_TOKEN_HPP |
43 |
|
|
#define SELECTION_TOKEN_HPP |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
namespace oopse { |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* @class Token |
51 |
|
|
* @todo document |
52 |
tim |
1962 |
* @note translate from jmol |
53 |
tim |
1961 |
*/ |
54 |
|
|
class Token { |
55 |
|
|
|
56 |
|
|
public: |
57 |
|
|
|
58 |
tim |
1962 |
static std::map<std::string, Token> tokenMap; |
59 |
|
|
|
60 |
tim |
1961 |
int tok; |
61 |
tim |
1962 |
Object value; |
62 |
|
|
int intValue = Integer.MAX_VALUE; |
63 |
|
|
|
64 |
|
|
Token(int tok, int intValue, Object value) { |
65 |
|
|
this.tok = tok; |
66 |
|
|
this.intValue = intValue; |
67 |
|
|
this.value = value; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
Token(int tok, int intValue) { |
71 |
|
|
this.tok = tok; |
72 |
|
|
this.intValue = intValue; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
Token(int tok) { |
76 |
|
|
this.tok = tok; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
Token(int tok, Object value) { |
80 |
|
|
this.tok = tok; |
81 |
|
|
this.value = value; |
82 |
|
|
} |
83 |
tim |
1961 |
|
84 |
|
|
const static int nada = 0; |
85 |
|
|
const static int identifier = 1; |
86 |
|
|
const static int integer = 2; |
87 |
|
|
const static int decimal = 3; |
88 |
|
|
const static int string = 4; |
89 |
tim |
1962 |
const static int unknown = 5; |
90 |
|
|
const static int keyword = 6; |
91 |
|
|
const static int whitespace = 7; |
92 |
|
|
const static int comment = 8; |
93 |
|
|
const static int endofline = 9; |
94 |
|
|
const static int endofstatement = 10; |
95 |
tim |
1961 |
|
96 |
|
|
const static int command = (1 << 8); |
97 |
|
|
const static int expressionCommand = (1 << 9); // expression command |
98 |
tim |
1962 |
const static int expression = (1 << 10); /// expression term |
99 |
tim |
1961 |
|
100 |
|
|
// every property is also valid in an expression context |
101 |
tim |
1962 |
const static int atomproperty = (1 << 11) | expression; |
102 |
tim |
1961 |
// every predefined is also valid in an expression context |
103 |
tim |
1962 |
const static int comparator = (1 << 12) | expression; |
104 |
|
|
const static int predefinedset = (1 << 13) | expression; |
105 |
tim |
1961 |
|
106 |
|
|
// rasmol commands |
107 |
|
|
const static int define = command | expressionCommand |1; |
108 |
|
|
const static int select = command |expressionCommand |2 ; |
109 |
|
|
const static int all = expression | 11 ; |
110 |
|
|
|
111 |
|
|
// atom expression operators |
112 |
|
|
const static int leftparen = expression | 0; |
113 |
|
|
const static int rightparen = expression | 1; |
114 |
|
|
const static int hyphen = expression | 2; |
115 |
|
|
const static int opAnd = expression | 3; |
116 |
|
|
const static int opOr = expression | 4; |
117 |
|
|
const static int opNot = expression | 5; |
118 |
|
|
const static int within = expression | 6; |
119 |
tim |
1962 |
const static int asterisk = expression | 7; |
120 |
|
|
const static int dot = expression | 8; |
121 |
tim |
1961 |
|
122 |
|
|
// miguel 2005 01 01 |
123 |
|
|
// these are used to demark the beginning and end of expressions |
124 |
|
|
// they do not exist in the source code, but are emitted by the |
125 |
|
|
// expression compiler |
126 |
|
|
const static int expressionBegin = expression | 100; |
127 |
|
|
const static int expressionEnd = expression | 101; |
128 |
|
|
|
129 |
|
|
const static int atomno = atomproperty | 0; |
130 |
|
|
const static int elemno = atomproperty | 1; |
131 |
|
|
const static int resno = atomproperty | 2; |
132 |
|
|
const static int radius = atomproperty | 3 ; |
133 |
|
|
const static int _bondedcount = atomproperty | 6; |
134 |
|
|
const static int _groupID = atomproperty | 7; |
135 |
|
|
const static int _atomID = atomproperty | 8; |
136 |
|
|
|
137 |
|
|
const static int opGT = comparator | 0; |
138 |
|
|
const static int opGE = comparator | 1; |
139 |
|
|
const static int opLE = comparator | 2; |
140 |
|
|
const static int opLT = comparator | 3; |
141 |
|
|
const static int opEQ = comparator | 4; |
142 |
|
|
const static int opNE = comparator | 5; |
143 |
|
|
|
144 |
|
|
const static int x = expression |2; |
145 |
|
|
const static int y = expression | 3; |
146 |
|
|
const static int z = expression | 4; |
147 |
|
|
const static int none = expression | 5; |
148 |
tim |
1962 |
|
149 |
tim |
1961 |
const static Token tokenExpressionBegin(expressionBegin, "expressionBegin"); |
150 |
|
|
const static Token tokenExpressionEnd(expressionEnd, "expressionEnd"); |
151 |
|
|
|
152 |
tim |
1962 |
}; |
153 |
tim |
1961 |
|
154 |
tim |
1962 |
}; |
155 |
tim |
1961 |
|
156 |
|
|
|
157 |
tim |
1962 |
class TokenMap { |
158 |
|
|
const static Object[] arrayPairs = { |
159 |
tim |
1961 |
// commands |
160 |
tim |
1962 |
"define", new Token(define, "define"), |
161 |
|
|
"select", new Token(select, "select"), |
162 |
tim |
1961 |
// atom expressions |
163 |
|
|
"(", new Token(leftparen, "("), |
164 |
|
|
")", new Token(rightparen, ")"), |
165 |
|
|
"-", new Token(hyphen, "-"), |
166 |
|
|
"and", tokenAnd, |
167 |
|
|
"or", new Token(opOr, "or"), |
168 |
|
|
"not", new Token(opNot, "not"), |
169 |
|
|
"<", new Token(opLT, "<"), |
170 |
|
|
"<=", new Token(opLE, "<="), |
171 |
|
|
">=", new Token(opGE, ">="), |
172 |
|
|
">", new Token(opGT, ">="), |
173 |
|
|
"==", new Token(opEQ, "=="), |
174 |
|
|
"!=", new Token(opNE, "!="), |
175 |
|
|
"within", new Token(within, "within"), |
176 |
|
|
".", new Token(dot, "."), |
177 |
|
|
"atomno", new Token(atomno, "atomno"), |
178 |
|
|
"elemno", tokenElemno, |
179 |
|
|
"_bondedcount", new Token(_bondedcount, "_bondedcount"), |
180 |
|
|
"_groupID", new Token(_groupID, "_groupID"), |
181 |
tim |
1962 |
"_atomID", new Token(_atomID, "_atomID"), |
182 |
tim |
1961 |
"x", new Token(x, "x"), |
183 |
|
|
"y", new Token(y, "y"), |
184 |
|
|
"z", new Token(z, "z"), |
185 |
|
|
"*", new Token(asterisk, "*"), |
186 |
|
|
"all", tokenAll, |
187 |
|
|
"none", new Token(none, "none"), |
188 |
|
|
|
189 |
|
|
}; |
190 |
|
|
|
191 |
|
|
} |
192 |
|
|
|
193 |
tim |
1962 |
#endif |