1 |
mmeineke |
10 |
#include <cstdlib> |
2 |
|
|
#include <cstdio> |
3 |
|
|
|
4 |
|
|
#include "MakeStamps.hpp" |
5 |
|
|
#include "MoleculeStamp.hpp" |
6 |
mmeineke |
160 |
#include "simError.h" |
7 |
mmeineke |
10 |
|
8 |
|
|
LinkedMolStamp::~LinkedMolStamp(){ |
9 |
|
|
if( mol_stamp != NULL ) delete mol_stamp; |
10 |
|
|
if( next != NULL ) delete next; |
11 |
|
|
} |
12 |
|
|
|
13 |
|
|
MoleculeStamp* LinkedMolStamp::match( char* id ){ |
14 |
|
|
|
15 |
|
|
if( mol_stamp != NULL ){ |
16 |
|
|
|
17 |
|
|
if(!strcmp( mol_stamp->getID(), id )) return mol_stamp; |
18 |
|
|
|
19 |
|
|
if( next != NULL ) return next->match( id ); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
return NULL; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
MakeStamps::MakeStamps(){ |
26 |
|
|
|
27 |
|
|
int i; |
28 |
|
|
|
29 |
|
|
my_mols = new LinkedMolStamp*[hash_size]; |
30 |
|
|
for( i=0; i<hash_size; i++ ){ |
31 |
|
|
my_mols[i] = NULL; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
MakeStamps::~MakeStamps(){ |
37 |
|
|
|
38 |
|
|
int i; |
39 |
|
|
|
40 |
|
|
for( i=0; i<hash_size; i++ ){ |
41 |
|
|
if( my_mols[i] != NULL ) delete my_mols[i]; |
42 |
|
|
} |
43 |
|
|
delete[] my_mols; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
int MakeStamps::hash( char* text ){ |
47 |
|
|
|
48 |
|
|
register unsigned short int i = 0; // loop counter |
49 |
|
|
int key = 0; // the hash key |
50 |
|
|
|
51 |
|
|
while( text[i] != '\0' ){ |
52 |
|
|
|
53 |
|
|
key = ( ( key << hash_shift ) + text[i] ) % hash_size; |
54 |
|
|
|
55 |
|
|
i++; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
if( key < 0 ){ |
59 |
|
|
|
60 |
|
|
// if the key is less than zero, we've had an overflow error |
61 |
|
|
|
62 |
mmeineke |
160 |
sprintf( painCave.errMsg, |
63 |
mmeineke |
10 |
"There has been an overflow error in the hash key."); |
64 |
mmeineke |
160 |
painCave.isFatal = 1; |
65 |
|
|
simError(); |
66 |
mmeineke |
10 |
} |
67 |
|
|
|
68 |
|
|
return key; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
MoleculeStamp* MakeStamps::getMolecule( char* the_id ){ |
72 |
|
|
int key; |
73 |
|
|
|
74 |
|
|
key = hash( the_id ); |
75 |
|
|
if( my_mols[key] != NULL ){ |
76 |
|
|
return my_mols[key]->match( the_id ); |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
return NULL; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){ |
83 |
|
|
|
84 |
|
|
int key; |
85 |
|
|
LinkedMolStamp* linked_mol; |
86 |
|
|
|
87 |
|
|
key = hash( the_stamp->getID() ); |
88 |
|
|
|
89 |
|
|
linked_mol = new LinkedMolStamp; |
90 |
|
|
linked_mol->setStamp( the_stamp ); |
91 |
|
|
linked_mol->setNext( my_mols[key] ); |
92 |
|
|
|
93 |
|
|
my_mols[key] = linked_mol; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
int MakeStamps::newMolecule( event* the_event ){ |
98 |
|
|
|
99 |
|
|
current_mol = new MoleculeStamp; |
100 |
|
|
return 1; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
int MakeStamps::moleculeAssign( event* the_event ){ |
104 |
|
|
|
105 |
|
|
switch( the_event->evt.asmt.asmt_type ){ |
106 |
|
|
|
107 |
|
|
case STRING: |
108 |
|
|
current_mol->assignString( the_event->evt.asmt.lhs, |
109 |
|
|
the_event->evt.asmt.rhs.sval ); |
110 |
|
|
return 1; |
111 |
|
|
break; |
112 |
|
|
|
113 |
|
|
case DOUBLE: |
114 |
|
|
current_mol->assignDouble( the_event->evt.asmt.lhs, |
115 |
|
|
the_event->evt.asmt.rhs.dval ); |
116 |
|
|
return 1; |
117 |
|
|
break; |
118 |
|
|
|
119 |
|
|
case INT: |
120 |
|
|
current_mol->assignInt( the_event->evt.asmt.lhs, |
121 |
|
|
the_event->evt.asmt.rhs.ival ); |
122 |
|
|
return 1; |
123 |
|
|
break; |
124 |
|
|
|
125 |
|
|
default: |
126 |
|
|
the_event->err_msg = strdup( "MakeStamp error. Invalid molecule" |
127 |
|
|
" assignment type" ); |
128 |
|
|
return 0; |
129 |
|
|
break; |
130 |
|
|
} |
131 |
|
|
return 0; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
int MakeStamps::moleculeEnd( event* the_event ){ |
135 |
|
|
|
136 |
|
|
the_event->err_msg = current_mol->checkMe(); |
137 |
|
|
// if err_msg is set, then something is wrong |
138 |
|
|
if( the_event->err_msg != NULL ) return 0; |
139 |
|
|
|
140 |
|
|
addMolStamp( current_mol ); |
141 |
|
|
return 1; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
int MakeStamps::newAtom( event* the_event ){ |
145 |
|
|
|
146 |
|
|
current_atom = new AtomStamp; |
147 |
|
|
|
148 |
|
|
the_event->err_msg = current_mol->addAtom( current_atom, |
149 |
|
|
the_event->evt.blk_index ); |
150 |
|
|
if( the_event->err_msg != NULL ) return 0; |
151 |
|
|
|
152 |
|
|
return 1; |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
int MakeStamps::atomPosition( event* the_event ){ |
156 |
|
|
|
157 |
|
|
current_atom->setPosition( the_event->evt.pos.x, |
158 |
|
|
the_event->evt.pos.y, |
159 |
|
|
the_event->evt.pos.z ); |
160 |
|
|
return 1; |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
|
164 |
|
|
int MakeStamps::atomOrientation( event* the_event ){ |
165 |
|
|
|
166 |
|
|
current_atom->setOrientation( the_event->evt.ornt.x, |
167 |
|
|
the_event->evt.ornt.y, |
168 |
|
|
the_event->evt.ornt.z ); |
169 |
|
|
return 1; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
int MakeStamps::atomAssign( event* the_event ){ |
173 |
|
|
|
174 |
|
|
switch( the_event->evt.asmt.asmt_type ){ |
175 |
|
|
|
176 |
|
|
case STRING: |
177 |
|
|
current_atom->assignString( the_event->evt.asmt.lhs, |
178 |
|
|
the_event->evt.asmt.rhs.sval ); |
179 |
|
|
return 1; |
180 |
|
|
break; |
181 |
|
|
|
182 |
|
|
case DOUBLE: |
183 |
|
|
current_atom->assignDouble( the_event->evt.asmt.lhs, |
184 |
|
|
the_event->evt.asmt.rhs.dval ); |
185 |
|
|
return 1; |
186 |
|
|
break; |
187 |
|
|
|
188 |
|
|
case INT: |
189 |
|
|
current_atom->assignInt( the_event->evt.asmt.lhs, |
190 |
|
|
the_event->evt.asmt.rhs.ival ); |
191 |
|
|
return 1; |
192 |
|
|
break; |
193 |
|
|
|
194 |
|
|
default: |
195 |
|
|
the_event->err_msg = strdup( "MakeStamp error. Invalid atom" |
196 |
|
|
" assignment type" ); |
197 |
|
|
return 0; |
198 |
|
|
break; |
199 |
|
|
} |
200 |
|
|
return 0; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
int MakeStamps::atomEnd( event* the_event ){ |
204 |
|
|
|
205 |
|
|
the_event->err_msg = current_atom->checkMe(); |
206 |
|
|
if( the_event->err_msg != NULL ) return 0; |
207 |
|
|
|
208 |
|
|
return 1; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
int MakeStamps::newBond( event* the_event ){ |
212 |
|
|
|
213 |
|
|
current_bond = new BondStamp; |
214 |
|
|
|
215 |
|
|
the_event->err_msg = current_mol->addBond( current_bond, |
216 |
|
|
the_event->evt.blk_index ); |
217 |
|
|
if( the_event->err_msg != NULL ) return 0; |
218 |
|
|
|
219 |
|
|
return 1; |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
int MakeStamps::bondAssign( event* the_event ){ |
223 |
|
|
|
224 |
|
|
switch( the_event->evt.asmt.asmt_type ){ |
225 |
|
|
|
226 |
|
|
case STRING: |
227 |
|
|
current_bond->assignString( the_event->evt.asmt.lhs, |
228 |
|
|
the_event->evt.asmt.rhs.sval ); |
229 |
|
|
return 1; |
230 |
|
|
break; |
231 |
|
|
|
232 |
|
|
case DOUBLE: |
233 |
|
|
current_bond->assignDouble( the_event->evt.asmt.lhs, |
234 |
|
|
the_event->evt.asmt.rhs.dval ); |
235 |
|
|
return 1; |
236 |
|
|
break; |
237 |
|
|
|
238 |
|
|
case INT: |
239 |
|
|
current_bond->assignInt( the_event->evt.asmt.lhs, |
240 |
|
|
the_event->evt.asmt.rhs.ival ); |
241 |
|
|
return 1; |
242 |
|
|
break; |
243 |
|
|
|
244 |
|
|
default: |
245 |
|
|
the_event->err_msg = strdup( "MakeStamp error. Invalid bond" |
246 |
|
|
" assignment type" ); |
247 |
|
|
return 0; |
248 |
|
|
break; |
249 |
|
|
} |
250 |
|
|
return 0; |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
int MakeStamps::bondMember( event* the_event ){ |
254 |
|
|
|
255 |
|
|
current_bond->members( the_event->evt.mbr.a, |
256 |
|
|
the_event->evt.mbr.b ); |
257 |
|
|
return 1; |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
int MakeStamps::bondConstraint( event* the_event ){ |
261 |
|
|
|
262 |
|
|
current_bond->constrain( the_event->evt.cnstr ); |
263 |
|
|
return 1; |
264 |
|
|
} |
265 |
|
|
|
266 |
|
|
int MakeStamps::bondEnd( event* the_event ){ |
267 |
|
|
|
268 |
|
|
the_event->err_msg = current_bond->checkMe(); |
269 |
|
|
if( the_event->err_msg != NULL ) return 0; |
270 |
|
|
|
271 |
|
|
return 1; |
272 |
|
|
} |
273 |
|
|
|
274 |
|
|
int MakeStamps::newBend( event* the_event ){ |
275 |
|
|
|
276 |
|
|
current_bend = new BendStamp; |
277 |
|
|
|
278 |
|
|
the_event->err_msg = current_mol->addBend( current_bend, |
279 |
|
|
the_event->evt.blk_index ); |
280 |
|
|
if( the_event->err_msg != NULL ) return 0; |
281 |
|
|
|
282 |
|
|
return 1; |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
int MakeStamps::bendAssign( event* the_event ){ |
286 |
|
|
|
287 |
|
|
switch( the_event->evt.asmt.asmt_type ){ |
288 |
|
|
|
289 |
|
|
case STRING: |
290 |
|
|
current_bend->assignString( the_event->evt.asmt.lhs, |
291 |
|
|
the_event->evt.asmt.rhs.sval ); |
292 |
|
|
return 1; |
293 |
|
|
break; |
294 |
|
|
|
295 |
|
|
case DOUBLE: |
296 |
|
|
current_bend->assignDouble( the_event->evt.asmt.lhs, |
297 |
|
|
the_event->evt.asmt.rhs.dval ); |
298 |
|
|
return 1; |
299 |
|
|
break; |
300 |
|
|
|
301 |
|
|
case INT: |
302 |
|
|
current_bend->assignInt( the_event->evt.asmt.lhs, |
303 |
|
|
the_event->evt.asmt.rhs.ival ); |
304 |
|
|
return 1; |
305 |
|
|
break; |
306 |
|
|
|
307 |
|
|
default: |
308 |
|
|
the_event->err_msg = strdup( "MakeStamp error. Invalid bend" |
309 |
|
|
" assignment type" ); |
310 |
|
|
return 0; |
311 |
|
|
break; |
312 |
|
|
} |
313 |
|
|
return 0; |
314 |
|
|
} |
315 |
|
|
|
316 |
|
|
int MakeStamps::bendMember( event* the_event ){ |
317 |
|
|
|
318 |
|
|
current_bend->members( the_event->evt.mbr.a, |
319 |
|
|
the_event->evt.mbr.b, |
320 |
|
|
the_event->evt.mbr.c ); |
321 |
|
|
return 1; |
322 |
|
|
} |
323 |
|
|
|
324 |
|
|
int MakeStamps::bendConstraint( event* the_event ){ |
325 |
|
|
|
326 |
|
|
current_bend->constrain( the_event->evt.cnstr ); |
327 |
|
|
return 1; |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
int MakeStamps::bendEnd( event* the_event ){ |
331 |
|
|
|
332 |
|
|
the_event->err_msg = current_bend->checkMe(); |
333 |
|
|
if( the_event->err_msg != NULL ) return 0; |
334 |
|
|
|
335 |
|
|
return 1; |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
int MakeStamps::newTorsion( event* the_event ){ |
339 |
|
|
|
340 |
|
|
current_torsion = new TorsionStamp; |
341 |
|
|
|
342 |
|
|
the_event->err_msg = current_mol->addTorsion( current_torsion, |
343 |
|
|
the_event->evt.blk_index ); |
344 |
|
|
if( the_event->err_msg != NULL ) return 0; |
345 |
|
|
|
346 |
|
|
return 1; |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
int MakeStamps::torsionAssign( event* the_event ){ |
350 |
|
|
|
351 |
|
|
switch( the_event->evt.asmt.asmt_type ){ |
352 |
|
|
|
353 |
|
|
case STRING: |
354 |
|
|
current_torsion->assignString( the_event->evt.asmt.lhs, |
355 |
|
|
the_event->evt.asmt.rhs.sval ); |
356 |
|
|
return 1; |
357 |
|
|
break; |
358 |
|
|
|
359 |
|
|
case DOUBLE: |
360 |
|
|
current_torsion->assignDouble( the_event->evt.asmt.lhs, |
361 |
|
|
the_event->evt.asmt.rhs.dval ); |
362 |
|
|
return 1; |
363 |
|
|
break; |
364 |
|
|
|
365 |
|
|
case INT: |
366 |
|
|
current_torsion->assignInt( the_event->evt.asmt.lhs, |
367 |
|
|
the_event->evt.asmt.rhs.ival ); |
368 |
|
|
return 1; |
369 |
|
|
break; |
370 |
|
|
|
371 |
|
|
default: |
372 |
|
|
the_event->err_msg = strdup( "MakeStamp error. Invalid torsion" |
373 |
|
|
" assignment type" ); |
374 |
|
|
return 0; |
375 |
|
|
break; |
376 |
|
|
} |
377 |
|
|
return 0; |
378 |
|
|
} |
379 |
|
|
|
380 |
|
|
int MakeStamps::torsionMember( event* the_event ){ |
381 |
|
|
|
382 |
|
|
current_torsion->members( the_event->evt.mbr.a, |
383 |
|
|
the_event->evt.mbr.b, |
384 |
|
|
the_event->evt.mbr.c, |
385 |
|
|
the_event->evt.mbr.d ); |
386 |
|
|
return 1; |
387 |
|
|
} |
388 |
|
|
|
389 |
|
|
int MakeStamps::torsionConstraint( event* the_event ){ |
390 |
|
|
|
391 |
|
|
current_torsion->constrain( the_event->evt.cnstr ); |
392 |
|
|
return 1; |
393 |
|
|
} |
394 |
|
|
|
395 |
|
|
int MakeStamps::torsionEnd( event* the_event ){ |
396 |
|
|
|
397 |
|
|
the_event->err_msg = current_torsion->checkMe(); |
398 |
|
|
if( the_event->err_msg != NULL ) return 0; |
399 |
|
|
|
400 |
|
|
return 1; |
401 |
|
|
} |