ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/types/MakeStamps.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/types/MakeStamps.cpp (file contents):
Revision 1957 by tim, Tue Jan 25 17:45:23 2005 UTC vs.
Revision 2187 by tim, Wed Apr 13 18:41:17 2005 UTC

# Line 52 | Line 52 | LinkedMolStamp::~LinkedMolStamp(){
52   #include "io/mpiBASS.h"
53   #endif // is_mpi
54  
55 < LinkedMolStamp::~LinkedMolStamp(){
56 <  if( mol_stamp != NULL ) delete mol_stamp;
57 <  if( next != NULL ) delete next;
55 > MakeStamps::MakeStamps(){
56   }
57  
58 < void LinkedMolStamp::add( LinkedMolStamp* newbie ){
58 > MakeStamps::~MakeStamps(){
59    
60 <  if( next != NULL ) next->add( newbie );
61 <  else{
62 <    next = newbie;
63 <    next->setPrev( this );
60 >  std::map<std::string, MoleculeStamp*>::iterator iter;
61 >
62 >  for (iter=my_mols.begin(); iter!=my_mols.end(); ++iter) {
63 >    delete iter->second;
64    }
67 }
65  
66 < MoleculeStamp* LinkedMolStamp::match( char* id ){
66 >  my_mols.clear();
67  
71  if( mol_stamp != NULL ){
72    if(!strcmp( mol_stamp->getID(), id )){
73      
74      // make sure we aren't hiding somebody else with the same name
75      if(next != NULL ){
76        if( next->match( id ) != NULL){
77          sprintf( painCave.errMsg,
78                   "Molecule Stamp Error. Two separate of declarations of "
79                   "%s present.\n",
80                   id );
81          painCave.isFatal = 1;
82          simError();
83 #ifdef IS_MPI
84          if( painCave.isEventLoop ){
85            if( worldRank == 0 ) mpiInterfaceExit();
86          }
87 #endif //is_mpi
88        }
89        else return mol_stamp;
90      }
91      else  return mol_stamp;
92    }
93  }
94  
95  if( next != NULL ) return next->match( id );
96  
97  return NULL;
68   }
69  
70 < LinkedMolStamp* LinkedMolStamp::extract( char* id ){
70 > MoleculeStamp* MakeStamps::getMolStamp( std::string the_id ){
71  
72 <  if( mol_stamp != NULL ){
103 <    if(!strcmp( mol_stamp->getID(), id )){
104 <      
105 <      // make sure we aren't hiding somebody else with the same name
106 <      if(next != NULL ){
107 <        if( next->match( id ) != NULL){
108 <          sprintf( painCave.errMsg,
109 <                   "Molecule Stamp Error. Two separate of declarations of "
110 <                   "%s present.\n",
111 <                   id );
112 <          painCave.isFatal = 1;
113 <          simError();
114 < #ifdef IS_MPI
115 <          if( painCave.isEventLoop ){
116 <            if( worldRank == 0 ) mpiInterfaceExit();
117 <          }
118 < #endif //is_mpi
119 <        }
120 <      }
121 <          
122 <      prev->setNext( next );
123 <      if( next != NULL ) next->setPrev( prev );
124 <      return this;
125 <    }
126 <  }
72 >  std::map<std::string, MoleculeStamp*>::iterator iter;
73    
74 <  if( next != NULL ) return next->extract( id );
129 <  
130 <  return NULL;
131 < }
74 >  iter = my_mols.find(the_id);
75  
76 < MakeStamps::MakeStamps(){
77 <  
78 <  int i;
79 <
137 <  hash_size = 47;
138 <  hash_shift = 4;
139 <  
140 <  my_mols = new LinkedMolStamp*[hash_size];
141 <  for( i=0; i<hash_size; i++ ){
142 <    my_mols[i] = new LinkedMolStamp();
76 >  if (iter == my_mols.end()) {
77 >    return NULL;
78 >  } else {
79 >    return iter->second;
80    }
81  
82   }
83  
84 < MakeStamps::~MakeStamps(){
84 > void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
85    
86 <  int i;
86 >  std::map<std::string, MoleculeStamp*>::iterator iter;
87  
88 <  for( i=0; i<hash_size; i++ ){
152 <    if( my_mols[i] != NULL ) delete my_mols[i];
153 <  }
154 <  delete[] my_mols;
155 < }
88 >  std::string molStampName(the_stamp->getID());
89  
90 < int MakeStamps::hash( char* text ){
158 <
159 <  register unsigned short int i = 0; // loop counter
160 <  int key = 0; // the hash key
161 <
162 <  while( text[i] != '\0' ){
163 <
164 <    key = ( ( key << hash_shift ) + text[i] ) % hash_size;
165 <    
166 <    i++;
167 <  }
168 <  
169 <  if( key < 0 ){
170 <
171 <    // if the key is less than zero, we've had an overflow error
90 >  iter = my_mols.find(molStampName);
91  
92 +  if (iter != my_mols.end()) {
93      sprintf( painCave.errMsg,
94 <             "There has been an overflow error in the MakeStamps hash key.");
94 >             "Molecule Stamp Error. Two separate of declarations of "
95 >             "%s present.\n",
96 >             the_stamp->getID());
97      painCave.isFatal = 1;
98      simError();
99   #ifdef IS_MPI
# Line 179 | Line 101 | int MakeStamps::hash( char* text ){
101        if( worldRank == 0 ) mpiInterfaceExit();
102      }
103   #endif //is_mpi
104 <  }
105 <  
106 <  return key;
185 < }
186 <
187 < LinkedMolStamp* MakeStamps::extractMolStamp( char* the_id ){
188 <  int key;
189 <  
190 <  key = hash( the_id );
191 <  if( my_mols[key] != NULL ){
192 <    return my_mols[key]->extract( the_id );
104 >    
105 >  } else {
106 >    my_mols.insert(std::map<std::string, MoleculeStamp*>::value_type(molStampName, the_stamp));
107    }
194  
195  return NULL;
108   }
109  
198 void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
110  
200  int key;
201  LinkedMolStamp* linked_mol;
202  
203  key = hash( the_stamp->getID() );
204
205  linked_mol = new LinkedMolStamp;
206  linked_mol->setStamp( the_stamp );
207
208  my_mols[key]->add( linked_mol );
209
210 }
211
212
111   int MakeStamps::newMolecule( event* the_event ){
112    
113    current_mol = new MoleculeStamp;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines