OSDN Git Service

Removing redundant error checking related to booking declaration.
[tjqt4port/tj2qt4.git] / taskjuggler / ExpressionTree.h
1 /*
2  * ExpressionTree.h - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * $Id$
11  */
12
13 #ifndef _ExpressionTree_h_
14 #define _ExpressionTree_h_
15
16 #include <time.h>
17
18 #include <qdict.h>
19 #include <qptrlist.h>
20
21 #include "ExpressionTreeFunction.h"
22
23 class CoreAttributes;
24 class ExpressionTree;
25 class Operation;
26 class Project;
27
28 /**
29  * @short This class represents the logical expressions that can be used to
30  * filter @see CoreAttributesList objects.
31  * @author Chris Schlaeger <cs@kde.org>
32  *
33  * @details To filter certain elements out of CoreAttributes lists one needs to
34  * specify a logical expression that describes the elements that should remain
35  * in the list. The ExpressionTree stores such a logical expression. To filter
36  * out the unwanted elements the ExpressionTree is evaluated against each of
37  * the elements. The attributes of the element can be referenced in the
38  * expression.
39  */
40 class ExpressionTree
41 {
42 public:
43     /**
44      * Use this constructor when you have rolled your own operation tree
45      * already.
46      * @ param op the root of the operation tree
47      */
48     ExpressionTree(const Operation* op);
49     /**
50      * The usual copy constructor.
51      */
52     ExpressionTree(const ExpressionTree& et);
53     /**
54      * The default constructor. When you use this, you need to call setTree()
55      * later on to assign an expression to the object.
56      */
57     ExpressionTree();
58     /**
59      * Destructor
60      */
61     ~ExpressionTree();
62
63     /**
64      * Use this fuction to assign a new expression to the object.
65      * @param expr is a logical expresion in text form.
66      * @param proj is a pointer to the project object.
67      */
68     bool setTree(const QString& expr, const Project* proj);
69
70     void setDefLocation(const QString file, int line)
71     {
72         defFileName = file;
73         defLineNo = line;
74     }
75
76     long evalAsInt(const CoreAttributes* c);
77     long resolve(const QString& symbol);
78
79     void setErrorFlag(bool flag = true)
80     {
81         evalErrorFlag = flag;
82     }
83     bool getErrorFlag() const
84     {
85         return evalErrorFlag;
86     }
87
88     void registerSymbol(const QString& symbol, long value)
89     {
90         symbolTable.insert(symbol, new long(value));
91     }
92     void clearSymbolTable() { symbolTable.clear(); }
93
94     const CoreAttributes* getCoreAttributes() const { return ca; }
95
96     void errorMessage(const QString& msg);
97
98 private:
99     void generateFunctionTable();
100     const CoreAttributes* ca;
101     QDict<long> symbolTable;
102     const Operation* expression;
103     bool evalErrorFlag;
104
105     QString defFileName;
106     int defLineNo;
107 } ;
108
109 #endif