Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
/*
2
  defines Settings - class that stores all the settings used by bob_dom_bob and 
3
  bob_dom_cut when loading/saving bob1/cut1 data
4
*/
5
 
6
#ifndef SETTINGS_INCLUDED
7
#define SETTINGS_INCLUDED
8
 
9
#include "../common/ext_list.h"
10
 
11
class Settings
12
{
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{
78
			Error,
79
			Warning
80
		};
81
 
82
		enum ErrorCodes
83
		{
84
			E_BadConstantDeclaration,
85
			E_BadFormatDeclaration,
86
			E_SectionEmpty,
87
			W_LineIgnored,
88
			W_ConstantAlwaysZero
89
		};
90
 
91
		enum SwitchValue
92
		{
93
			on,
94
			off,
95
			notSet
96
		};
97
 
98
		struct ErrorMsg
99
		{
100
			ErrorType type;
101
			ErrorCodes code;
102
			char message[255];
103
		};
104
 
105
	private:
106
		typedef ext::list<ErrorMsg*> ErrorList;
107
#ifdef X2BC_USE_INI_FORMATS 
108
		typedef ext::list<StatFormat*> FormatList;
109
#endif
110
 
111
	public:
112
		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
 
118
	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
 
126
		bool m_bOutputWarnings; // write warnings to file
127
		bool m_bConvert;				// convert values
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
130
		bool m_bXtraX3BobInfo; // extra x3 bob info
131
		//SwitchValue m_X3BOB; // force/suppress extra bob3 info loading
132
 
133
		void error(ErrorType type, ErrorCodes code, const char *format, ...);
134
 
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:
147
		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
 
155
		bool loadINI(const char *pszFileName);
156
 
157
		bool outputWarnings() const { return m_bOutputWarnings; }
158
		void outputWarnings(bool val) { m_bOutputWarnings=val; }
159
		bool convert() const { return m_bConvert; }
160
		void convert(bool val) { m_bConvert=val; }
161
		bool statFormatWarnings() const { return m_bStatFormatWarnings; }
162
		void statFormatWarnings(bool val) { m_bStatFormatWarnings=val; }
163
		bool extraPntInfo() const { return m_bXtraPntInfo; }
164
		void extraPntInfo(bool val) { m_bXtraPntInfo=val; }
165
		bool extraX3BobInfo() const { return m_bXtraX3BobInfo; }
166
		void extraX3BobInfo(bool val) { m_bXtraX3BobInfo=val; }
167
		//SwitchValue X3BOB() const { return m_X3BOB; }
168
		//void X3BOB(SwitchValue val) { m_X3BOB=val; }
169
 
170
		void clearErrors()
171
		{
172
			for(ErrorIterator &it=errors.begin(); it!=errors.end(); ++it){
173
				delete *it;
174
			}
175
			errors.clear();
176
		}
177
 
178
		Settings() { outputWarnings(false); convert(true); statFormatWarnings(true); extraPntInfo(true); /*X3BOB(notSet);*/ }
179
 
180
		~Settings()
181
		{
182
#ifdef X2BC_USE_INI_FORMATS
183
			for(iterator &it=formats.begin(); it!=formats.end(); ++it){
184
				delete *it;
185
			}
186
#endif
187
			clearErrors();
188
		}
189
 
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
};
200
 
201
#endif // !defined(SETTINGS_INCLUDED)