BALL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
expression.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_KERNEL_EXPRESSION_H
6 #define BALL_KERNEL_EXPRESSION_H
7 
8 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
10 #endif
11 
12 #ifndef BALL_KERNEL_EXPRESSIONPARSER_H
14 #endif
15 
16 namespace BALL
17 {
18  class Atom;
19  class ExpressionTree;
20 
37  {
38  public:
39 
41 
42 
45 
48  typedef void * (*CreationMethod) ();
49 
51 
54 
57  Expression();
58 
61  Expression(const Expression& expression);
62 
66  Expression(const String& expression_string);
67 
70  virtual ~Expression();
71 
73 
76 
79  bool hasPredicate(const String& name) const;
80 
83  bool operator == (const Expression& expression) const;
84 
86 
89 
93  virtual bool operator () (const Atom& atom) const;
94 
100  ExpressionPredicate* getPredicate(const String& name,
101  const String& args = "") const;
102 
105  void registerPredicate(const String& name, CreationMethod creation_method);
106 
110  void setExpression(const String& expression);
111 
114  const String& getExpressionString() const;
115 
118  const ExpressionTree* getExpressionTree() const;
119 
122  const StringHashMap<CreationMethod>& getCreationMethods() const;
123 
125 
128 
131  Expression& operator = (const Expression& expression);
132 
135  virtual void clear();
136 
138 
139  protected:
140 
141  /*_ @name Protected methods
142  */
144 
145  /*_ Construct the expression tree from the SyntaxTree
146  * @throw Exception::ParseError if a syntax error was encountered
147  */
148  ExpressionTree* constructExpressionTree_(const ExpressionParser::SyntaxTree& tree);
149 
150  /*_ Register the predicates defined by default.
151  See also: BALL/KERNEL/standardPredicates.h
152  */
153  void registerStandardPredicates_();
154 
156  /*_ @name Protected attributes
157  */
159 
160  /*_ The methods to create the ExpressionPredicate instances
161  */
162  StringHashMap<CreationMethod> create_methods_;
163 
164  /*_ The ExpressionTree constructed from the string.
165  This tree contains the instances of the predicates.
166  */
167  ExpressionTree* expression_tree_;
168 
169  /*_ The string describing the expression.
170  */
171  String expression_string_;
172 
174  };
175 }
176 
177 #endif // BALL_KERNEL_EXPRESSION_H
178