ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/SelectionEvaluator.cpp
(Generate patch)

Comparing trunk/src/selection/SelectionEvaluator.cpp (file contents):
Revision 288 by tim, Fri Feb 4 22:39:26 2005 UTC vs.
Revision 413 by tim, Wed Mar 9 17:30:29 2005 UTC

# 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 102 | Line 104 | bool SelectionEvaluator::loadScriptFileInternal(const
104   }
105  
106   bool SelectionEvaluator::loadScriptFileInternal(const  std::string & filename) {
107 <    ifstream ifs(filename.c_str());
107 >  std::ifstream ifs(filename.c_str());
108      if (!ifs.is_open()) {
109          return false;
110      }
# Line 181 | Line 183 | void SelectionEvaluator::instructionDispatchLoop(BitSe
183        case Token::name:
184          stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
185          break;
186 +      case Token::index:
187 +        stack.push(indexInstruction(instruction.value));
188          break;
189        case Token::identifier:
190          stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
# Line 211 | Line 215 | BitSet SelectionEvaluator::comparatorInstruction(const
215      float comparisonValue = boost::any_cast<float>(instruction.value);
216      float propertyValue;
217      BitSet bs(nStuntDouble);
218 +    bs.clearAll();
219      
220      SimInfo::MoleculeIterator mi;
221      Molecule* mol;
# Line 277 | Line 282 | void SelectionEvaluator::withinInstruction(const Token
282   }
283  
284   void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs){
285 <
285 >    
286      boost::any withinSpec = instruction.value;
287 +    float distance;
288      if (withinSpec.type() == typeid(float)){
289 <        //
290 <        return;
289 >        distance = boost::any_cast<float>(withinSpec);
290 >    } else if (withinSpec.type() == typeid(int)) {
291 >        distance = boost::any_cast<int>(withinSpec);    
292 >    } else {
293 >        evalError("casting error in withinInstruction");
294 >        bs.clearAll();
295      }
296      
297 <    evalError("Unrecognized within parameter");
297 >    bs = distanceFinder.find(bs, distance);            
298   }
299  
300   void SelectionEvaluator::define() {
# Line 292 | Line 302 | void SelectionEvaluator::define() {
302  
303      std::string variable = boost::any_cast<std::string>(statement[1].value);
304  
305 <    variables.insert(std::make_pair(variable, expression(statement, 2)));
305 >    variables.insert(VariablesType::value_type(variable, expression(statement, 2)));
306   }
307  
308  
# Line 311 | Line 321 | void SelectionEvaluator::predefine(const std::string&
321              int tok = statement[1].tok;
322              if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) {
323                  std::string variable = boost::any_cast<std::string>(statement[1].value);
324 <                variables.insert(std::make_pair(variable, statement));
324 >                variables.insert(VariablesType::value_type(variable, statement));
325  
326              } else {
327                  evalError("invalid variable name:" + script);
# Line 334 | Line 344 | BitSet SelectionEvaluator::lookupValue(const std::stri
344  
345   BitSet SelectionEvaluator::lookupValue(const std::string& variable){
346  
347 +    BitSet bs(nStuntDouble);
348      std::map<std::string, boost::any>::iterator i = variables.find(variable);
349 <
349 >    
350      if (i != variables.end()) {
351          if (i->second.type() == typeid(BitSet)) {
352              return boost::any_cast<BitSet>(i->second);
353          } else if (i->second.type() ==  typeid(std::vector<Token>)){
354 <            BitSet bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
354 >            bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
355              i->second =  bs; /**@todo fixme */
356              return bs;
357          }
358      } else {
359          unrecognizedIdentifier(variable);
360      }
361 +
362 +    return bs;
363   }
364  
365   BitSet SelectionEvaluator::nameInstruction(const std::string& name){
366      
367 <    return finder.match(name);
367 >    return nameFinder.match(name);
368  
369   }    
370  
# Line 375 | Line 388 | BitSet SelectionEvaluator::evaluate() {
388   BitSet SelectionEvaluator::evaluate() {
389      BitSet bs(nStuntDouble);
390      if (isLoaded_) {
391 +        pc = 0;
392          instructionDispatchLoop(bs);
393      }
394  
395      return bs;
396   }
383        
384 //BitSet SelectionEvaluator::evaluate(int frameNo) {
385 //
386 //}
397  
398 + BitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
399 +    BitSet bs(nStuntDouble);
400 +
401 +    if (value.type() == typeid(int)) {
402 +        int index = boost::any_cast<int>(value);
403 +        if (index < 0 || index >= bs.size()) {
404 +            invalidIndex(index);
405 +        } else {
406 +            indexFinder.find(index);
407 +        }
408 +    } else if (value.type() == typeid(std::pair<int, int>)) {
409 +        std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value);
410 +        assert(indexRange.first <= indexRange.second);
411 +        if (indexRange.first < 0 || indexRange.second >= bs.size()) {
412 +            invalidIndexRange(indexRange);
413 +        }else {
414 +            indexFinder.find(indexRange.first, indexRange.second);
415 +        }
416 +    }
417 +
418 +    return bs;
419   }
420 +
421 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines