summaryrefslogtreecommitdiff
path: root/coreengine/complextypes.h
blob: 1e1867aef3fe54378d54915914c0054cc98ede42 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#ifndef __COMPLEXTYPES_H
#define __COMPLEXTYPES_H

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <vdr/skins.h>
#include "globals.h"
#include "../libskindesignerapi/tokencontainer.h"

class cLoopInfo;
class cFunction;
/******************************************************************
* helpers
******************************************************************/
char *RemoveSpace(char *e);
void ReplaceDecimalpoint(char *e);
void ReplaceStart(char *e, int num);
void ReplaceEnd(char *e, int num);

/******************************************************************
* cCondition
******************************************************************/
enum class eCondOp {
    tAnd,
    tOr
};

enum class eCondType {
    token,
    negtoken,
    lowerInt,
    equalInt,
    notequalInt,
    greaterInt,
    isset,
    empty,
    equalString,
    notEqualString,
    contains,
    notContains
};

enum class eCondTokenType {
    inttoken,
    stringtoken,
    looptoken
};

class cCond : public cListObject {
public:
    cCond(const char *expression);
    cCond(const cCond &other);
    virtual ~cCond(void);
    void Debug(void);
    char *expr;
    eCondOp operation;
    eCondType type;
    eCondTokenType tokenType;
    bool constant;
    bool isTrue;
    int tokenIndex;
    int compareValue;
    char *compareStrValue;
};

class cCondition {
private:
    char *expr;
    cGlobals *globals;
    skindesignerapi::cTokenContainer *tokenContainer;
    cLoopInfo *loopInfo;
    cList<cCond> conds;
    void Tokenize(void);
    void PrepareTokens(void);
    void SetTokenCond(cCond *c);
    void SetIntegerCond(cCond *c);
    void SetStringCond(cCond *c);
    void SetStringCompareCond(cCond *c);
    void SetTokenIndex(cCond *c, const char *token);
public:
    cCondition(const char *expression);
    cCondition(const cCondition &other);
    virtual ~cCondition(void);
    void SetGlobals(cGlobals *globals) { this->globals = globals; };
    void SetTokenContainer(skindesignerapi::cTokenContainer *tokenContainer) {this->tokenContainer = tokenContainer; };
    void SetLoopInfo(cLoopInfo *loopInfo) { this->loopInfo = loopInfo; };
    void Prepare(void);
    bool True(void);
    void Debug(void);
};

/******************************************************************
* cNumericExpr
******************************************************************/
enum class eFactorType {
    constant = 0,
    stringtoken,
    inttoken,
    looptoken,
    xref,
    yref,
    widthref,
    heightref,
    areawidth,
    areaheight,
    columnwidth,
    rowheight
};

class cFactor: public cListObject {
public:
    cFactor(void) {
        multiplication = true;
        type = eFactorType::constant;
        constValue = 1.0f;
        tokenIndex = -1;
        funcRefName = NULL;
        funcRef = NULL;
    };
    cFactor(const cFactor &other) {
        multiplication = other.multiplication;
        type = other.type;
        constValue = other.constValue;
        tokenIndex = other.tokenIndex;
        funcRefName = NULL;
        if (other.funcRefName)
            funcRefName = strdup(other.funcRefName);
        funcRef = other.funcRef;
    }
    ~cFactor(void) {
        free(funcRefName);
    };
    bool multiplication;
    eFactorType type;
    double constValue;
    int tokenIndex;
    char *funcRefName;
    cFunction *funcRef;
};

class cSummand : public cListObject {
public:
    cSummand(const char *summand);
    cSummand(const cSummand &other);
    ~cSummand(void);
    void Debug(void);
    char *summand;
    bool positive;
    cList<cFactor> factors;
};

class cNumericExpr {
private:
    cGlobals *globals;
    cRect *container;
    skindesignerapi::cTokenContainer *tokenContainer;
    cLoopInfo *loopInfo;
    char *expr;
    cList<cSummand> summands;
    bool horizontal;
    int value;
    bool dynamic;
    //common string functions
    bool IsNumeric(const char *e);
    bool IsNumericExpression(const char *e);
    bool PercentValue(const char *e);
    char *ReplacePercentValue(char *e);
    char *ReplaceToken(char *e, const char* token, int value);
    char *ReplaceTokens(char *e, const char* token, int value);
    //calculate numeric expressions
    int EvaluateExpression(char *e);
    double EvaluateExpressionDouble(char *e);
    double ParseAtom(char*& e);
    double ParseFactors(char*& e);
    double ParseSummands(char*& e);
    //prepare expressions with tokens
    void CreateSummands(void);
    void CreateFactors(void);
    bool SetTokenFactor(cFactor *f, char *tokenName);
    bool SetReferenceFactor(cFactor *f, char *tokenName);
    bool SetGeometryFactor(cFactor *f, char *tokenName);
    void ConsolidateSummand(void);
    void ConsolidateFactors(void);
public:
    cNumericExpr(const char *expression);
    cNumericExpr(const cNumericExpr &other);
    virtual ~cNumericExpr(void);
    void SetContainer(cRect *container) { this->container = container; };
    void SetGlobals(cGlobals *globals) { this->globals = globals; };
    void SetTokenContainer(skindesignerapi::cTokenContainer *tokenContainer) { this->tokenContainer = tokenContainer; };
    void SetLoopInfo(cLoopInfo *loopInfo) { this->loopInfo = loopInfo; };
    void SetVertical(void) { horizontal = false; };
    bool CacheStatic(void);
    void PrepareTokens(void);
    vector<cFactor*> GetRefFactors(void);
    int GetValue(void) { return value; };
    bool Dynamic(void) { return dynamic; };
    int Calculate(void);
    void Debug(void);
};

/******************************************************************
* cColor
******************************************************************/
class cColor {
private:
    cGlobals *globals;
    char *expr;
    tColor value;
public:
    cColor(const char *expression);
    cColor(const cColor &other);
    virtual ~cColor(void);
    void SetGlobals(cGlobals *globals) { this->globals = globals; };
    void Cache(void);
    tColor Color(void);
    void Debug(void);
};

/******************************************************************
* cTextExpr
******************************************************************/
enum class eTexttokenType {
    constant = 0,
    stringtoken,
    inttoken,
    looptoken,
    printftoken,
    condstringtoken,
    condinttoken,
};

enum class ePrintfVarType {
    stringtoken,
    inttoken,
    looptoken
};

struct sPrintfInfo {
    ePrintfVarType type;
    int index;
};

class cTextToken: public cListObject {
public:
    cTextToken(void) {
        type = eTexttokenType::constant;
        constValue = NULL;
        printfExpr = NULL;
        printfResult = NULL;
        tokenIndex = -1;
        condStart = NULL;
        condEnd = NULL;
    };
    cTextToken(const cTextToken &other) {
        type = other.type;
        constValue = NULL;
        if (other.constValue)
            constValue = strdup(other.constValue);
        printfExpr = NULL;
        if (other.printfExpr)
            printfExpr = strdup(other.printfExpr);
        printfVarIndices = other.printfVarIndices;
        printfResult = NULL;
        if (other.printfResult)
            printfResult = strdup(other.printfResult);
        tokenIndex = other.tokenIndex;
        condStart = NULL;
        if (other.condStart)
            condStart = strdup(other.condStart);
        condEnd = NULL;
        if (other.condEnd)
            condEnd = strdup(other.condEnd);
    };
    ~cTextToken(void) {
        free(constValue);
        free(printfExpr);
    };
    eTexttokenType type;
    char *constValue;
    int tokenIndex;
    char *printfExpr;
    vector<sPrintfInfo> printfVarIndices;
    char *printfResult;
    char *condStart;
    char *condEnd;
};

class cTextExpr {
private:
    cGlobals *globals;
    skindesignerapi::cTokenContainer *tokenContainer;
    cLoopInfo *loopInfo;
    char *expr;
    cList<cTextToken> textTokens;
    void Translate(void);
    void Tokenize(void);
    void PrepareTokens(void);
    bool CheckGlobals(cTextToken *t);
    bool ParsePrintfToken(cTextToken *t);
    void DeterminatePrintfToken(cTextToken *t);
    void ParseCondToken(cTextToken *t);
    char *CopyTextPart(char *start, char *stop, bool incLastChar= true);
public:
    cTextExpr(const char *expression);
    cTextExpr(const cTextExpr &other);
    virtual ~cTextExpr(void);
    void SetGlobals(cGlobals *globals) { this->globals = globals; };
    void SetTokenContainer(skindesignerapi::cTokenContainer *tokenContainer) { this->tokenContainer = tokenContainer; };
    void SetLoopInfo(cLoopInfo *loopInfo) { this->loopInfo = loopInfo; };
    void CorrectImagePath(void);
    void Cache(void);
    char *DeterminateText(void);
    void Debug(const char *exprName);
};

#endif //__COMPLEXTYPES_H