Subversion Repositories spk

Rev

Rev 1 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 114
Line 9... Line 9...
9
#include "../common/ext_list.h"
9
#include "../common/ext_list.h"
10
 
10
 
11
class Settings
11
class Settings
12
{
12
{
13
	public:
13
	public:
14
#ifdef X2BC_USE_INI_FORMATS
-
 
15
		template <class Ty1, class Ty2>
-
 
16
		class pair
-
 
17
		{
-
 
18
			public:
-
 
19
				Ty1 left;
-
 
20
				Ty2 right;
-
 
21
				
-
 
22
				pair(const Ty1 &val1, const Ty2 &val2) { left=val1; right=val2; }
-
 
23
				pair(const pair &other) { left=other.left; right=other.right; }
-
 
24
				pair() { }
-
 
25
		};
-
 
26
 
-
 
27
		struct NumberFormat
-
 
28
		{
-
 
29
			enum OutputFormat
-
 
30
			{
-
 
31
				Float,
-
 
32
				Integer
-
 
33
			};
-
 
34
			char type;
-
 
35
			double multiplier;
-
 
36
			OutputFormat outformat;
-
 
37
		};
-
 
38
		
-
 
39
		class StatFormat
-
 
40
		{
-
 
41
			public:
-
 
42
				struct token
-
 
43
				{
-
 
44
					int count;
-
 
45
					char type;
-
 
46
					char *data;
-
 
47
					NumberFormat *numFormat;
-
 
48
					
-
 
49
					token() { data=0; }
-
 
50
					~token() { delete[] data; }
-
 
51
				};
-
 
52
				int id;
-
 
53
			
-
 
54
			private:
-
 
55
				typedef ext::list<token*> TokenList;
-
 
56
				
-
 
57
			public:
-
 
58
				typedef TokenList::iterator iterator;
-
 
59
				typedef TokenList::const_iterator const_iterator;
-
 
60
				
-
 
61
				TokenList tokens;
-
 
62
				bool issueWarning;
-
 
63
				TokenList::size_type cumulativeTokenCount;
-
 
64
				
-
 
65
				StatFormat() { issueWarning=false; cumulativeTokenCount=0; }
-
 
66
				~StatFormat()
-
 
67
				{
-
 
68
					for(iterator &it=tokens.begin(); it!=tokens.end(); ++it){
-
 
69
						delete *it;
-
 
70
					}
-
 
71
				}
-
 
72
		};
-
 
73
		
-
 
74
		typedef pair<const char *, const char*> conststringpair;
-
 
75
#endif // defined(X2BC_USE_INI_FORMATS)
-
 
76
 
-
 
77
		enum ErrorType{
14
		enum ErrorType{
78
			Error,
15
			Error,
79
			Warning
16
			Warning
80
		};
17
		};
81
		
18
		
Line 102... Line 39...
102
			char message[255];
39
			char message[255];
103
		};
40
		};
104
	
41
	
105
	private:
42
	private:
106
		typedef ext::list<ErrorMsg*> ErrorList;
43
		typedef ext::list<ErrorMsg*> ErrorList;
107
#ifdef X2BC_USE_INI_FORMATS 
-
 
108
		typedef ext::list<StatFormat*> FormatList;
-
 
109
#endif
-
 
110
 
44
 
111
	public:
45
	public:
112
		typedef ErrorList::iterator ErrorIterator;
46
		typedef ErrorList::iterator ErrorIterator;
113
#ifdef X2BC_USE_INI_FORMATS
-
 
114
		typedef FormatList::iterator iterator;
-
 
115
		typedef FormatList::const_iterator const_iterator;
-
 
116
#endif
-
 
117
 
47
 
118
	private:
48
	private:
119
#ifdef X2BC_USE_INI_FORMATS
-
 
120
		typedef bool ParsePairCallback(const char *pszSectionName, conststringpair &);
-
 
121
		typedef ext::list<NumberFormat*> NumberFormatList;
-
 
122
		
-
 
123
		NumberFormatList m_constants;
-
 
124
#endif
-
 
125
		
49
		
126
		bool m_bOutputWarnings; // write warnings to file
50
		bool m_bOutputWarnings; // write warnings to file
127
		bool m_bConvert;				// convert values
51
		bool m_bRawMode;				// don't convert to BOD format
128
		bool m_bStatFormatWarnings; // make warning if format is marked with warning sign
-
 
129
		bool m_bXtraPntInfo; // whether extra point info is outputed to BOD
52
		bool m_bXtraPntInfo; // whether extra point info is outputed to BOD
130
		bool m_bXtraX3BobInfo; // extra x3 bob info
-
 
131
		//SwitchValue m_X3BOB; // force/suppress extra bob3 info loading
53
		bool m_bWriteX3Data; // whether to compute/write x3 vertex data and extra part data
132
 
54
 
133
		void error(ErrorType type, ErrorCodes code, const char *format, ...);
55
		void error(ErrorType type, ErrorCodes code, const char *format, ...);
134
 
56
 
135
#ifdef X2BC_USE_INI_FORMATS
-
 
136
		char * readSection(const char *pszSection, const char *pszFileName, size_t *size);
-
 
137
		conststringpair parsePair(const char *left, const char *right);
-
 
138
		bool parseLines(const char *pszSectionName, char *pszData, size_t size, ParsePairCallback *callback);
-
 
139
		
-
 
140
		bool parseStatFormat(const char *pszSectionName, conststringpair &p);
-
 
141
		bool parseFormatString(const char *pszSectionName, StatFormat *f, char *format);
-
 
142
		
-
 
143
		NumberFormat * findNumberFormat(char ch);
-
 
144
#endif
-
 
145
 
-
 
146
	public:
57
	public:
147
		ErrorList errors;
58
		ErrorList errors;
148
#ifdef X2BC_USE_INI_FORMATS 
-
 
149
		FormatList formats;
-
 
150
		
-
 
151
		bool parseConstant(const char *pszSectionName, conststringpair &p);
-
 
152
		bool parseFormat(const char *pszSectionName, conststringpair &p);
-
 
153
#endif
-
 
154
		
59
		
155
		bool loadINI(const char *pszFileName);
60
		bool loadINI(const char *pszFileName);
156
		
61
		
157
		bool outputWarnings() const { return m_bOutputWarnings; }
62
		bool outputWarnings() const { return m_bOutputWarnings; }
158
		void outputWarnings(bool val) { m_bOutputWarnings=val; }
63
		void outputWarnings(bool val) { m_bOutputWarnings=val; }
159
		bool convert() const { return m_bConvert; }
64
		bool rawMode() const { return m_bRawMode; }
160
		void convert(bool val) { m_bConvert=val; }
65
		void rawMode(bool val) { m_bRawMode=val; }
161
		bool statFormatWarnings() const { return m_bStatFormatWarnings; }
-
 
162
		void statFormatWarnings(bool val) { m_bStatFormatWarnings=val; }
-
 
163
		bool extraPntInfo() const { return m_bXtraPntInfo; }
66
		bool extraPntInfo() const { return m_bXtraPntInfo; }
164
		void extraPntInfo(bool val) { m_bXtraPntInfo=val; }
67
		void extraPntInfo(bool val) { m_bXtraPntInfo=val; }
165
		bool extraX3BobInfo() const { return m_bXtraX3BobInfo; }
-
 
166
		void extraX3BobInfo(bool val) { m_bXtraX3BobInfo=val; }
68
		void writeX3Data(bool val) { m_bWriteX3Data=val; }
167
		//SwitchValue X3BOB() const { return m_X3BOB; }
69
		bool writeX3Data() const { return m_bWriteX3Data; }
168
		//void X3BOB(SwitchValue val) { m_X3BOB=val; }
-
 
169
 
70
 
170
		void clearErrors()
71
		void clearErrors()
171
		{
72
		{
172
			for(ErrorIterator &it=errors.begin(); it!=errors.end(); ++it){
73
			for(ErrorIterator &it=errors.begin(); it!=errors.end(); ++it){
173
				delete *it;
74
				delete *it;
174
			}
75
			}
175
			errors.clear();
76
			errors.clear();
176
		}
77
		}
177
		
78
		
178
		Settings() { outputWarnings(false); convert(true); statFormatWarnings(true); extraPntInfo(true); /*X3BOB(notSet);*/ }
79
		Settings() { outputWarnings(false); rawMode(false); extraPntInfo(true); }
179
		
80
		
180
		~Settings()
81
		~Settings()
181
		{
82
		{
182
#ifdef X2BC_USE_INI_FORMATS
-
 
183
			for(iterator &it=formats.begin(); it!=formats.end(); ++it){
-
 
184
				delete *it;
-
 
185
			}
-
 
186
#endif
-
 
187
			clearErrors();
83
			clearErrors();
188
		}
84
		}
189
		
85
		
190
#ifdef X2BC_USE_INI_FORMATS 
-
 
191
		const StatFormat* findStatFormat(int ID) const
-
 
192
		{
-
 
193
			for(const_iterator &it=formats.begin(); it!=formats.end(); ++it){
-
 
194
				if(it->id==ID) return *it;
-
 
195
			}
-
 
196
			return 0;
-
 
197
		}
-
 
198
#endif
-
 
199
};
86
};
200
 
87
 
201
#endif // !defined(SETTINGS_INCLUDED)
88
#endif // !defined(SETTINGS_INCLUDED)