summaryrefslogtreecommitdiffstats
path: root/kpresenter/autoformEdit/ATFInterpreter.h
blob: e532a49acdf4eab05c2dc7772d80027d7fe00d9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// -*- Mode: c++-mode; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Reginald Stadlbauer <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef ATFINTERP_H
#define ATFINTERP_H

#include <tqpointarray.h>
#include <tqptrlist.h>
#include <tqstringlist.h>

class ATFInterpreter {

public:

    // structure of an attribute list
    struct AttribList
    {
        bool isVariable;
        int pwDiv;
    };

    // coordinate structure
    struct CoordStruct
    {
        TQString a;
        TQString b;
        TQString c;
        TQString d;
        TQString e;
        TQString f;
        TQString result;
    };

    // attribute structure
    struct AttribStruct
    {
        TQString isVariable;
        TQString pwDiv;
    };

    // structure of signs
    struct Sign
    {
        char op;
        int num;
        char var;
        int type;
    };

    // structure of values
    struct Value
    {
        TQPtrList<Sign> var1;
        TQPtrList<Sign> var2;
        TQPtrList<Sign> var3;
        TQPtrList<Sign> var4;
        TQPtrList<Sign> var5;
        TQPtrList<Sign> var6;
        TQPtrList<Sign> result;
    };

    // constructure - destructure
    ATFInterpreter();
    ~ATFInterpreter();

    // load autoform
    void load(const TQString &);

    // get pointarray/attribute list/points
    TQPointArray getPointArray(int,int);
    TQPtrList<AttribList> getAttribList();

protected:

    // fields
    static const int ST_WIDTH;
    static const int ST_HEIGHT;
    static const int ST_VARIABLE;
    static const int ST_NUMBER;
    static const int ST_OPERATOR;

    // operators
    static const char OP_EQUAL;
    static const char OP_PLUS;
    static const char OP_MINUS;
    static const char OP_MULT;
    static const char OP_DIV;
    static const char COMMENT;

    // block (structure) beginnings - ends
    static const char PNT_BG[];
    static const char X_BG[];
    static const char Y_BG[];
    static const char ATTR_BG[];
    static const char END[];

    // allowed variables
    static const char VAR_1;
    static const char VAR_2;
    static const char VAR_3;
    static const char VAR_4;
    static const char VAR_5;
    static const char VAR_6;
    static const char VAR_X;
    static const char VAR_Y;
    static const char VAR_VARIA;
    static const char VAR_PW;
    static const char VAR_W;
    static const char VAR_H;

    // level (depth) of the syntax
    static const int LEVEL_NULL;
    static const int LEVEL_POINT;
    static const int LEVEL_X;
    static const int LEVEL_Y;
    static const int LEVEL_ATTR;

    // numbers
    static const char NUM_0;
    static const char NUM_1;
    static const char NUM_2;
    static const char NUM_3;
    static const char NUM_4;
    static const char NUM_5;
    static const char NUM_6;
    static const char NUM_7;
    static const char NUM_8;
    static const char NUM_9;

    // structure of coordinates
    struct Coord
    {
        Value pntX;
        Value pntY;
        bool isVariable;
        int pwDiv;
    };

    // interpret the code
    void interpret();

    // get varaible of a line
    TQPtrList<Sign> getVar(const TQString&);

    // ********** variables **********

    // list of coordinates and pointers to coordinate/sign/value
    TQPtrList<Coord> coordList;
    TQPtrList<AttribList> attrLs;
    Coord *coordPtr;
    Sign *signPtr;
    Value *valuePtr;

    // list of lines
    TQStringList lines;
};

#endif //ATFINTERP_H