# | Line 42 | Line 42 | |
---|---|---|
42 | #include "utils/wildcards.hpp" | |
43 | #include "utils/StringTokenizer.hpp" | |
44 | #include "primitives/Molecule.hpp" | |
45 | + | #include "utils/StringUtils.hpp" |
46 | namespace oopse { | |
47 | ||
48 | TreeNode::~TreeNode(){ | |
# | Line 151 | Line 152 | BitSet NameFinder::match(const std::string& name){ | |
152 | break; | |
153 | case 2: | |
154 | //could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody) | |
155 | < | matchRigidAtoms("*", names[0], names[1], bs); |
156 | < | matchStuntDouble(names[0], names[1], bs); |
155 | > | |
156 | > | if (!isInteger(names[1])){ |
157 | > | matchRigidAtoms("*", names[0], names[1], bs); |
158 | > | matchStuntDouble(names[0], names[1], bs); |
159 | > | } else { |
160 | > | int internalIndex = lexi_cast<int>(names[1]); |
161 | > | if (internalIndex < 0) { |
162 | > | std::cerr << names[0] << ". " << names[1] << " is an invalid name" << std::endl; |
163 | > | } else { |
164 | > | matchInternalIndex(names[0], internalIndex, bs); |
165 | > | } |
166 | > | } |
167 | ||
168 | break; | |
169 | case 3: | |
# | Line 222 | Line 233 | bool NameFinder::isMatched(const std::string& str, con | |
233 | return Wildcard::wildcardfit (wildcard.c_str(), str.c_str()); | |
234 | } | |
235 | ||
236 | + | |
237 | + | void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, BitSet& bs){ |
238 | + | |
239 | + | std::map<std::string, TreeNode*>::iterator foundIter; |
240 | + | SimInfo::MoleculeIterator mi; |
241 | + | Molecule* mol; |
242 | + | |
243 | + | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
244 | + | |
245 | + | if (isMatched(mol->getMoleculeName(), name) ) { |
246 | + | int natoms = mol->getNAtoms(); |
247 | + | int nrigidbodies = mol->getNRigidBodies(); |
248 | + | if (internalIndex >= natoms + nrigidbodies) { |
249 | + | continue; |
250 | + | } else if (internalIndex < natoms) { |
251 | + | bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex()); |
252 | + | continue; |
253 | + | } else if ( internalIndex < natoms + nrigidbodies) { |
254 | + | bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex()); |
255 | + | } |
256 | + | } |
257 | + | |
258 | + | } |
259 | + | |
260 | } | |
261 | + | |
262 | + | bool NameFinder::isInteger(const std::string str) { |
263 | + | for(int i =0; i < str.size(); ++i){ |
264 | + | if (!std::isdigit(str[i])) { |
265 | + | return false; |
266 | + | } |
267 | + | } |
268 | + | |
269 | + | return true; |
270 | + | } |
271 | + | |
272 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |