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

Comparing trunk/OOPSE-3.0/src/selection/NameFinder.cpp (file contents):
Revision 1968 by tim, Fri Feb 4 04:57:04 2005 UTC vs.
Revision 1972 by tim, Fri Feb 4 22:39:26 2005 UTC

# Line 40 | Line 40 | namespace oopse {
40   */
41   #include "selection/NameFinder.hpp"
42   #include "utils/wildcards.hpp"
43 + #include "utils/StringTokenizer.hpp"
44 + #include "primitives/Molecule.hpp"
45   namespace oopse {
46  
47   TreeNode::~TreeNode(){
# Line 52 | Line 54 | NameFinder::NameFinder(SimInfo* info) : info_(info), r
54  
55  
56   NameFinder::NameFinder(SimInfo* info) : info_(info), root_(NULL){
57 <    nStuntDouble_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies()
57 >    nStuntDouble_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies();
58      loadNames();
59   }
60  
# Line 72 | Line 74 | void NameFinder::loadNames() {
74      RigidBody* rb;
75  
76      root_ = new TreeNode;
77 <    root_->bs.resize(nStuntDobule_);
77 >    root_->bs.resize(nStuntDouble_);
78      root_->bs.setAll(); //
79      
80      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
81 <        TreeNode* currentMolNode;            
81 >          
82          std::string molName = mol->getMoleculeName();
83 <
82 <        foundIter = root_->children.find(molName);
83 <        if ( foundIter  == root_->children.end()) {
84 <            currentMolNode = new TreeNode;
85 <            currentMolNode->name = molName;
86 <            currentMolNode->bs.resize(nStuntDouble_);
87 <        }else {
88 <            currentMolNode = i->second;
89 <        }
83 >         TreeNode* currentMolNode = createNode(root_, molName);
84          
85          for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
86              std::string atomName = atom->getType();
87 <            TreeNode* currentAtomNode;
88 <            foundIter = currentMolNode->children.find(molName);
95 <            if (foundIter == currentMolNode->children.end()) {
96 <                currentAtomNode = new TreeNode;
97 <                currentAtomNode->name = atomName;
98 <                currentAtomNode->bs.resize(nStuntDouble_);
99 <            } else {
100 <                currentAtomNode = foundIter->second;
101 <            }
87 >            TreeNode* currentAtomNode = createNode(currentMolNode, atomName);
88 >            
89              currentMolNode->bs.setBitOn(atom->getGlobalIndex());
90              currentAtomNode->bs.setBitOn(atom->getGlobalIndex());
91          }
92  
93          for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
94 <            std::string rbName = atom->getType();
95 <            TreeNode* currentRbNode;
109 <            foundIter = currentMolNode->children.find(molName);
110 <            if (foundIter == currentMolNode->children.end()) {
111 <                currentRbNode = new TreeNode;
112 <                currentRbNode->name = rbName;
113 <                currentRbNode->bs.resize(nStuntDouble_);
114 <            } else {
115 <                currentRbNode = foundIter->second;
116 <            }
94 >            std::string rbName = rb->getType();
95 >            TreeNode* currentRbNode = createNode(currentMolNode, rbName);
96              
97              currentMolNode->bs.setBitOn(rb->getGlobalIndex());
98              currentRbNode->bs.setBitOn(rb->getGlobalIndex());
99  
100              //create nodes for atoms belong to this rigidbody
101 <            for(atom = rb->beginAtom(ai); rb != NULL; atom = rb->nextAtom(ai)) {
101 >            for(atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
102                  std::string rbAtomName = atom->getType();
103 <                TreeNode* currentRbAtomNode;
104 <                foundIter = currentRbNode->children.find(molName);
126 <                if (foundIter == currentRbNode->children.end()) {
127 <                    currentRbAtomNode = new TreeNode;
128 <                    currentRbAtomNode->name = rbAtomName;
129 <                    currentRbAtomNode->bs.resize(nStuntDouble_);
130 <                } else {
131 <                    currentRbAtomNode = foundIter->second;
132 <                }
103 >                TreeNode* currentRbAtomNode = createNode(currentRbNode, rbName);;
104 >
105                  currentRbAtomNode->bs.setBitOn(atom->getGlobalIndex());
106              }
107  
# Line 137 | Line 109 | void NameFinder::loadNames() {
109          
110      }    
111  
112 <    std::map<std::string, TreeNode*>::iterator i;
113 <    for( i = root_->children.begin(); i != ; ++i){
114 <        i->bs =
112 > }
113 >
114 > TreeNode* NameFinder::createNode(TreeNode* parent, const std::string& name) {
115 >    TreeNode* node;    
116 >    std::map<std::string, TreeNode*>::iterator foundIter;
117 >    foundIter = parent->children.find(name);
118 >    if ( foundIter  == parent->children.end()) {
119 >        node = new TreeNode;
120 >        node->name = name;
121 >        node->bs.resize(nStuntDouble_);
122 >        parent->children.insert(std::make_pair(name, node));
123 >    }else {
124 >        node = foundIter->second;
125      }
126 +    return node;
127   }
128  
129 < bool NameFinder::match(const std::string& name, BitSet& bs){
130 <
131 <    bool error = true;
129 > BitSet NameFinder::match(const std::string& name){
130 >    BitSet bs(nStuntDouble_);
131 >  
132      StringTokenizer tokenizer(name, ".");
133  
134      std::vector<std::string> names;
# Line 161 | Line 144 | bool NameFinder::match(const std::string& name, BitSet
144                  //if all molecules are selected, we don't need to do the matching, just set all of the bits
145                  bs.setAll();
146              } else{
147 <                matchMolecule(name[0]);
148 <                matchStuntDouble("*", names[0]);
147 >                matchMolecule(names[0], bs);
148 >                matchStuntDouble("*", names[0], bs);
149              }
150              
151              break;
152          case 2:
153              //could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody)
154              matchRigidAtoms("*", names[0], names[1], bs);
155 <            matchStuntDouble(names[0], names[1]);
155 >            matchStuntDouble(names[0], names[1], bs);
156              
157              break;
158          case 3:
159              //must be molecule.rigidbody.*
160 <            matchRigidAtoms(names[0], names[1], names[2], bs)
160 >            matchRigidAtoms(names[0], names[1], names[2], bs);
161              break;
162 <        default:            
162 >        default:      
163 >            std::cerr << "invalid name: " << name << std::endl;
164              break;          
165      }
166  
167 <    return matched;
167 >    return bs;
168   }
169  
170   void NameFinder::matchMolecule(const std::string& molName, BitSet& bs) {
171      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
172      std::vector<TreeNode*>::iterator i;
173      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
174 <        bs |= i->bs;
174 >        bs |= (*i)->bs;
175      }    
176   }
177  
# Line 198 | Line 182 | void NameFinder::matchStuntDouble(const std::string& m
182          std::vector<TreeNode*> sdNodes = getMatchedChildren(*i, sdName);  
183          std::vector<TreeNode*>::iterator j;
184          for (j = sdNodes.begin(); j != sdNodes.end(); ++j) {
185 <            bs |= j->bs;
185 >            bs |= (*j)->bs;
186          }
187      }
188  
# Line 214 | Line 198 | void NameFinder::matchRigidAtoms(const std::string& mo
198              std::vector<TreeNode*> rbAtomNodes = getMatchedChildren(*j, rbAtomName);
199              std::vector<TreeNode*>::iterator k;
200              for(k = rbAtomNodes.begin(); k != rbAtomNodes.end(); ++k){
201 <                bs |= k->bs;
201 >                bs |= (*k)->bs;
202              }
203          }
204      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines