--- trunk/mdtools/interface_implementation/MakeStamps.cpp 2002/11/18 21:24:02 178 +++ trunk/mdtools/interface_implementation/MakeStamps.cpp 2002/12/06 21:20:42 198 @@ -13,25 +13,86 @@ MoleculeStamp* LinkedMolStamp::match( char* id ){ 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; +} + MakeStamps::MakeStamps(){ int i; my_mols = new LinkedMolStamp*[hash_size]; for( i=0; imatch( the_id ); + return my_mols[key]->extract( the_id ); } return NULL; @@ -96,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 ); + }