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
|
#ifndef __DESCPARSER_H__
#define __DESCPARSER_H__
#include "Common.h"
namespace Sexy
{
class DataElement
{
public:
bool mIsList;
public:
DataElement();
virtual ~DataElement();
virtual DataElement* Duplicate() = NULL;
};
class SingleDataElement : public DataElement
{
public:
std::string mString;
public:
SingleDataElement();
SingleDataElement(const std::string theString);
virtual ~SingleDataElement();
virtual DataElement* Duplicate();
};
typedef std::vector<DataElement*> ElementVector;
class ListDataElement : public DataElement
{
public:
ElementVector mElementVector;
public:
ListDataElement();
ListDataElement(const ListDataElement& theListDataElement);
virtual ~ListDataElement();
ListDataElement& operator=(const ListDataElement& theListDataElement);
virtual DataElement* Duplicate();
};
typedef std::map<std::string, DataElement*> DataElementMap;
typedef std::vector<std::string> StringVector;
typedef std::vector<int> IntVector;
typedef std::vector<double> DoubleVector;
class DescParser
{
public:
enum
{
CMDSEP_SEMICOLON = 1,
CMDSEP_NO_INDENT = 2
};
public:
int mCmdSep;
std::string mError;
int mCurrentLineNum;
std::string mCurrentLine;
DataElementMap mDefineMap;
public:
virtual bool Error(const std::string& theError);
virtual DataElement* Dereference(const std::string& theString);
bool IsImmediate(const std::string& theString);
std::string Unquote(const std::string& theQuotedString);
bool GetValues(ListDataElement* theSource, ListDataElement* theValues);
std::string DataElementToString(DataElement* theDataElement);
bool DataToString(DataElement* theSource, std::string* theString);
bool DataToInt(DataElement* theSource, int* theInt);
bool DataToStringVector(DataElement* theSource, StringVector* theStringVector);
bool DataToList(DataElement* theSource, ListDataElement* theValues);
bool DataToIntVector(DataElement* theSource, IntVector* theIntVector);
bool DataToDoubleVector(DataElement* theSource, DoubleVector* theDoubleVector);
bool ParseToList(const std::string& theString, ListDataElement* theList, bool expectListEnd, int* theStringPos);
bool ParseDescriptorLine(const std::string& theDescriptorLine);
// You must implement this one
virtual bool HandleCommand(const ListDataElement& theParams) = 0;
public:
DescParser();
virtual ~DescParser();
bool LoadDescriptor(const std::string& theFileName);
};
}
#endif //__DESCPARSER_H__
|