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

Comparing trunk/OOPSE-2.0/src/types/MakeStamps.cpp (file contents):
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# 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 );
63 <  else{
64 <    next = newbie;
65 <    next->setPrev( this );
66 <  }
67 < }
60 >  std::map<std::string, MoleculeStamp*>::iterator iter;
61  
62 < MoleculeStamp* LinkedMolStamp::match( char* id ){
63 <
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 <    }
62 >  for (iter=my_mols.begin(); iter!=my_mols.end(); ++iter) {
63 >    delete iter->second;
64    }
94  
95  if( next != NULL ) return next->match( id );
96  
97  return NULL;
98 }
65  
66 < LinkedMolStamp* LinkedMolStamp::extract( char* id ){
66 >  my_mols.clear();
67  
102  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  }
127  
128  if( next != NULL ) return next->extract( id );
129  
130  return NULL;
68   }
69  
70 < MakeStamps::MakeStamps(){
134 <  
135 <  int i;
70 > MoleculeStamp* MakeStamps::getMolStamp( std::string the_id ){
71  
72 <  hash_size = 47;
138 <  hash_shift = 4;
72 >  std::map<std::string, MoleculeStamp*>::iterator iter;
73    
74 <  my_mols = new LinkedMolStamp*[hash_size];
75 <  for( i=0; i<hash_size; i++ ){
76 <    my_mols[i] = new LinkedMolStamp();
74 >  iter = my_mols.find(the_id);
75 >
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 ){
90 >  iter = my_mols.find(molStampName);
91  
92 <  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
172 <
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 +  } else {
106 +    my_mols.insert(std::map<std::string, MoleculeStamp*>::value_type(molStampName, the_stamp));
107    }
183  
184  return key;
108   }
109  
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 );
193  }
194  
195  return NULL;
196 }
110  
198 void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
199
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;
# Line 222 | Line 120 | int MakeStamps::moleculeAssign( event* the_event ){
120      
121    case STRING:
122      the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs,
123 <                                      the_event->evt.asmt.rhs.sval );
123 >                                                    the_event->evt.asmt.rhs.sval );
124      break;
125  
126    case DOUBLE:
127      the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs,
128 <                                      the_event->evt.asmt.rhs.dval );
128 >                                                    the_event->evt.asmt.rhs.dval );
129      break;
130      
131    case INT:
132      the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs,
133 <                                   the_event->evt.asmt.rhs.ival );
133 >                                                 the_event->evt.asmt.rhs.ival );
134      break;
135  
136    default:
# Line 495 | Line 393 | int MakeStamps::bondAssign( event* the_event ){
393      
394    case STRING:
395      current_bond->assignString( the_event->evt.asmt.lhs,
396 <                               the_event->evt.asmt.rhs.sval );
396 >                                the_event->evt.asmt.rhs.sval );
397      return 1;
398      break;
399  
400    case DOUBLE:
401      current_bond->assignDouble( the_event->evt.asmt.lhs,
402 <                               the_event->evt.asmt.rhs.dval );
402 >                                the_event->evt.asmt.rhs.dval );
403      return 1;
404      break;
405  
406    case INT:
407      current_bond->assignInt( the_event->evt.asmt.lhs,
408 <                            the_event->evt.asmt.rhs.ival );
408 >                             the_event->evt.asmt.rhs.ival );
409      return 1;
410      break;
411  
# Line 568 | Line 466 | int MakeStamps::bendAssign( event* the_event ){
466      
467    case STRING:
468      current_bend->assignString( the_event->evt.asmt.lhs,
469 <                               the_event->evt.asmt.rhs.sval );
469 >                                the_event->evt.asmt.rhs.sval );
470      return 1;
471      break;
472  
473    case DOUBLE:
474      current_bend->assignDouble( the_event->evt.asmt.lhs,
475 <                               the_event->evt.asmt.rhs.dval );
475 >                                the_event->evt.asmt.rhs.dval );
476      return 1;
477      break;
478  
479    case INT:
480      current_bend->assignInt( the_event->evt.asmt.lhs,
481 <                            the_event->evt.asmt.rhs.ival );
481 >                             the_event->evt.asmt.rhs.ival );
482      return 1;
483      break;
484  
# Line 649 | Line 547 | int MakeStamps::torsionAssign( event* the_event ){
547      
548    case STRING:
549      current_torsion->assignString( the_event->evt.asmt.lhs,
550 <                               the_event->evt.asmt.rhs.sval );
550 >                                   the_event->evt.asmt.rhs.sval );
551      return 1;
552      break;
553  
554    case DOUBLE:
555      current_torsion->assignDouble( the_event->evt.asmt.lhs,
556 <                               the_event->evt.asmt.rhs.dval );
556 >                                   the_event->evt.asmt.rhs.dval );
557      return 1;
558      break;
559  
560    case INT:
561      current_torsion->assignInt( the_event->evt.asmt.lhs,
562 <                            the_event->evt.asmt.rhs.ival );
562 >                                the_event->evt.asmt.rhs.ival );
563      return 1;
564      break;
565  
# Line 676 | Line 574 | int MakeStamps::torsionMembers( event* the_event ){
574  
575   int MakeStamps::torsionMembers( event* the_event ){
576  
577 <  if( the_event->evt.mbrs.nMembers == 4 ){
577 >
578 >  switch( the_event->evt.mbrs.nMembers ) {
579 >  case 4:
580      
581      current_torsion->members( the_event->evt.mbrs.memberList[0],
582                                the_event->evt.mbrs.memberList[1],
583                                the_event->evt.mbrs.memberList[2],
584                                the_event->evt.mbrs.memberList[3]);
585      return 1;
586 +    break;
587 +  case 3:
588 +
589      
590 <  } else {
590 >    current_torsion->members( the_event->evt.mbrs.memberList[0],
591 >                              the_event->evt.mbrs.memberList[1],
592 >                              the_event->evt.mbrs.memberList[2],
593 >                              -1);
594 >    
595 >    return 1;
596 >    break;
597 >  default:      
598      the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
599 <                                 " in torsion");
599 >                                 "in torsion.");
600      return 0;
601 <
601 >    break;
602    }
603 +  return 0;
604 +  
605   }
606  
607   int MakeStamps::torsionConstraint( event* the_event ){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines