| 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(){ | 
| 141 | 
  | 
    switch(size) { | 
| 142 | 
  | 
        case 1 : | 
| 143 | 
  | 
            //could be molecule name, atom name and rigidbody name | 
| 144 | 
< | 
            if (names[0] == "*"){ | 
| 145 | 
< | 
                //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(names[0], bs); | 
| 148 | 
< | 
                matchStuntDouble("*", names[0], bs); | 
| 149 | 
< | 
            }  | 
| 144 | 
> | 
            matchMolecule(names[0], bs); | 
| 145 | 
> | 
            matchStuntDouble("*", names[0], bs); | 
| 146 | 
  | 
             | 
| 147 | 
  | 
            break; | 
| 148 | 
  | 
        case 2: | 
| 149 | 
  | 
            //could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody) | 
| 150 | 
< | 
            matchRigidAtoms("*", names[0], names[1], bs); | 
| 151 | 
< | 
            matchStuntDouble(names[0], names[1], bs); | 
| 150 | 
> | 
 | 
| 151 | 
> | 
            if (!isInteger(names[1])){ | 
| 152 | 
> | 
                matchRigidAtoms("*", names[0], names[1], bs); | 
| 153 | 
> | 
                matchStuntDouble(names[0], names[1], bs); | 
| 154 | 
> | 
            } else { | 
| 155 | 
> | 
                int internalIndex = lexi_cast<int>(names[1]); | 
| 156 | 
> | 
                if (internalIndex < 0) { | 
| 157 | 
> | 
                    std::cerr << names[0] << ". " << names[1] << " is an invalid name" << std::endl;            | 
| 158 | 
> | 
                } else { | 
| 159 | 
> | 
                    matchInternalIndex(names[0], internalIndex, bs); | 
| 160 | 
> | 
                } | 
| 161 | 
> | 
            } | 
| 162 | 
  | 
             | 
| 163 | 
  | 
            break; | 
| 164 | 
  | 
        case 3: | 
| 228 | 
  | 
    return Wildcard::wildcardfit (wildcard.c_str(), str.c_str()); | 
| 229 | 
  | 
} | 
| 230 | 
  | 
 | 
| 231 | 
+ | 
 | 
| 232 | 
+ | 
void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, BitSet& bs){ | 
| 233 | 
+ | 
 | 
| 234 | 
+ | 
    std::map<std::string, TreeNode*>::iterator foundIter; | 
| 235 | 
+ | 
    SimInfo::MoleculeIterator mi; | 
| 236 | 
+ | 
    Molecule* mol; | 
| 237 | 
+ | 
 | 
| 238 | 
+ | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 239 | 
+ | 
            | 
| 240 | 
+ | 
        if (isMatched(mol->getMoleculeName(), name) ) { | 
| 241 | 
+ | 
            int natoms = mol->getNAtoms(); | 
| 242 | 
+ | 
            int nrigidbodies = mol->getNRigidBodies(); | 
| 243 | 
+ | 
            if (internalIndex >= natoms + nrigidbodies) { | 
| 244 | 
+ | 
                continue; | 
| 245 | 
+ | 
            } else if (internalIndex < natoms) { | 
| 246 | 
+ | 
                bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex()); | 
| 247 | 
+ | 
                continue; | 
| 248 | 
+ | 
            } else if ( internalIndex < natoms + nrigidbodies) { | 
| 249 | 
+ | 
                bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex()); | 
| 250 | 
+ | 
            } | 
| 251 | 
+ | 
        } | 
| 252 | 
+ | 
         | 
| 253 | 
+ | 
    }     | 
| 254 | 
+ | 
     | 
| 255 | 
  | 
} | 
| 256 | 
+ | 
 | 
| 257 | 
+ | 
 bool NameFinder::isInteger(const std::string str) { | 
| 258 | 
+ | 
    for(int i =0; i < str.size(); ++i){ | 
| 259 | 
+ | 
        if (!std::isdigit(str[i])) { | 
| 260 | 
+ | 
            return false; | 
| 261 | 
+ | 
        } | 
| 262 | 
+ | 
    } | 
| 263 | 
+ | 
 | 
| 264 | 
+ | 
    return true; | 
| 265 | 
+ | 
 } | 
| 266 | 
+ | 
 | 
| 267 | 
+ | 
} |