--- trunk/mdtools/interface_implementation/MakeStamps.cpp 2002/07/09 18:40:59 11 +++ trunk/mdtools/interface_implementation/MakeStamps.cpp 2002/12/06 21:20:42 198 @@ -3,21 +3,86 @@ #include "MakeStamps.hpp" #include "MoleculeStamp.hpp" +#include "simError.h" +#ifdef IS_MPI +#include "mpiBASS.h" +#endif // is_mpi LinkedMolStamp::~LinkedMolStamp(){ if( mol_stamp != NULL ) delete mol_stamp; if( next != NULL ) delete next; } +void LinkedMolStamp::add( LinkedMolStamp* newbie ){ + + if( next != NULL ) next->add( newbie ); + else{ + next = newbie; + next->setPrev( this ); + } +} + MoleculeStamp* LinkedMolStamp::match( char* id ){ if( mol_stamp != NULL ){ - - if(!strcmp( mol_stamp->getID(), id )) return mol_stamp; - - if( next != NULL ) return next->match( id ); + if(!strcmp( mol_stamp->getID(), id )){ + + // make sure we aren't hiding somebody else with the same name + if(next != NULL ){ + if( next->match( id ) != NULL){ + sprintf( painCave.errMsg, + "Molecule Stamp Error. Two separate of declarations of " + "%s present.\n", + id ); + painCave.isFatal = 1; + simError(); +#ifdef IS_MPI + if( painCave.isEventLoop ){ + if( worldRank == 0 ) mpiInterfaceExit(); + } +#endif //is_mpi + } + else return mol_stamp; + } + else return mol_stamp; + } + } + + if( next != NULL ) return next->match( id ); + + return NULL; +} + +LinkedMolStamp* LinkedMolStamp::extract( char* id ){ + + if( mol_stamp != NULL ){ + if(!strcmp( mol_stamp->getID(), id )){ + + // make sure we aren't hiding somebody else with the same name + if(next != NULL ){ + if( next->match( id ) != NULL){ + sprintf( painCave.errMsg, + "Molecule Stamp Error. Two separate of declarations of " + "%s present.\n", + id ); + painCave.isFatal = 1; + simError(); +#ifdef IS_MPI + if( painCave.isEventLoop ){ + if( worldRank == 0 ) mpiInterfaceExit(); + } +#endif //is_mpi + } + } + + prev->setNext( next ); + if( next != NULL ) next->setPrev( prev ); + return this; + } } + if( next != NULL ) return next->extract( id ); + return NULL; } @@ -27,7 +92,7 @@ MakeStamps::MakeStamps(){ my_mols = new LinkedMolStamp*[hash_size]; for( i=0; imatch( the_id ); + return my_mols[key]->extract( the_id ); } return NULL; @@ -86,9 +157,9 @@ void MakeStamps::addMolStamp( MoleculeStamp* the_stamp linked_mol = new LinkedMolStamp; linked_mol->setStamp( the_stamp ); - linked_mol->setNext( my_mols[key] ); - my_mols[key] = linked_mol; + my_mols[key]->add( linked_mol ); + } @@ -103,21 +174,18 @@ int MakeStamps::moleculeAssign( event* the_event ){ switch( the_event->evt.asmt.asmt_type ){ case STRING: - current_mol->assignString( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.sval ); - return 1; + the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs, + the_event->evt.asmt.rhs.sval ); break; case DOUBLE: - current_mol->assignDouble( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.dval ); - return 1; - break; - + the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs, + the_event->evt.asmt.rhs.dval ); + break; + case INT: - current_mol->assignInt( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.ival ); - return 1; + the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs, + the_event->evt.asmt.rhs.ival ); break; default: @@ -126,7 +194,8 @@ int MakeStamps::moleculeAssign( event* the_event ){ return 0; break; } - return 0; + if( the_event->err_msg != NULL ) return 0; + return 1; } int MakeStamps::moleculeEnd( event* the_event ){ @@ -146,7 +215,6 @@ int MakeStamps::newAtom( event* the_event ){ the_event->err_msg = current_mol->addAtom( current_atom, the_event->evt.blk_index ); if( the_event->err_msg != NULL ) return 0; - return 1; } @@ -172,20 +240,26 @@ int MakeStamps::atomAssign( event* the_event ){ switch( the_event->evt.asmt.asmt_type ){ case STRING: - current_atom->assignString( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.sval ); + the_event->err_msg = + current_atom->assignString( the_event->evt.asmt.lhs, + the_event->evt.asmt.rhs.sval ); + if( the_event->err_msg != NULL ) return 0; return 1; break; case DOUBLE: - current_atom->assignDouble( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.dval ); - return 1; + the_event->err_msg = + current_atom->assignDouble( the_event->evt.asmt.lhs, + the_event->evt.asmt.rhs.dval ); + if( the_event->err_msg != NULL ) return 0; + return 1; break; case INT: - current_atom->assignInt( the_event->evt.asmt.lhs, - the_event->evt.asmt.rhs.ival ); + the_event->err_msg = + current_atom->assignInt( the_event->evt.asmt.lhs, + the_event->evt.asmt.rhs.ival ); + if( the_event->err_msg != NULL ) return 0; return 1; break;