ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/MakeStamps.cpp
Revision: 196
Committed: Thu Dec 5 21:37:51 2002 UTC (21 years, 7 months ago) by chuckv
File size: 9237 byte(s)
Log Message:

Working on the clean removal of key Molecule stamps from the Hash table.
stamps will be moved into a persitient linked list.

File Contents

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