summaryrefslogtreecommitdiff
path: root/TConfig.h
blob: ba12b3f304206140a3e3a4431dd3c7b15718ab93 (plain)
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
#ifndef _TCONFIG_H_
#define _TCONFIG_H_
/*
 *      TConfig.h
 *      
 *      Copyright 2009 Florian <flo@localhost.localdomain>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */


#include <iostream>
#include <string>
#include <vector>

using namespace std;

#include "TConfigReadOnly.h"

class TConfig : public TConfigReadOnly
{
	public:
		TConfig();
		TConfig(string f);
		bool loadconfig(string f);
		
		virtual int get_integer(string name);
		virtual string get_string(string name);
		virtual bool get_boolean(string name);
		
		virtual int get_valid_integer(string name, int def);
		virtual string get_valid_string(string name, string def);
		virtual bool get_valid_boolean(string name, bool def);
		
		virtual bool is_stored(string name);
		
		virtual bool is_string(string name);
		virtual bool is_integer(string name);
		virtual bool is_boolean(string name);
		
		vector<int> get_errors();
	private:
		struct conf_ent
		{
			string name;
			string value;
			bool is_string;
		};
		vector<conf_ent> entries;
		vector<int> errorlines;
		
		int findentry(string name);
		
		static string remove_quotes(string str);
		static string removecomments(string s);
		static int findunquoted(string haystack, string needle);
		static bool is_correct(string s);
};
#endif