ITAConfigUtils.cpp 26.9 KB
Newer Older
Fabian Schlieper's avatar
Fabian Schlieper committed
1
2
3
4
5
6
7
8
9
10
11
#include <ITAConfigUtils.h>

#include <ITAException.h>
#include <ITAFileSystemUtils.h>
#include <ITAStringUtils.h>

#include <cstdlib>

std::string sCurrentINIFile = "";
std::string sCurrentSection = "";

12
13
bool INIFileExists( const std::string& sINIFilename )
{
Fabian Schlieper's avatar
Fabian Schlieper committed
14
	// Nur pr�fen ob die Datei existiert
15
	return doesFileExist( sINIFilename );
Fabian Schlieper's avatar
Fabian Schlieper committed
16
17
}

18
19
20
21
22
23
bool INIFileSectionExists( const std::string& sINIFilename, const std::string& sSection )
{
	std::vector<std::string> vsSects = INIFileGetSections( sINIFilename );
	std::string s = toUppercase( sSection );
	for( unsigned int i = 0; i < vsSects.size(); i++ )
		if( toUppercase( vsSects[ i ] ).compare( s ) == 0 ) return true;
Fabian Schlieper's avatar
Fabian Schlieper committed
24
25
26
	return false;
}

27
28
29
30
31
32
bool INIFileKeyExists( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey )
{
	std::vector<std::string> vsKeys = INIFileGetKeys( sINIFilename, sSection );
	std::string s = toUppercase( sKey );
	for( unsigned int i = 0; i < vsKeys.size(); i++ )
		if( toUppercase( vsKeys[ i ] ).compare( s ) == 0 ) return true;
Fabian Schlieper's avatar
Fabian Schlieper committed
33
34
35
	return false;
}

36
37
void INIFileUseFile( const std::string& sINIFilename )
{
Fabian Schlieper's avatar
Fabian Schlieper committed
38
39
40
41
42
43
	// Sicherstellen das die INI-Datei existiert
	// [fwe 2008-11-07] Bugfix, baby! Das geht beim reinen Schreiben nicht: INIFileRequireINIFile(sINIFilename);

	sCurrentINIFile = sINIFilename;
}

44
void INIFileUseSection( const std::string& sSection ) {
Fabian Schlieper's avatar
Fabian Schlieper committed
45
46
47
48
49
50
	// Sicherstellen das die Sektion existiert
	// [fwe 2008-11-07] Bugfix, baby! Das geht beim reinen Schreiben nicht: INIFileRequireSection(sCurrentINIFile, sSection);

	sCurrentSection = sSection;
}

51
52
53
bool INIFileUseSectionIfExists( const std::string& sSection ) {
	if( INIFileSectionExists( sSection ) ) {
		INIFileUseSection( sSection );
Fabian Schlieper's avatar
Fabian Schlieper committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
		return true;
	}
	return false;
}


void INIFileUseNothing() {
	sCurrentINIFile = "";
	sCurrentSection = "";
}

/* +-----------------------------------------------------------------------------------------+
 * |                                                                                         |
 * |  Assertion-Funktionen: Lösen Ausnahmen aus, falls Bedingungen nicht erfüllt sind.       |
 * |                                                                                         |
 * +-----------------------------------------------------------------------------------------+ */

71
72
73
74
75
76
77
void INIFileRequireINIFile( const std::string& sINIFilename ) {
	if( sINIFilename.size() == 0 )
		ITA_EXCEPT1( INVALID_PARAMETER, "INI file name can not be an empty string" );
	if( !doesPathExist( sINIFilename ) )
		ITA_EXCEPT1( FILE_NOT_FOUND, std::string( "INI file \"" ) + sINIFilename + std::string( "\" not found" ) );
	if( !isFile( sINIFilename ) )
		ITA_EXCEPT1( FILE_NOT_FOUND, std::string( "The path \"" ) + sINIFilename + std::string( "\" does not point to a file" ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
78
79
}

80
81
82
void INIFileRequireSection( const std::string& sINIFilename, const std::string& sSection ) {
	if( !INIFileSectionExists( sINIFilename, sSection ) )
		ITA_EXCEPT1( IO_ERROR, std::string( "INI file \"" ) + sINIFilename + std::string( "\" is missing a [" ) + sSection + std::string( "] section" ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
83
84
}

85
86
87
88
void INIFileRequireKey( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey ) {
	INIFileRequireSection( sINIFilename, sSection );
	if( !INIFileKeyExists( sINIFilename, sSection, sKey ) )
		ITA_EXCEPT1( IO_ERROR, std::string( "In INI file \"" ) + sINIFilename + std::string( "\" section [" ) + sSection + std::string( "]: Missing a \"" ) + sKey + std::string( "\" key" ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
89
90
}

91
void INIFileRequireNonemptyKey( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey ) {
Fabian Schlieper's avatar
Fabian Schlieper committed
92
	// Abgebildet �ber die explizite String-Lesefunktion (Ergebnis wegschmeissen)
93
	INIFileReadStringExplicit( sINIFilename, sSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
94
95
96
97
98
99
100
101
}

/* +----------------------------------------------------------------------------------------------+
 * |                                                                                              |
 * |  Implizite Lese-Funktionen                                                                   |
 * |                                                                                              |
 * +----------------------------------------------------------------------------------------------+ */

102
103
104
int INIFileReadInt( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, int iDefaultValue ) {
	std::string s = INIFileReadString( sINIFilename, sSection, sKey );
	return ( s.empty() ? iDefaultValue : StringToInt( s ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
105
106
}

107
108
109
unsigned int INIFileReadUInt( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, unsigned int uiDefaultValue ) {
	std::string s = INIFileReadString( sINIFilename, sSection, sKey );
	return ( s.empty() ? uiDefaultValue : StringToUInt( s ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
110
111
}

112
113
114
long INIFileReadLong( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, long lDefaultValue ) {
	std::string s = INIFileReadString( sINIFilename, sSection, sKey );
	return ( s.empty() ? lDefaultValue : ( long ) StringToInt( s ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
115
116
}

117
118
119
float INIFileReadFloat( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, float fDefaultValue ) {
	std::string s = INIFileReadString( sINIFilename, sSection, sKey );
	return ( s.empty() ? fDefaultValue : StringToFloat( s ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
120
121
}

122
123
124
double INIFileReadDouble( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, double dDefaultValue ) {
	std::string s = INIFileReadString( sINIFilename, sSection, sKey );
	return ( s.empty() ? dDefaultValue : StringToFloat( s ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
125
126
}

127
128
bool INIFileReadBool( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, bool bDefaultValue ) {
	std::string s = toUppercase( INIFileReadString( sINIFilename, sSection, sKey, ( bDefaultValue ? "yes" : "no" ) ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
129
130
131

	int i = -1;

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
	if( s == "TRUE" ) i = 1;
	if( s == "YES" ) i = 1;
	if( s == "ENABLED" ) i = 1;
	if( s == "JA" ) i = 1;
	if( s == "1" ) i = 1;
	if( s == "JO" ) i = 1;
	if( s == "SIGGI" ) i = 1;
	if( s == "I LIKE" ) i = 1;
	if( s == "MAG ICH" ) i = 1;
	if( s == "FREILICH" ) i = 1;
	if( s == "KLAR" ) i = 1;
	if( s == "JAWOHL" ) i = 1;
	if( s == "SELBSTVERSTÄNDLICH" ) i = 1;
	if( s == "TOP" ) i = 1;

	if( s == "FALSE" ) i = 0;
	if( s == "NO" ) i = 0;
	if( s == "DISABLED" ) i = 0;
	if( s == "NEIN" ) i = 0;
	if( s == "0" ) i = 0;
	if( s == "NÖ" ) i = 0;
	if( s == "NOPE" ) i = 0;
	if( s == "I DONT LIKE" ) i = 0;
	if( s == "MAG ICH NICHT" ) i = 0;
	if( s == "LASS DAS" ) i = 0;
	if( s == "VETO" ) i = 1;

	if( i == -1 )
		ITA_EXCEPT1( IO_ERROR, std::string( "In INI file \"" ) + sINIFilename + std::string( "\" section [" ) + sSection + std::string( "] key \"" ) + sKey + std::string( "\": Invalid value (\"" + s + "\") for a boolean key" ) );

	return ( i == 1 );
}

std::vector<int> INIFileReadIntList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringList( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
170
	std::vector<int> vout;
171
172
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ )
		vout.push_back( atoi( ( *cit ).c_str() ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
173
174
175
	return vout;
}

176
177
178
179
180
std::vector<unsigned int> INIFileReadUIntList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringList( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
181
	std::vector<unsigned int> vout;
182
183
184
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ ) {
		int i = atoi( ( *cit ).c_str() );
		vout.push_back( ( i >= 0 ? ( unsigned int ) i : 0 ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
185
186
187
188
	}
	return vout;
}

189
190
191
192
193
std::vector<float> INIFileReadFloatList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringList( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
194
	std::vector<float> vout;
195
196
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ )
		vout.push_back( ( float ) atof( ( *cit ).c_str() ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
197
198
199
	return vout;
}

200
201
202
203
204
std::vector<double> INIFileReadDoubleList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringList( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
205
	std::vector<double> vout;
206
207
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ )
		vout.push_back( atof( ( *cit ).c_str() ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
208
209
210
	return vout;
}

211
212
213
214
215
std::vector<std::string> INIFileReadStringList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::string s = INIFileReadString( sINIFilename, sSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
216
217
218
	std::vector<std::string> v;

	int a = 0;
219
	int b = ( int ) s.find( cSeparator, 0 );
Fabian Schlieper's avatar
Fabian Schlieper committed
220
221

	// Kein Separator gefunden?
222
	if( b == ( int ) s.npos ) {
Fabian Schlieper's avatar
Fabian Schlieper committed
223
		// Falls der String nicht leer ist, kommt er als einziges Element in den Vektor
224
225
		std::string t = stripSpaces( s );
		if( !t.empty() ) v.push_back( t );
Fabian Schlieper's avatar
Fabian Schlieper committed
226
227
		return v;
	}
228

Fabian Schlieper's avatar
Fabian Schlieper committed
229
230
231
232
233
	// Mindestens ein Separator enthalten!
	do {
		// Gefundenen Substring von Leerr�umen befreien und speichern
		// Wichtig: Hier wird auch gespeichert, wenn der Substring leer ist
		//          da wir hier zwischen zwei Separatoren sind.
234
235
236
		v.push_back( stripSpaces( s.substr( a, b - a ) ) );
		a = b + 1;
	} while( ( b = ( int ) s.find( cSeparator, a ) ) != ( int ) s.npos );
Fabian Schlieper's avatar
Fabian Schlieper committed
237
238

	// Den Rest speichern
239
	v.push_back( stripSpaces( s.substr( a, s.length() - a ) ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
240
241
242
243
244
245
246
247
248
249

	return v;
}

/* +-----------------------------------------------------------------------------------------+
 * |                                                                                         |
 * |  Explizite Lese-Funktionen.                                                             |
 * |                                                                                         |
 * +-----------------------------------------------------------------------------------------+ */

250
251
252
253
254
int INIFileReadIntExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey ) {
	std::string s = INIFileReadStringExplicit( sINIFilename, sSection, sKey );
	return StringToInt( s );
Fabian Schlieper's avatar
Fabian Schlieper committed
255
256
}

257
258
259
260
261
unsigned int INIFileReadUIntExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey ) {
	std::string s = INIFileReadStringExplicit( sINIFilename, sSection, sKey );
	return StringToUInt( s );
Fabian Schlieper's avatar
Fabian Schlieper committed
262
263
}

264
265
266
267
268
long INIFileReadLongExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey ) {
	std::string s = INIFileReadStringExplicit( sINIFilename, sSection, sKey );
	return ( long ) StringToInt( s );
Fabian Schlieper's avatar
Fabian Schlieper committed
269
270
}

271
272
273
274
275
float INIFileReadFloatExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey ) {
	std::string s = INIFileReadStringExplicit( sINIFilename, sSection, sKey );
	return StringToFloat( s );
Fabian Schlieper's avatar
Fabian Schlieper committed
276
277
}

278
279
280
281
282
double INIFileReadDoubleExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey ) {
	std::string s = INIFileReadStringExplicit( sINIFilename, sSection, sKey );
	return StringToDouble( s );
Fabian Schlieper's avatar
Fabian Schlieper committed
283
284
}

285
286
287
288
bool INIFileReadBoolExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey ) {
	std::string s = toUppercase( INIFileReadStringExplicit( sINIFilename, sSection, sKey ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
289
290
291

	int i = -1;

292
293
294
295
	if( s == "TRUE" ) i = 1;
	if( s == "YES" ) i = 1;
	if( s == "JA" ) i = 1;
	if( s == "1" ) i = 1;
Fabian Schlieper's avatar
Fabian Schlieper committed
296

297
298
299
300
	if( s == "FALSE" ) i = 0;
	if( s == "NO" ) i = 0;
	if( s == "NEIN" ) i = 0;
	if( s == "0" ) i = 0;
Fabian Schlieper's avatar
Fabian Schlieper committed
301

302
303
	if( i == -1 )
		ITA_EXCEPT1( IO_ERROR, std::string( "In INI file \"" ) + sINIFilename + std::string( "\" section [" ) + sSection + std::string( "] key \"" ) + sKey + std::string( "\": Invalid value (\"" + s + "\") for a boolean key" ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
304

305
	return ( i == 1 );
Fabian Schlieper's avatar
Fabian Schlieper committed
306
307
}

308
309
310
311
312
313
314
std::string INIFileReadStringExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey ) {
	INIFileRequireKey( sINIFilename, sSection, sKey );
	std::string s = stripSpaces( INIFileReadString( sINIFilename, sSection, sKey ) );
	if( s.empty() )
		ITA_EXCEPT1( IO_ERROR, std::string( "In INI file \"" ) + sINIFilename + std::string( "\" section [" ) + sSection + std::string( "]: The key \"" ) + sKey + std::string( "\" must have a value" ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
315
316
317
	return s;
}

318
319
320
321
322
std::vector<int> INIFileReadIntListExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringListExplicit( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
323
	std::vector<int> vout;
324
325
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ )
		vout.push_back( atoi( ( *cit ).c_str() ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
326
327
328
	return vout;
}

329
330
331
332
333
std::vector<unsigned int> INIFileReadUIntListExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringListExplicit( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
334
	std::vector<unsigned int> vout;
335
336
337
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ ) {
		int i = atoi( ( *cit ).c_str() );
		vout.push_back( ( i >= 0 ? ( unsigned int ) i : 0 ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
338
339
340
341
	}
	return vout;
}

342
343
344
345
346
std::vector<float> INIFileReadFloatListExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringListExplicit( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
347
	std::vector<float> vout;
348
349
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ )
		vout.push_back( ( float ) atof( ( *cit ).c_str() ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
350
351
352
	return vout;
}

353
354
355
356
357
std::vector<double> INIFileReadDoubleListExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::vector<std::string> vin = INIFileReadStringListExplicit( sINIFilename, sSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
358
	std::vector<double> vout;
359
360
	for( std::vector<std::string>::const_iterator cit = vin.begin(); cit != vin.end(); cit++ )
		vout.push_back( atof( ( *cit ).c_str() ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
361
362
363
	return vout;
}

364
365
366
367
368
std::vector<std::string> INIFileReadStringListExplicit( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	char cSeparator ) {
	std::string s = INIFileReadString( sINIFilename, sSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
369
370
371
	std::vector<std::string> v;

	int a = 0;
372
	int b = ( int ) s.find( cSeparator, 0 );
Fabian Schlieper's avatar
Fabian Schlieper committed
373
374

	// Kein Separator gefunden?
375
	if( b == ( int ) s.npos ) {
Fabian Schlieper's avatar
Fabian Schlieper committed
376
		// Falls der String nicht leer ist, kommt er als einziges Element in den Vektor
377
378
		std::string t = stripSpaces( s );
		if( !t.empty() ) v.push_back( t );
Fabian Schlieper's avatar
Fabian Schlieper committed
379
380
		return v;
	}
381

Fabian Schlieper's avatar
Fabian Schlieper committed
382
383
384
385
386
	// Mindestens ein Separator enthalten!
	do {
		// Gefundenen Substring von Leerr�umen befreien und speichern
		// Wichtig: Hier wird auch gespeichert, wenn der Substring leer ist
		//          da wir hier zwischen zwei Separatoren sind.
387
388
389
		v.push_back( stripSpaces( s.substr( a, b - a ) ) );
		a = b + 1;
	} while( ( b = ( int ) s.find( cSeparator, a ) ) != ( int ) s.npos );
Fabian Schlieper's avatar
Fabian Schlieper committed
390
391

	// Den Rest speichern
392
	v.push_back( stripSpaces( s.substr( a, s.length() - a ) ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
393
394

	// Nicht-leere Liste erforderlich
395
396
	if( v.empty() )
		ITA_EXCEPT1( IO_ERROR, std::string( "In INI file \"" ) + sINIFilename + std::string( "\" section [" ) + sSection + std::string( "]: The value of key \"" ) + sKey + std::string( "\" must be a non-empty list" ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

	return v;
}


/* +-----------------------------------------------------------------------------------------+
 * |                                                                                         |
 * |  Schreibfunktionen                                                                      |
 * |                                                                                         |
 * |  - Existiert eine INI-Datei nicht, so wird sie angelegt.                                |                                                                                      |
 * |  - Existiert eine Sektion nicht, so wird sie angelegt.                                  |                      |
 * |  - Existiert ein Schl�ssel bereits, so wird sein Wert �berschrieben                     |
 * |                                                                                         |
 * +-----------------------------------------------------------------------------------------+ */

412
413
bool INIFileWriteInt( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, int iValue ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, IntToString( iValue ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
414
415
}

416
417
bool INIFileWriteUInt( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, unsigned int uiValue ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, UIntToString( uiValue ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
418
419
}

420
421
bool INIFileWriteLong( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, long lValue ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, LongToString( lValue ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
422
423
}

424
425
bool INIFileWriteFloat( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, float fValue, int iDecimalPlaces ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, FloatToString( fValue, iDecimalPlaces ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
426
427
}

428
429
bool INIFileWriteDouble( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, double dValue, int iDecimalPlaces ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, DoubleToString( dValue, iDecimalPlaces ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
430
431
}

432
433
bool INIFileWriteBool( const std::string& sINIFilename, const std::string& sSection, const std::string& sKey, bool bValue ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, ( bValue ? "1" : "0" ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
434
435
}

436
437
438
439
440
441
bool INIFileWriteIntList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	const std::vector<int>& viValues,
	std::string sSeparator ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, IntVecToString( viValues, sSeparator ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
442
443
}

444
445
446
447
448
449
bool INIFileWriteUIntList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	const std::vector<unsigned int>& vuiValues,
	std::string sSeparator ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, UIntVecToString( vuiValues, sSeparator ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
450
451
}

452
453
454
455
456
457
bool INIFileWriteFloatList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	const std::vector<float>& vfValues,
	std::string sSeparator ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, FloatVecToString( vfValues, -1, sSeparator ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
458
459
}

460
461
462
463
464
465
bool INIFileWriteDoubleList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	const std::vector<double>& vdValues,
	std::string sSeparator ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, DoubleVecToString( vdValues, -1, sSeparator ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
466
467
}

468
469
470
471
472
473
bool INIFileWriteStringList( const std::string& sINIFilename,
	const std::string& sSection,
	const std::string& sKey,
	const std::vector<std::string>& vsValues,
	std::string sSeparator ) {
	return INIFileWriteString( sINIFilename, sSection, sKey, StringVecToString( vsValues, sSeparator ) );
Fabian Schlieper's avatar
Fabian Schlieper committed
474
475
476
477
478
479
480
481
}

/* +-----------------------------------------------------------------------------------------+
 * |                                                                                         |
 * |  Alias-Funktionen f�r vorausgew�hlte INI-Dateien und Sektionen                          |
 * |                                                                                         |
 * +-----------------------------------------------------------------------------------------+ */

482
483
bool INIFileSectionExists( const std::string& sSection )
{
484
	return INIFileSectionExists( sCurrentINIFile, sSection );
Fabian Schlieper's avatar
Fabian Schlieper committed
485
486
}

487
488
std::vector<std::string> INIFileGetSections()
{
489
	return INIFileGetSections( sCurrentINIFile );
Fabian Schlieper's avatar
Fabian Schlieper committed
490
491
}

492
493
bool INIFileKeyExists( const std::string& sKey ) {
	return INIFileKeyExists( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
494
495
}

496
497
std::vector<std::string> INIFileGetKeys( const std::string& sSection ) {
	return INIFileGetKeys( sCurrentINIFile, sSection );
Fabian Schlieper's avatar
Fabian Schlieper committed
498
499
}

500
501
void INIFileRequireSection( const std::string& sSection ) {
	return INIFileRequireSection( sCurrentINIFile, sSection );
Fabian Schlieper's avatar
Fabian Schlieper committed
502
503
}

504
505
void INIFileRequireKey( const std::string& sKey ) {
	return INIFileRequireKey( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
506
507
}

508
509
void INIFileRequireNonemptyKey( const std::string& sKey ) {
	return INIFileRequireNonemptyKey( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
510
511
}

512
513
int INIFileReadInt( const std::string& sKey, int iDefaultValue ) {
	return INIFileReadInt( sCurrentINIFile, sCurrentSection, sKey, iDefaultValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
514
515
}

516
517
unsigned int INIFileReadUInt( const std::string& sKey, unsigned int uiDefaultValue ) {
	return INIFileReadUInt( sCurrentINIFile, sCurrentSection, sKey, uiDefaultValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
518
519
}

520
521
long INIFileReadLong( const std::string& sKey, long lDefaultValue ) {
	return INIFileReadLong( sCurrentINIFile, sCurrentSection, sKey, lDefaultValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
522
523
}

524
525
float INIFileReadFloat( const std::string& sKey, float fDefaultValue ) {
	return INIFileReadFloat( sCurrentINIFile, sCurrentSection, sKey, fDefaultValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
526
527
}

528
529
double INIFileReadDouble( const std::string& sKey, double dDefaultValue ) {
	return INIFileReadDouble( sCurrentINIFile, sCurrentSection, sKey, dDefaultValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
530
531
}

532
533
bool INIFileReadBool( const std::string& sKey, bool bDefaultValue ) {
	return INIFileReadBool( sCurrentINIFile, sCurrentSection, sKey, bDefaultValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
534
535
}

536
537
std::string INIFileReadString( const std::string& sKey, std::string sDefaultValue )
{
538
	return INIFileReadString( sCurrentINIFile, sCurrentSection, sKey, sDefaultValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
539
540
}

541
542
std::vector<int> INIFileReadIntList( const std::string& sKey, char cSeparator )
{
543
	return INIFileReadIntList( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
544
545
}

546
547
std::vector<unsigned int> INIFileReadUIntList( const std::string& sKey, char cSeparator )
{
548
	return INIFileReadUIntList( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
549
550
}

551
552
std::vector<float> INIFileReadFloatList( const std::string& sKey, char cSeparator )
{
553
	return INIFileReadFloatList( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
554
555
}

556
557
std::vector<double> INIFileReadDoubleList( const std::string& sKey, char cSeparator )
{
558
	return INIFileReadDoubleList( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
559
560
}

561
562
std::vector<std::string> INIFileReadStringList( const std::string& sKey, char cSeparator )
{
563
	return INIFileReadStringList( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
564
565
}

566
567
int INIFileReadIntExplicit( const std::string& sKey )
{
568
	return INIFileReadIntExplicit( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
569
570
}

571
572
unsigned int INIFileReadUIntExplicit( const std::string& sKey )
{
573
	return INIFileReadUIntExplicit( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
574
575
}

576
577
long INIFileReadLongExplicit( const std::string& sKey )
{
578
579
	return INIFileReadLongExplicit( sCurrentINIFile, sCurrentSection, sKey );
}
Fabian Schlieper's avatar
Fabian Schlieper committed
580

581
582
float INIFileReadFloatExplicit( const std::string& sKey ) {
	return INIFileReadFloatExplicit( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
583
584
}

585
586
double INIFileReadDoubleExplicit( const std::string& sKey ) {
	return INIFileReadDoubleExplicit( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
587
588
}

589
590
bool INIFileReadBoolExplicit( const std::string& sKey ) {
	return INIFileReadBoolExplicit( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
591
592
}

593
594
std::string INIFileReadStringExplicit( const std::string& sKey ) {
	return INIFileReadStringExplicit( sCurrentINIFile, sCurrentSection, sKey );
Fabian Schlieper's avatar
Fabian Schlieper committed
595
596
}

597
598
std::vector<int> INIFileReadIntListExplicit( const std::string& sKey, char cSeparator ) {
	return INIFileReadIntListExplicit( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
599
600
}

601
602
std::vector<unsigned int> INIFileReadUIntListExplicit( const std::string& sKey, char cSeparator ) {
	return INIFileReadUIntListExplicit( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
603
604
}

605
606
std::vector<float> INIFileReadFloatListExplicit( const std::string& sKey, char cSeparator ) {
	return INIFileReadFloatListExplicit( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
607
608
}

609
610
std::vector<double> INIFileReadDoubleListExplicit( const std::string& sKey, char cSeparator ) {
	return INIFileReadDoubleListExplicit( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
611
612
}

613
614
std::vector<std::string> INIFileReadStringListExplicit( const std::string& sKey, char cSeparator ) {
	return INIFileReadStringListExplicit( sCurrentINIFile, sCurrentSection, sKey, cSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
615
616
}

617
618
bool INIFileWriteInt( const std::string& sKey, int iValue ) {
	return INIFileWriteInt( sCurrentINIFile, sCurrentSection, sKey, iValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
619
620
}

621
622
bool INIFileWriteUInt( const std::string& sKey, unsigned int uiValue ) {
	return INIFileWriteUInt( sCurrentINIFile, sCurrentSection, sKey, uiValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
623
624
}

625
626
bool INIFileWriteLong( const std::string& sKey, long lValue ) {
	return INIFileWriteLong( sCurrentINIFile, sCurrentSection, sKey, lValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
627
628
}

629
630
bool INIFileWriteFloat( const std::string& sKey, float fValue, int iDecimalPlaces ) {
	return INIFileWriteFloat( sCurrentINIFile, sCurrentSection, sKey, fValue, iDecimalPlaces );
Fabian Schlieper's avatar
Fabian Schlieper committed
631
632
}

633
634
bool INIFileWriteDouble( const std::string& sKey, double dValue, int iDecimalPlaces ) {
	return INIFileWriteDouble( sCurrentINIFile, sCurrentSection, sKey, dValue, iDecimalPlaces );
Fabian Schlieper's avatar
Fabian Schlieper committed
635
636
}

637
638
bool INIFileWriteBool( const std::string& sKey, bool bValue ) {
	return INIFileWriteBool( sCurrentINIFile, sCurrentSection, sKey, bValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
639
640
}

641
642
bool INIFileWriteString( const std::string& sKey, const std::string& sValue ) {
	return INIFileWriteString( sCurrentINIFile, sCurrentSection, sKey, sValue );
Fabian Schlieper's avatar
Fabian Schlieper committed
643
644
}

645
646
647
648
bool INIFileWriteIntList( const std::string& sKey,
	const std::vector<int>& viValues,
	std::string sSeparator ) {
	return INIFileWriteIntList( sCurrentINIFile, sCurrentSection, sKey, viValues, sSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
649
650
}

651
652
653
654
bool INIFileWriteUIntList( const std::string& sKey,
	const std::vector<unsigned int>& vuiValues,
	std::string sSeparator ) {
	return INIFileWriteUIntList( sCurrentINIFile, sCurrentSection, sKey, vuiValues, sSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
655
656
}

657
658
659
660
bool INIFileWriteFloatList( const std::string& sKey,
	const std::vector<float>& vfValues,
	std::string sSeparator ) {
	return INIFileWriteFloatList( sCurrentINIFile, sCurrentSection, sKey, vfValues, sSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
661
662
}

663
664
665
666
bool INIFileWriteDoubleList( const std::string& sKey,
	const std::vector<double>& vdValues,
	std::string sSeparator ) {
	return INIFileWriteDoubleList( sCurrentINIFile, sCurrentSection, sKey, vdValues, sSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
667
668
}

669
670
671
672
bool INIFileWriteStringList( const std::string& sKey,
	const std::vector<std::string>& vsValues,
	std::string sSeparator ) {
	return INIFileWriteStringList( sCurrentINIFile, sCurrentSection, sKey, vsValues, sSeparator );
Fabian Schlieper's avatar
Fabian Schlieper committed
673
}