summaryrefslogtreecommitdiff
path: root/libtemplate/parameter.h
blob: 0a4ca23a701783e7f28d0b20b7a3521770f423a2 (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
#ifndef __TEMPLATEPARAMETER_H
#define __TEMPLATEPARAMETER_H

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>

#include "globals.h"

using namespace std;

enum eAlign {
    alLeft,
    alCenter,
    alRight,
    alTop,
    alBottom
};

enum eScrollMode {
    smNone,
    smCarriageReturn,
    smForthAndBack
};

enum eScrollSpeed {
    ssNone,
    ssSlow,
    ssMedium,
    ssFast
};

enum eOrientation {
    orNone,
    orHorizontal,
    orVertical,
    orAbsolute
};

// --- cNumericParameter -------------------------------------------------------------

class cNumericParameter {
private:
    cGlobals *globals;
    string value;
    bool isValid;
    int width;
    int height;
    int columnWidth;
    int rowHeight;
    bool hor;
    int defaultValue;
    bool IsNumber(const string& s);
    bool CheckPercentValue(int &val);
    bool CheckExpression(int &val, string &parsedVal);
    bool ValidNumericExpression(string &parsedValue);
    int EvaluateTheExpression(char* expr);
    double ParseAtom(char*& expr);
    double ParseFactors(char*& expr);
    double ParseSummands(char*& expr);
public:
    cNumericParameter(string value);
    virtual ~cNumericParameter(void);
    void SetGlobals(cGlobals *globals) { this->globals = globals; };
    void SetAreaSize(int w, int h);
    void SetLoopContainer(int columnWidth, int rowHeight) { this->columnWidth = columnWidth; this->rowHeight = rowHeight; };
    void SetDefault(int def) { defaultValue = def; };
    void SetHorizontal(void) { hor = true; };
    void SetVertical(void) { hor = false; };
    int Parse(string &parsedValue);
    bool Valid(void) { return isValid; };
};

// --- cTextToken -------------------------------------------------------------

enum eTextTokenType {
    ttConstString,
    ttToken,
    ttConditionalToken,
    ttPrintfToken
};

class cTextToken {
public:
    eTextTokenType type;
    string value;
    vector<string> parameters;
    vector<cTextToken> subTokens;
};

// --- cConditionalParameter -------------------------------------------------------------

enum eCondParameterType {
    cpAnd,
    cpOr,
    cpNone
};

enum eCondType {
    ctLower,
    ctGreater,
    ctEquals,
    ctBool,
    ctStringSet,
    ctStringEmpty,
    ctStringEquals,
    ctStringNotEquals,
    ctStringContains,
    ctStringNotContains,
    ctNone
};

struct sCondition {
    string tokenName;
    bool isNegated;
    eCondType type;
    int compareValue;
    string strCompareValue;
};

class cConditionalParameter {
private:
    cGlobals *globals;
    bool isTrue;
    string value;
    eCondParameterType type;
    vector<sCondition> conditions;
    void TokenizeValue(string sep);
    void InsertCondition(string cond);
    string StripWhitespaces(string value);
    int EvaluateParameter(string token, map < string, int > *intTokens, map < string, string > *stringTokens);
public:
    cConditionalParameter(cGlobals *globals, string value);
    virtual ~cConditionalParameter(void);
    void Tokenize(void);
    void Evaluate(map < string, int > *intTokens, map < string, string > *stringTokens);
    bool IsTrue(void) { return isTrue; };
    void Debug(void);
};
#endif //__TEMPLATEPARAMETER_H