# | Line 49 | Line 49 | namespace oopse { | |
---|---|---|
49 | namespace oopse { | |
50 | ||
51 | ||
52 | < | SelectionEvaluator::SelectionEvaluator(SimInfo* si) : info(si), finder(info), isLoaded_(false){ |
53 | < | |
52 | > | SelectionEvaluator::SelectionEvaluator(SimInfo* si) |
53 | > | : info(si), nameFinder(info), distanceFinder(info), indexFinder(info), isLoaded_(false){ |
54 | > | |
55 | > | nStuntDouble = info->getNGlobalAtoms() + info->getNRigidBodies(); |
56 | } | |
57 | ||
58 | bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) { | |
# | Line 84 | Line 86 | void SelectionEvaluator::clearState() { | |
86 | } | |
87 | ||
88 | void SelectionEvaluator::clearState() { | |
87 | – | //for (int i = scriptLevelMax; --i >= 0; ) |
88 | – | // stack[i].clear(); |
89 | – | //scriptLevel = 0; |
89 | error = false; | |
90 | errorMessage = ""; | |
91 | } | |
# | Line 102 | Line 101 | bool SelectionEvaluator::loadScriptFileInternal(const | |
101 | } | |
102 | ||
103 | bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { | |
104 | < | ifstream ifs(filename.c_str()); |
104 | > | std::ifstream ifs(filename.c_str()); |
105 | if (!ifs.is_open()) { | |
106 | return false; | |
107 | } | |
# | Line 181 | Line 180 | void SelectionEvaluator::instructionDispatchLoop(BitSe | |
180 | case Token::name: | |
181 | stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value))); | |
182 | break; | |
183 | + | case Token::index: |
184 | + | stack.push(indexInstruction(instruction.value)); |
185 | break; | |
186 | case Token::identifier: | |
187 | stack.push(lookupValue(boost::any_cast<std::string>(instruction.value))); | |
# | Line 211 | Line 212 | BitSet SelectionEvaluator::comparatorInstruction(const | |
212 | float comparisonValue = boost::any_cast<float>(instruction.value); | |
213 | float propertyValue; | |
214 | BitSet bs(nStuntDouble); | |
215 | + | bs.clearAll(); |
216 | ||
217 | SimInfo::MoleculeIterator mi; | |
218 | Molecule* mol; | |
# | Line 225 | Line 227 | BitSet SelectionEvaluator::comparatorInstruction(const | |
227 | compareProperty(atom, bs, property, comparator, comparisonValue); | |
228 | } | |
229 | ||
228 | – | //change the positions of atoms which belong to the rigidbodies |
230 | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | |
231 | compareProperty(rb, bs, property, comparator, comparisonValue); | |
232 | } | |
# | Line 277 | Line 278 | void SelectionEvaluator::withinInstruction(const Token | |
278 | } | |
279 | ||
280 | void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs){ | |
281 | < | |
281 | > | |
282 | boost::any withinSpec = instruction.value; | |
283 | + | float distance; |
284 | if (withinSpec.type() == typeid(float)){ | |
285 | < | // |
286 | < | return; |
285 | > | distance = boost::any_cast<float>(withinSpec); |
286 | > | } else if (withinSpec.type() == typeid(int)) { |
287 | > | distance = boost::any_cast<int>(withinSpec); |
288 | > | } else { |
289 | > | evalError("casting error in withinInstruction"); |
290 | > | bs.clearAll(); |
291 | } | |
292 | ||
293 | < | evalError("Unrecognized within parameter"); |
293 | > | bs = distanceFinder.find(bs, distance); |
294 | } | |
295 | ||
296 | void SelectionEvaluator::define() { | |
# | Line 292 | Line 298 | void SelectionEvaluator::define() { | |
298 | ||
299 | std::string variable = boost::any_cast<std::string>(statement[1].value); | |
300 | ||
301 | < | variables.insert(std::make_pair(variable, expression(statement, 2))); |
301 | > | variables.insert(VariablesType::value_type(variable, expression(statement, 2))); |
302 | } | |
303 | ||
304 | ||
# | Line 311 | Line 317 | void SelectionEvaluator::predefine(const std::string& | |
317 | int tok = statement[1].tok; | |
318 | if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { | |
319 | std::string variable = boost::any_cast<std::string>(statement[1].value); | |
320 | < | variables.insert(std::make_pair(variable, statement)); |
320 | > | variables.insert(VariablesType::value_type(variable, statement)); |
321 | ||
322 | } else { | |
323 | evalError("invalid variable name:" + script); | |
# | Line 334 | Line 340 | BitSet SelectionEvaluator::lookupValue(const std::stri | |
340 | ||
341 | BitSet SelectionEvaluator::lookupValue(const std::string& variable){ | |
342 | ||
343 | + | BitSet bs(nStuntDouble); |
344 | std::map<std::string, boost::any>::iterator i = variables.find(variable); | |
345 | < | |
345 | > | |
346 | if (i != variables.end()) { | |
347 | if (i->second.type() == typeid(BitSet)) { | |
348 | return boost::any_cast<BitSet>(i->second); | |
349 | } else if (i->second.type() == typeid(std::vector<Token>)){ | |
350 | < | BitSet bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); |
350 | > | bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); |
351 | i->second = bs; /**@todo fixme */ | |
352 | return bs; | |
353 | } | |
354 | } else { | |
355 | unrecognizedIdentifier(variable); | |
356 | } | |
357 | + | |
358 | + | return bs; |
359 | } | |
360 | ||
361 | BitSet SelectionEvaluator::nameInstruction(const std::string& name){ | |
362 | ||
363 | < | return finder.match(name); |
363 | > | return nameFinder.match(name); |
364 | ||
365 | } | |
366 | ||
# | Line 375 | Line 384 | BitSet SelectionEvaluator::evaluate() { | |
384 | BitSet SelectionEvaluator::evaluate() { | |
385 | BitSet bs(nStuntDouble); | |
386 | if (isLoaded_) { | |
387 | + | pc = 0; |
388 | instructionDispatchLoop(bs); | |
389 | } | |
390 | ||
391 | return bs; | |
392 | } | |
383 | – | |
384 | – | //BitSet SelectionEvaluator::evaluate(int frameNo) { |
385 | – | // |
386 | – | //} |
393 | ||
394 | + | BitSet SelectionEvaluator::indexInstruction(const boost::any& value) { |
395 | + | BitSet bs(nStuntDouble); |
396 | + | |
397 | + | if (value.type() == typeid(int)) { |
398 | + | int index = boost::any_cast<int>(value); |
399 | + | if (index < 0 || index >= bs.size()) { |
400 | + | invalidIndex(index); |
401 | + | } else { |
402 | + | bs = indexFinder.find(index); |
403 | + | } |
404 | + | } else if (value.type() == typeid(std::pair<int, int>)) { |
405 | + | std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value); |
406 | + | assert(indexRange.first <= indexRange.second); |
407 | + | if (indexRange.first < 0 || indexRange.second >= bs.size()) { |
408 | + | invalidIndexRange(indexRange); |
409 | + | }else { |
410 | + | bs = indexFinder.find(indexRange.first, indexRange.second); |
411 | + | } |
412 | + | } |
413 | + | |
414 | + | return bs; |
415 | } | |
416 | + | |
417 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |