Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
244 chris 1
#ifndef __DESCPARSER_H__
2
#define __DESCPARSER_H__
3
 
4
#include "Common.h"
5
 
6
namespace Sexy
7
{
8
 
9
class DataElement
10
{
11
public:
12
        bool                                    mIsList;
13
 
14
public:
15
        DataElement();
16
        virtual ~DataElement();
17
 
18
        virtual DataElement*    Duplicate() = NULL;
19
};
20
 
21
class SingleDataElement : public DataElement
22
{
23
public:
24
        std::string                             mString;       
25
 
26
public:
27
        SingleDataElement();
28
        SingleDataElement(const std::string theString);
29
        virtual ~SingleDataElement();
30
 
31
        virtual DataElement*    Duplicate();
32
};
33
 
34
typedef std::vector<DataElement*> ElementVector;
35
 
36
class ListDataElement : public DataElement
37
{
38
public:
39
        ElementVector                   mElementVector;
40
 
41
public:
42
        ListDataElement();
43
        ListDataElement(const ListDataElement& theListDataElement);
44
        virtual ~ListDataElement();
45
 
46
        ListDataElement&                operator=(const ListDataElement& theListDataElement);
47
 
48
        virtual DataElement*    Duplicate();
49
};
50
 
51
typedef std::map<std::string, DataElement*> DataElementMap;
52
typedef std::vector<std::string> StringVector;
53
typedef std::vector<int> IntVector;
54
typedef std::vector<double> DoubleVector;
55
 
56
class DescParser
57
{
58
public:
59
        enum
60
        {
61
                CMDSEP_SEMICOLON = 1,
62
                CMDSEP_NO_INDENT = 2
63
        };
64
 
65
public:
66
        int                                             mCmdSep;
67
 
68
        std::string                             mError;
69
        int                                             mCurrentLineNum;
70
        std::string                             mCurrentLine;
71
        DataElementMap                  mDefineMap;
72
 
73
public:
74
        virtual bool                    Error(const std::string& theError);
75
        virtual DataElement*    Dereference(const std::string& theString);
76
        bool                                    IsImmediate(const std::string& theString);
77
        std::string                             Unquote(const std::string& theQuotedString);
78
        bool                                    GetValues(ListDataElement* theSource, ListDataElement* theValues);
79
        std::string                             DataElementToString(DataElement* theDataElement);
80
        bool                                    DataToString(DataElement* theSource, std::string* theString);
81
        bool                                    DataToInt(DataElement* theSource, int* theInt);
82
        bool                                    DataToStringVector(DataElement* theSource, StringVector* theStringVector);
83
        bool                                    DataToList(DataElement* theSource, ListDataElement* theValues);
84
        bool                                    DataToIntVector(DataElement* theSource, IntVector* theIntVector);
85
        bool                                    DataToDoubleVector(DataElement* theSource, DoubleVector* theDoubleVector);
86
        bool                                    ParseToList(const std::string& theString, ListDataElement* theList, bool expectListEnd, int* theStringPos);
87
        bool                                    ParseDescriptorLine(const std::string& theDescriptorLine);
88
 
89
        // You must implement this one
90
        virtual bool                    HandleCommand(const ListDataElement& theParams) = 0;
91
 
92
public:
93
        DescParser();
94
        virtual ~DescParser(); 
95
 
96
        bool                                    LoadDescriptor(const std::string& theFileName);
97
};
98
 
99
}
100
 
101
#endif //__DESCPARSER_H__