--- trunk/src/selection/SelectionEvaluator.hpp 2005/03/09 17:30:29 413 +++ trunk/src/selection/SelectionEvaluator.hpp 2005/12/02 15:38:03 770 @@ -48,153 +48,155 @@ #include #include "brains/SimInfo.hpp" -#include "selection/Token.hpp" +#include "selection/SelectionToken.hpp" #include "selection/SelectionCompiler.hpp" #include "selection/NameFinder.hpp" #include "selection/DistanceFinder.hpp" #include "selection/IndexFinder.hpp" -#include "utils/BitSet.hpp" +#include "utils/OOPSEBitSet.hpp" #include "primitives/StuntDouble.hpp" #include "utils/StringUtils.hpp" namespace oopse { -/** - * @class SelectionEvaluator SelectionEvaluator.hpp "selection/SelectionEvaluator" - * @brief Evalute the tokens compiled by SelectionCompiler and return a BitSet - */ -class SelectionEvaluator{ - public: + /** + * @class SelectionEvaluator SelectionEvaluator.hpp "selection/SelectionEvaluator" + * @brief Evalute the tokens compiled by SelectionCompiler and return a OOPSEBitSet + */ + class SelectionEvaluator{ + public: - SelectionEvaluator(SimInfo* info); + SelectionEvaluator(SimInfo* info); - bool loadScriptString(const std::string& script); - bool loadScriptFile(const std::string& filename); + bool loadScriptString(const std::string& script); + bool loadScriptFile(const std::string& filename); - BitSet evaluate(); + OOPSEBitSet evaluate(); - /** - * Tests if the result from evaluation of script is dynamic. - */ - bool isDynamic() { - return isDynamic_; - } + /** + * Tests if the result from evaluation of script is dynamic. + */ + bool isDynamic() { + return isDynamic_; + } - bool hadRuntimeError() const{ - return error; - } + bool hadRuntimeError() const{ + return error; + } - std::string getErrorMessage() const { - return errorMessage; - } + std::string getErrorMessage() const { + return errorMessage; + } - int getLinenumber() { - return linenumbers[pc]; - } + int getLinenumber() { + return linenumbers[pc]; + } - std::string getLine() { - int ichBegin = lineIndices[pc]; - int ichEnd; - if ((ichEnd = script.find('\r', ichBegin)) == std::string::npos && - (ichEnd = script.find('\n', ichBegin)) == std::string::npos) { - ichEnd = script.size(); - } - return script.substr(ichBegin, ichEnd); - } + std::string getLine() { + int ichBegin = lineIndices[pc]; + int ichEnd; + if ((ichEnd = script.find('\r', ichBegin)) == std::string::npos && + (ichEnd = script.find('\n', ichBegin)) == std::string::npos) { + ichEnd = script.size(); + } + return script.substr(ichBegin, ichEnd); + } - private: + private: - void clearState(); + void clearState(); - bool loadScript(const std::string& filename, const std::string& script); + bool loadScript(const std::string& filename, const std::string& script); - bool loadScriptFileInternal(const std::string& filename); + bool loadScriptFileInternal(const std::string& filename); - void clearDefinitionsAndLoadPredefined(); + void clearDefinitionsAndLoadPredefined(); - void define(); - void select(BitSet& bs); - void predefine(const std::string& script); + void define(); + void select(OOPSEBitSet& bs); + void predefine(const std::string& script); - void instructionDispatchLoop(BitSet& bs); + void instructionDispatchLoop(OOPSEBitSet& bs); - void withinInstruction(const Token& instruction, BitSet& bs); + void withinInstruction(const Token& instruction, OOPSEBitSet& bs); - BitSet comparatorInstruction(const Token& instruction); - void compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue); - BitSet nameInstruction(const std::string& name); - BitSet indexInstruction(const boost::any& value); - BitSet expression(const std::vector& tokens, int pc); + OOPSEBitSet comparatorInstruction(const Token& instruction); + void compareProperty(StuntDouble* sd, OOPSEBitSet& bs, int property, int comparator, float comparisonValue); + OOPSEBitSet nameInstruction(const std::string& name); + OOPSEBitSet indexInstruction(const boost::any& value); + OOPSEBitSet expression(const std::vector& tokens, int pc); - BitSet lookupValue(const std::string& variable); + OOPSEBitSet lookupValue(const std::string& variable); - void evalError(const std::string& message) { - std::cerr << "SelectionEvaulator Error: " << message << std::endl; - } + void evalError(const std::string& message) { + std::cerr << "SelectionEvaulator Error: " << message << std::endl; + } - void unrecognizedCommand(const Token& token) { - evalError("unrecognized command:" + boost::any_cast(token.value)); - } + void unrecognizedCommand(const Token& token) { + evalError("unrecognized command:" + boost::any_cast(token.value)); + } - void unrecognizedExpression() { - evalError("unrecognized expression"); - } + void unrecognizedExpression() { + evalError("unrecognized expression"); + } - void unrecognizedAtomProperty(int property){ - evalError("unrecognized atom property"); - } + void unrecognizedAtomProperty(int property){ + evalError("unrecognized atom property"); + } - void unrecognizedIdentifier(const std::string& identifier) { - evalError("unrecognized identifier:" + identifier); - } + void unrecognizedIdentifier(const std::string& identifier) { + evalError("unrecognized identifier:" + identifier); + } - void invalidIndexRange(std::pair range) { - evalError("invalid index range: [" + toString(range.first) + ", " + toString(range.second) + ")"); - } + void invalidIndexRange(std::pair range) { + evalError("invalid index range: [" + toString(range.first) + ", " + toString(range.second) + ")"); + } - void invalidIndex(int index) { - evalError("invalid index : " + toString(index) ); - } + void invalidIndex(int index) { + evalError("invalid index : " + toString(index) ); + } - bool containDynamicToken(const std::vector& tokens); + bool containDynamicToken(const std::vector& tokens); + + double getCharge(Atom* atom); - SelectionCompiler compiler; + SelectionCompiler compiler; - //const static int scriptLevelMax = 10; - //int scriptLevel; + //const static int scriptLevelMax = 10; + //int scriptLevel; - //Context stack[scriptLevelMax]; + //Context stack[scriptLevelMax]; - std::string filename; - std::string script; - std::vector linenumbers; - std::vector lineIndices; - std::vector > aatoken; - int pc; // program counter + std::string filename; + std::string script; + std::vector linenumbers; + std::vector lineIndices; + std::vector > aatoken; + int pc; // program counter - bool error; - std::string errorMessage; + bool error; + std::string errorMessage; - std::vector statement; - int statementLength; + std::vector statement; + int statementLength; - SimInfo* info; - NameFinder nameFinder; - DistanceFinder distanceFinder; - IndexFinder indexFinder; - int nStuntDouble; //natoms + nrigidbodies + SimInfo* info; + NameFinder nameFinder; + DistanceFinder distanceFinder; + IndexFinder indexFinder; + int nStuntDouble; //natoms + nrigidbodies - typedef std::map VariablesType; - VariablesType variables; + typedef std::map VariablesType; + VariablesType variables; - bool isDynamic_; - bool isLoaded_; + bool isDynamic_; + bool isLoaded_; -}; + }; } #endif