]> git.stg.codes - stg.git/blob - stglibs/conffiles.lib/conffiles.h
Добавление исходников
[stg.git] / stglibs / conffiles.lib / conffiles.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  * 
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Date: 27.10.2002
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@ua.fm>
23  */
24
25  /*
26  $Revision: 1.5 $
27  $Date: 2009/06/22 16:00:38 $
28  */
29
30 //---------------------------------------------------------------------------
31
32 #ifndef ConfFilesH
33 #define ConfFilesH
34 #include <sys/types.h>
35 #include <stdio.h>
36 #include <map>
37 #include <string>
38
39 #include "os_int.h"
40
41 using namespace std;
42 //---------------------------------------------------------------------------
43 //#define CONF_STR_LEN    300
44 //typedef char STRING[CONF_STR_LEN];
45
46 typedef bool (*StringCaseCmp_t)(const string & str1, const string & str2);
47
48 class CONFIGFILE
49 {
50 private:
51     mutable map<string, string, StringCaseCmp_t> param_val;
52     mutable map<string, string>::iterator it;
53
54     FILE * f;
55     int Flush();
56     //int ReadFile();
57     string fileName;
58     int error;
59
60 public:
61     CONFIGFILE(const string &fn);
62     ~CONFIGFILE();
63     const string & GetFileName() const;
64
65     // 5 ÆÕÎËÃÉÉ Read* ×ÏÚ×ÒÁÝÁÀÔ 0 ÐÒÉ ÕÓÐÅÛÎÏÍ ÓÞÉÔÙ×ÁÎÉÉ
66     // É EINVAL ÐÒÉ ÏÔÓÕÔÓ×ÉÉ ÐÁÒÁÍÅÔÒÁ É ×ÙÓÔÁ×ÌÑÀÔ defaulValue
67     int ReadString(const string & param, char * val, int * maxLen, const char * defaultVal) const;
68     int ReadString(const string & param, string * val, const string & defaultVal) const;
69
70     int FindParameter(const string &parameter, string * value) const;
71
72     int ReadTime       (const string & param, time_t *,        time_t) const;
73
74     int ReadShortInt   (const string & param, short int *,     short int) const;
75     int ReadInt        (const string & param, int *,           int) const;
76     int ReadLongInt    (const string & param, long int *,      long int) const;
77     int ReadLongLongInt(const string & param, int64_t *, int64_t) const;
78
79     int ReadUShortInt   (const string & param, unsigned short int *,     unsigned short int) const;
80     int ReadUInt        (const string & param, unsigned int *,           unsigned int) const;
81     int ReadULongInt    (const string & param, unsigned long int *,      unsigned long int) const;
82     int ReadULongLongInt(const string & param, uint64_t *, uint64_t) const;
83
84     int ReadDouble (const string & param, double * val, double defaultVal) const;
85
86     int WriteString(const string & param, const char * val);
87     int WriteString(const string & param, const string & val);
88     int WriteInt   (const string & param, int64_t val);
89     int WriteDouble(const string & param, double val);
90
91     int Error();
92 };
93 //---------------------------------------------------------------------------
94 #endif