1 | /*************************************************************************** |
2 | * KBlocks, a falling blocks game for KDE * |
3 | * Copyright (C) 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com> * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * |
9 | ***************************************************************************/ |
10 | #ifndef KBLOCKSCONFIGMANAGER_H_INCLUDED |
11 | #define KBLOCKSCONFIGMANAGER_H_INCLUDED |
12 | |
13 | #include <stdio.h> |
14 | #include <string> |
15 | #include <map> |
16 | |
17 | using namespace std; |
18 | class KBlocksConfigManager |
19 | { |
20 | private: |
21 | map< int, string > stConfigSectionList; |
22 | map< string, map< int, string > > stConfigKeyNameList; |
23 | map< string, map< string, string > > stConfigDataTable; |
24 | |
25 | bool isDebug; |
26 | |
27 | public: |
28 | KBlocksConfigManager(); |
29 | ~KBlocksConfigManager(); |
30 | |
31 | int SetDebugOutput(bool flag); |
32 | |
33 | int LoadConfigFile(string filename); |
34 | int SaveConfigFile(string filename); |
35 | |
36 | int GetSectionCount(); |
37 | int GetKeyCount(string SectionName); |
38 | |
39 | int GetKeyString(string SectionName, string KeyName, string* KeyString, const string Default); |
40 | int GetKeyInt(string SectionName, string KeyName, int* KeyInt, const int Default); |
41 | int GetKeyBool(string SectionName, string KeyName, bool* KeyBool, const bool Default); |
42 | |
43 | int SetKeyString(string SectionName, string KeyName, string KeyString); |
44 | int SetKeyInt(string SectionName, string KeyName, int KeyInt); |
45 | int SetKeyBool(string SectionName, string KeyName, bool KeyBool); |
46 | |
47 | private: |
48 | int ParseConfigFile(FILE* fp); |
49 | int ConstructConfigFile(FILE* fp); |
50 | |
51 | string int16tostring(int input); |
52 | }; |
53 | |
54 | #endif // KBLOCKSCONFIGMANAGER_H_INCLUDED |
55 | |
56 | |