| 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 |
< |
|
| 29 |
< |
if(!strcmp( mol_stamp->getID(), id )) return mol_stamp; |
| 30 |
< |
|
| 31 |
< |
if( next != NULL ) return next->match( id ); |
| 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 " |
| 35 |
> |
"%s present.\n", |
| 36 |
> |
id ); |
| 37 |
> |
painCave.isFatal = 1; |
| 38 |
> |
simError(); |
| 39 |
> |
#ifdef IS_MPI |
| 40 |
> |
if( painCave.isEventLoop ){ |
| 41 |
> |
if( worldRank == 0 ) mpiInterfaceExit(); |
| 42 |
> |
} |
| 43 |
> |
#endif //is_mpi |
| 44 |
> |
} |
| 45 |
> |
else return mol_stamp; |
| 46 |
> |
} |
| 47 |
> |
else return mol_stamp; |
| 48 |
> |
} |
| 49 |
|
} |
| 50 |
|
|
| 51 |
+ |
if( next != NULL ) return next->match( id ); |
| 52 |
+ |
|
| 53 |
|
return NULL; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
+ |
LinkedMolStamp* LinkedMolStamp::extract( char* id ){ |
| 57 |
+ |
|
| 58 |
+ |
if( mol_stamp != NULL ){ |
| 59 |
+ |
if(!strcmp( mol_stamp->getID(), id )){ |
| 60 |
+ |
|
| 61 |
+ |
// make sure we aren't hiding somebody else with the same name |
| 62 |
+ |
if(next != NULL ){ |
| 63 |
+ |
if( next->match( id ) != NULL){ |
| 64 |
+ |
sprintf( painCave.errMsg, |
| 65 |
+ |
"Molecule Stamp Error. Two separate of declarations of " |
| 66 |
+ |
"%s present.\n", |
| 67 |
+ |
id ); |
| 68 |
+ |
painCave.isFatal = 1; |
| 69 |
+ |
simError(); |
| 70 |
+ |
#ifdef IS_MPI |
| 71 |
+ |
if( painCave.isEventLoop ){ |
| 72 |
+ |
if( worldRank == 0 ) mpiInterfaceExit(); |
| 73 |
+ |
} |
| 74 |
+ |
#endif //is_mpi |
| 75 |
+ |
} |
| 76 |
+ |
} |
| 77 |
+ |
|
| 78 |
+ |
prev->setNext( next ); |
| 79 |
+ |
if( next != NULL ) next->setPrev( prev ); |
| 80 |
+ |
return this; |
| 81 |
+ |
} |
| 82 |
+ |
} |
| 83 |
+ |
|
| 84 |
+ |
if( next != NULL ) return next->extract( id ); |
| 85 |
+ |
|
| 86 |
+ |
return NULL; |
| 87 |
+ |
} |
| 88 |
+ |
|
| 89 |
|
MakeStamps::MakeStamps(){ |
| 90 |
|
|
| 91 |
|
int i; |
| 92 |
|
|
| 93 |
|
my_mols = new LinkedMolStamp*[hash_size]; |
| 94 |
|
for( i=0; i<hash_size; i++ ){ |
| 95 |
< |
my_mols[i] = NULL; |
| 95 |
> |
my_mols[i] = new LinkedMolStamp(); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
} |
| 137 |
|
return key; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
< |
MoleculeStamp* MakeStamps::getMolecule( char* the_id ){ |
| 140 |
> |
LinkedMolStamp* MakeStamps::extractMolStamp( char* the_id ){ |
| 141 |
|
int key; |
| 142 |
|
|
| 143 |
|
key = hash( the_id ); |
| 144 |
|
if( my_mols[key] != NULL ){ |
| 145 |
< |
return my_mols[key]->match( the_id ); |
| 145 |
> |
return my_mols[key]->extract( the_id ); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
return NULL; |
| 157 |
|
|
| 158 |
|
linked_mol = new LinkedMolStamp; |
| 159 |
|
linked_mol->setStamp( the_stamp ); |
| 97 |
– |
linked_mol->setNext( my_mols[key] ); |
| 160 |
|
|
| 161 |
< |
my_mols[key] = linked_mol; |
| 161 |
> |
my_mols[key]->add( linked_mol ); |
| 162 |
> |
|
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 174 |
|
switch( the_event->evt.asmt.asmt_type ){ |
| 175 |
|
|
| 176 |
|
case STRING: |
| 177 |
< |
return current_mol->assignString( the_event->evt.asmt.lhs, |
| 177 |
> |
the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs, |
| 178 |
|
the_event->evt.asmt.rhs.sval ); |
| 179 |
|
break; |
| 180 |
|
|
| 181 |
|
case DOUBLE: |
| 182 |
< |
return current_mol->assignDouble( the_event->evt.asmt.lhs, |
| 182 |
> |
the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs, |
| 183 |
|
the_event->evt.asmt.rhs.dval ); |
| 184 |
|
break; |
| 185 |
|
|
| 186 |
|
case INT: |
| 187 |
< |
return current_mol->assignInt( the_event->evt.asmt.lhs, |
| 187 |
> |
the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs, |
| 188 |
|
the_event->evt.asmt.rhs.ival ); |
| 189 |
|
break; |
| 190 |
|
|
| 194 |
|
return 0; |
| 195 |
|
break; |
| 196 |
|
} |
| 197 |
< |
return 0; |
| 197 |
> |
if( the_event->err_msg != NULL ) return 0; |
| 198 |
> |
return 1; |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
int MakeStamps::moleculeEnd( event* the_event ){ |
| 215 |
|
the_event->err_msg = current_mol->addAtom( current_atom, |
| 216 |
|
the_event->evt.blk_index ); |
| 217 |
|
if( the_event->err_msg != NULL ) return 0; |
| 154 |
– |
|
| 218 |
|
return 1; |
| 219 |
|
} |
| 220 |
|
|
| 240 |
|
switch( the_event->evt.asmt.asmt_type ){ |
| 241 |
|
|
| 242 |
|
case STRING: |
| 243 |
< |
current_atom->assignString( the_event->evt.asmt.lhs, |
| 244 |
< |
the_event->evt.asmt.rhs.sval ); |
| 243 |
> |
the_event->err_msg = |
| 244 |
> |
current_atom->assignString( the_event->evt.asmt.lhs, |
| 245 |
> |
the_event->evt.asmt.rhs.sval ); |
| 246 |
> |
if( the_event->err_msg != NULL ) return 0; |
| 247 |
|
return 1; |
| 248 |
|
break; |
| 249 |
|
|
| 250 |
|
case DOUBLE: |
| 251 |
< |
current_atom->assignDouble( the_event->evt.asmt.lhs, |
| 252 |
< |
the_event->evt.asmt.rhs.dval ); |
| 253 |
< |
return 1; |
| 251 |
> |
the_event->err_msg = |
| 252 |
> |
current_atom->assignDouble( the_event->evt.asmt.lhs, |
| 253 |
> |
the_event->evt.asmt.rhs.dval ); |
| 254 |
> |
if( the_event->err_msg != NULL ) return 0; |
| 255 |
> |
return 1; |
| 256 |
|
break; |
| 257 |
|
|
| 258 |
|
case INT: |
| 259 |
< |
current_atom->assignInt( the_event->evt.asmt.lhs, |
| 260 |
< |
the_event->evt.asmt.rhs.ival ); |
| 259 |
> |
the_event->err_msg = |
| 260 |
> |
current_atom->assignInt( the_event->evt.asmt.lhs, |
| 261 |
> |
the_event->evt.asmt.rhs.ival ); |
| 262 |
> |
if( the_event->err_msg != NULL ) return 0; |
| 263 |
|
return 1; |
| 264 |
|
break; |
| 265 |
|
|