--- trunk/src/selection/SelectionEvaluator.hpp 2005/02/03 23:14:05 283 +++ trunk/src/selection/SelectionEvaluator.hpp 2005/03/09 17:30:29 413 @@ -45,34 +45,20 @@ #include #include #include +#include #include "brains/SimInfo.hpp" #include "selection/Token.hpp" #include "selection/SelectionCompiler.hpp" #include "selection/NameFinder.hpp" +#include "selection/DistanceFinder.hpp" +#include "selection/IndexFinder.hpp" #include "utils/BitSet.hpp" #include "primitives/StuntDouble.hpp" +#include "utils/StringUtils.hpp" namespace oopse { -class Context { - public: - - void clear() { - linenumbers.clear(); - lineIndices.clear(); - aatoken.clear(); - } - - std::string filename; - std::string script; - std::vector linenumbers; - std::vector lineIndices; - std::vector > aatoken; - int pc; -}; - - /** * @class SelectionEvaluator SelectionEvaluator.hpp "selection/SelectionEvaluator" * @brief Evalute the tokens compiled by SelectionCompiler and return a BitSet @@ -80,18 +66,20 @@ class SelectionEvaluator{ class SelectionEvaluator{ public: - SelectionEvaluator(SimInfo* info, const std::string& script); + SelectionEvaluator(SimInfo* info); + bool loadScriptString(const std::string& script); + bool loadScriptFile(const std::string& filename); + BitSet evaluate(); - BitSet evaluate(int frameNo); - /** - * Tests if the result from evaluation of script is static. - * @return true if the result keeps the same even the frame change, otherwise return false + * Tests if the result from evaluation of script is dynamic. */ - bool isStatic(); + bool isDynamic() { + return isDynamic_; + } bool hadRuntimeError() const{ return error; @@ -121,29 +109,31 @@ class SelectionEvaluator{ void clearState(); bool loadScript(const std::string& filename, const std::string& script); - bool loadScriptString(const std::string& script); + bool loadScriptFileInternal(const std::string& filename); - bool loadScriptFile(const std::string& filename); + void clearDefinitionsAndLoadPredefined(); void define(); - void select(); + void select(BitSet& bs); void predefine(const std::string& script); - void instructionDispatchLoop(); + void instructionDispatchLoop(BitSet& bs); void withinInstruction(const Token& instruction, BitSet& 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); BitSet lookupValue(const std::string& variable); - void evalError(const std::string& message); + 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)); @@ -160,12 +150,24 @@ class SelectionEvaluator{ 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 invalidIndex(int index) { + evalError("invalid index : " + toString(index) ); + } + + + bool containDynamicToken(const std::vector& tokens); + 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; @@ -181,9 +183,17 @@ class SelectionEvaluator{ int statementLength; SimInfo* info; - NameFinder finder; + NameFinder nameFinder; + DistanceFinder distanceFinder; + IndexFinder indexFinder; int nStuntDouble; //natoms + nrigidbodies - std::map variables; + + typedef std::map VariablesType; + VariablesType variables; + + bool isDynamic_; + bool isLoaded_; + }; }