OSDN Git Service

Removing redundant error checking related to booking declaration.
[tjqt4port/tj2qt4.git] / taskjuggler / MacroTable.h
1 /*
2  * MacroTable.h - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002, 2003, 2004, 2005 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 _MacroTable_h_
14 #define _MacroTable_h_
15
16 #include <stdarg.h>
17
18 #include <qstring.h>
19 #include <qstringlist.h>
20 #include <qdict.h>
21
22 class Macro
23 {
24 public:
25     Macro(const QString& n, const QString& v, const QString& f, uint l)
26         : name(n), value(v), file(f), line(l) { }
27     Macro(const QString& n, const int v, const QString& f, uint l)
28         : name(n), value(QString::number(v)), file(f), line(l) { }
29     Macro(const QString& n, const long v, const QString& f, uint l)
30         : name(n), value(QString::number(v)), file(f), line(l) { }
31     Macro(const QString& n, const double v, const QString& f, uint l)
32         : name(n), value(QString::number(v)), file(f), line(l) { }
33     ~Macro() { }
34
35     const QString& getName() const { return name; }
36     const QString& getValue() const { return value; }
37     const QString& getFile() const { return file; }
38     uint getLine() const { return line; }
39
40 private:
41     QString name;
42     QString value;
43     QString file;
44     uint line;
45 } ;
46
47 class MacroTable
48 {
49 public:
50     MacroTable() : defFileName(), defFileLine(0), macros()
51     {
52         macros.setAutoDelete(true);
53     }
54     ~MacroTable() { }
55
56     bool addMacro(Macro* m);
57     void setMacro(Macro* m);
58
59     bool deleteMacro(const QString name)
60     {
61         return macros.remove(name);
62     }
63
64     void clear()
65     {
66         macros.clear();
67     }
68     QString resolve(const QStringList* argList) const;
69     QString expandReportVariable(QString text, const QStringList* argList) const;
70     Macro* getMacro(const QString& name) const { return macros[name]; }
71
72     void setLocation(const QString& df, int dl)
73     {
74         defFileName = df;
75         defFileLine = dl;
76     }
77
78 private:
79     bool evalExpression(const QString expr) const;
80     void errorMessage(const QString& msg) const;
81
82     /* We store a file name and a line number in case we need this for
83      * error reports or warnings. This is the location of the macro reference,
84      * not the macro definitions. */
85     QString defFileName;
86     int defFileLine;
87
88     QDict<Macro> macros;
89 } ;
90
91 #endif