BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 00005 #ifndef BALL_KERNEL_EXPRESSION_H 00006 #define BALL_KERNEL_EXPRESSION_H 00007 00008 #ifndef BALL_DATATYPE_STRINGHASHMAP_H 00009 # include <BALL/DATATYPE/stringHashMap.h> 00010 #endif 00011 00012 #ifndef BALL_KERNEL_EXPRESSIONPARSER_H 00013 # include <BALL/KERNEL/expressionParser.h> 00014 #endif 00015 00016 namespace BALL 00017 { 00018 class Atom; 00019 class ExpressionTree; 00020 00036 class BALL_EXPORT Expression 00037 { 00038 public: 00039 00040 BALL_CREATE(Expression) 00041 00042 00045 00048 typedef void * (*CreationMethod) (); 00049 00051 00054 00057 Expression(); 00058 00061 Expression(const Expression& expression); 00062 00066 Expression(const String& expression_string); 00067 00070 virtual ~Expression(); 00071 00073 00076 00079 bool hasPredicate(const String& name) const; 00080 00083 bool operator == (const Expression& expression) const; 00084 00086 00089 00093 virtual bool operator () (const Atom& atom) const; 00094 00100 ExpressionPredicate* getPredicate(const String& name, 00101 const String& args = "") const; 00102 00105 void registerPredicate(const String& name, CreationMethod creation_method); 00106 00110 void setExpression(const String& expression); 00111 00114 const String& getExpressionString() const; 00115 00118 const ExpressionTree* getExpressionTree() const; 00119 00122 const StringHashMap<CreationMethod>& getCreationMethods() const; 00123 00125 00128 00131 Expression& operator = (const Expression& expression); 00132 00135 virtual void clear(); 00136 00138 00139 protected: 00140 00141 /*_ @name Protected methods 00142 */ 00144 00145 /*_ Construct the expression tree from the SyntaxTree 00146 * @throw Exception::ParseError if a syntax error was encountered 00147 */ 00148 ExpressionTree* constructExpressionTree_(const ExpressionParser::SyntaxTree& tree); 00149 00150 /*_ Register the predicates defined by default. 00151 See also: BALL/KERNEL/standardPredicates.h 00152 */ 00153 void registerStandardPredicates_(); 00154 00156 /*_ @name Protected attributes 00157 */ 00159 00160 /*_ The methods to create the ExpressionPredicate instances 00161 */ 00162 StringHashMap<CreationMethod> create_methods_; 00163 00164 /*_ The ExpressionTree constructed from the string. 00165 This tree contains the instances of the predicates. 00166 */ 00167 ExpressionTree* expression_tree_; 00168 00169 /*_ The string describing the expression. 00170 */ 00171 String expression_string_; 00172 00174 }; 00175 } 00176 00177 #endif // BALL_KERNEL_EXPRESSION_H 00178