expression.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: expression.h,v 1.33 2005/10/23 12:02:18 oliver Exp $
00005 //
00006 
00007 #ifndef BALL_KERNEL_EXPRESSION_H
00008 #define BALL_KERNEL_EXPRESSION_H
00009 
00010 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
00011 # include <BALL/DATATYPE/stringHashMap.h>
00012 #endif
00013 
00014 #ifndef BALL_KERNEL_EXPRESSIONPARSER_H
00015 # include <BALL/KERNEL/expressionParser.h>
00016 #endif
00017 
00018 namespace BALL
00019 {
00020   class Atom;
00021   class ExpressionTree;
00022 
00038   class BALL_EXPORT Expression
00039   {
00040     public:
00041 
00042     BALL_CREATE(Expression)
00043 
00044     
00047 
00050     typedef void * (*CreationMethod) ();
00051 
00053 
00056 
00059     Expression();
00060 
00063     Expression(const Expression& expression);
00064 
00067     Expression(const String& expression_string)
00068       throw(Exception::ParseError);
00069 
00072     virtual ~Expression();
00073 
00075 
00078 
00081     bool hasPredicate(const String& name) const;
00082 
00085     bool operator == (const Expression& expression) const;
00086 
00088 
00091 
00095     virtual bool operator () (const Atom& atom) const;
00096 
00102     ExpressionPredicate* getPredicate(const String& name,
00103                                       const String& args = "") const;
00104 
00107     void registerPredicate(const String& name, CreationMethod creation_method);
00108 
00111     void setExpression(const String& expression) throw(Exception::ParseError);
00112 
00115     const String& getExpressionString() const;
00116 
00119     const ExpressionTree* getExpressionTree() const;
00120 
00123     const StringHashMap<CreationMethod>& getCreationMethods() const;
00124 
00126 
00129 
00132     Expression& operator = (const Expression& expression);
00133 
00136     virtual void clear();
00137 
00139 
00140     protected:
00141 
00142     /*_ @name Protected methods
00143     */
00145 
00146     /*_ Construct the expression tree from the SyntaxTree
00147     */
00148     ExpressionTree* constructExpressionTree_(const ExpressionParser::SyntaxTree& tree)
00149       throw(Exception::ParseError);
00150 
00151     /*_ Register the predicates defined by default.
00152         See also: BALL/KERNEL/standardPredicates.h
00153     */
00154     void registerStandardPredicates_();
00155 
00157     /*_ @name Protected attributes
00158     */
00160 
00161     /*_ The methods to create the ExpressionPredicate instances
00162     */
00163     StringHashMap<CreationMethod> create_methods_;
00164 
00165     /*_ The ExpressionTree constructed from the string.
00166         This tree contains the instances of the predicates.
00167     */
00168     ExpressionTree*               expression_tree_;
00169 
00170     /*_ The string describing the expression.
00171     */
00172     String                        expression_string_;
00173 
00175   };
00176 }
00177 
00178 #endif // BALL_KERNEL_EXPRESSION_H
00179