ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/io/BondTypesSectionParser.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-4/src/io/BondTypesSectionParser.cpp (file contents):
Revision 1790 by tim, Mon Nov 29 15:50:05 2004 UTC vs.
Revision 1801 by tim, Tue Nov 30 04:43:29 2004 UTC

# Line 29 | Line 29
29   #include "types/CubicBondType.hpp"
30   #include "types/QuarticBondType.hpp"
31   #include "types/PolynomialBondType.hpp"
32 <
32 > #include "UseTheForce/ForceField.hpp"
33   namespace oopse {
34  
35   BondTypesSectionParser::BondTypesSectionParser() {
36      setSectionName("BondTypes");
37 +
38 +    stringToEnumMap_["Fixed"] =  btFixed;                
39 +    stringToEnumMap_["Harmonic"] =  btHarmonic;                                
40 +    stringToEnumMap_["Cubic"] = btCubic;
41 +    stringToEnumMap_["Quartic"] = btQuartic;
42 +    stringToEnumMap_["Polynomial"] = btPolynomial;
43   }
44  
45   void BondTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
46      StringTokenizer tokenizer(line);
41    std::string at1;
42    std::string at2;
43    std::string bt;
47      BondType* bondType = NULL;
45    double b0;
46    
48      int nTokens = tokenizer.countTokens();
49  
50      if (nTokens < 4) {
# Line 51 | Line 52 | void BondTypesSectionParser::parseLine(ForceField& ff,
52          return;
53      }
54      
55 <    at1 = tokenizer.nextToken();
56 <    at2 = tokenizer.nextToken();
57 <    bt = tokenizer.nextToken();
58 <    b0 = tokenizer.nextTokenAsDouble();
55 >    std::string at1 = tokenizer.nextToken();
56 >    std::string at2 = tokenizer.nextToken();
57 >    BondTypeEnum bt = getBondTypeEnum(tokenizer.nextToken());
58 >    double b0 = tokenizer.nextTokenAsDouble();
59      nTokens -= 4;
60  
61      //switch is a maintain nightmare
62      switch(bt) {
63 <        case "Fixed" :
64 <            bondType = new FixedBondType();
63 >        case btFixed :
64 >            bondType = new FixedBondType(b0);
65              break;
66              
67 <        case "Harmonic" :
67 >        case btHarmonic :
68              if (nTokens < 1) {
69  
70              } else {
# Line 74 | Line 75 | void BondTypesSectionParser::parseLine(ForceField& ff,
75  
76              break;
77  
78 <        case "Cubic" :
78 >        case btCubic :
79              if (nTokens < 4) {
80  
81              } else {
# Line 88 | Line 89 | void BondTypesSectionParser::parseLine(ForceField& ff,
89              }
90              break;
91              
92 <        case "Quartic" :
92 >        case btQuartic :
93              if (nTokens < 5) {
94  
95              } else {
# Line 104 | Line 105 | void BondTypesSectionParser::parseLine(ForceField& ff,
105              }
106              break;
107  
108 <        case "Polynomial" :
108 >        case btPolynomial :
109              if (nTokens < 2 || nTokens % 2 != 0) {
110  
111              } else {
112                  int nPairs = nTokens / 2;
113                  int power;
114                  double coefficient;
115 <                PolynomialBondType pbt = new PolynomialBondType();
115 >                PolynomialBondType* pbt = new PolynomialBondType(b0);
116                  
117                  for (int i = 0; i < nPairs; ++i) {
118                      power = tokenizer.nextTokenAsInt();
# Line 122 | Line 123 | void BondTypesSectionParser::parseLine(ForceField& ff,
123              
124              break;
125  
126 +        case btUnknown :
127          default:
128 +            break;
129              
130      }
131  
# Line 132 | Line 135 | void BondTypesSectionParser::parseLine(ForceField& ff,
135  
136   }
137  
138 + BondTypesSectionParser::BondTypeEnum BondTypesSectionParser::getBondTypeEnum(const std::string& str) {
139 +    std::map<std::string, BondTypeEnum>::iterator i;
140 +    i = stringToEnumMap_.find(str);
141 +
142 +    return i == stringToEnumMap_.end() ? btUnknown : i->second;
143 + }
144 +
145   } //end namespace oopse
146  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines