summaryrefslogtreecommitdiff
path: root/glcdskin/string.h
blob: 20c517cb57d759e4df70869bf551f1680b0c79b8 (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
/*
 * GraphLCD skin library
 *
 * string.h  -  skin string class
 *
 * This file is released under the GNU General Public License. Refer
 * to the COPYING file distributed with this package.
 *
 * based on text2skin
 *
 */

#ifndef _GLCDSKIN_STRING_H_
#define _GLCDSKIN_STRING_H_

#include <string>
#include <vector>

#include "type.h"

namespace GLCD
{

enum eSkinAttrib
{
    aNone,
    aNumber,
    aString,
    aClean,
    aRest

#define __COUNT_ATTRIB__ (aRest + 1)
};

struct tSkinAttrib
{
    eSkinAttrib Type;
    std::string Text;
    int         Number;

    tSkinAttrib(const std::string & a): Type(aString), Text(a), Number(0) {}
    tSkinAttrib(int n): Type(aNumber), Text(""), Number(n) {}
    tSkinAttrib(eSkinAttrib t): Type(t), Text(""), Number(0) {}
    tSkinAttrib(void): Type(aNone), Text(""), Number(0) {}

    friend bool operator== (const tSkinAttrib & A, const tSkinAttrib & B);
    friend bool operator<  (const tSkinAttrib & A, const tSkinAttrib & B);
};

inline bool operator== (const tSkinAttrib & A, const tSkinAttrib & B)
{
    return A.Type == B.Type
        && A.Text == B.Text
        && A.Number == B.Number;
}

inline bool operator<  (const tSkinAttrib & A, const tSkinAttrib & B)
{
    return A.Type == B.Type
        ? A.Text == B.Text
           ? A.Number < B.Number
           : A.Text < B.Text
       : A.Type < B.Type;
}

struct tSkinToken
{
    int         Id;
    std::string Name;
    uint32_t    Offset;
    tSkinAttrib Attrib;
    int         MaxItems;
    int         Index;

    tSkinToken(void);
    tSkinToken(int id, std::string n, uint32_t o, const std::string & a);

    friend bool operator< (const tSkinToken & A, const tSkinToken & B);

    static std::string Token(const tSkinToken & Token);
};

class cSkinObject;
class cSkin;

class cSkinString
{
private:
#if 0
    typedef std::vector<cSkinString*> tStringList;
    static tStringList mStrings;
#endif

    cSkinObject *           mObject;
    cSkin *                 mSkin;
    std::string             mText;
    std::string             mOriginal;
    std::vector<tSkinToken> mTokens;
    bool                    mTranslate;

public:
#if 0
    static void Reparse(void);
#endif

    cSkinString(cSkinObject *Parent, bool Translate);
    ~cSkinString();

    bool Parse(const std::string & Text, bool Translate = false);
    cType Evaluate(void) const;

    void SetListIndex(int MaxItems, int Index);

    cSkinObject * Object(void) const { return mObject; }
    cSkin * Skin(void) const { return mSkin; }
};

inline void cSkinString::SetListIndex(int MaxItems, int Index)
{
    for (uint32_t i = 0; i < mTokens.size(); ++i)
    {
        mTokens[i].MaxItems = MaxItems;
        mTokens[i].Index = Index;
    }
}

} // end of namespace

#endif