]> git.stg.codes - stg.git/blob - stglibs/conffiles.lib/include/stg/conffiles.h
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / conffiles.lib / include / stg / 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
35 #include <map>
36 #include <string>
37
38 #include "stg/os_int.h"
39
40 //---------------------------------------------------------------------------
41
42 typedef bool (*StringCaseCmp_t)(const std::string & str1, const std::string & str2);
43
44 class CONFIGFILE
45 {
46 public:
47     CONFIGFILE(const std::string & fn, bool nook = false);
48     ~CONFIGFILE();
49     const std::string & GetFileName() const;
50
51     // æÕÎËÃÉÉ Read* ×ÏÚ×ÒÁÝÁÀÔ 0 ÐÒÉ ÕÓÐÅÛÎÏÍ ÓÞÉÔÙ×ÁÎÉÉ
52     // É EINVAL ÐÒÉ ÏÔÓÕÔÓ×ÉÉ ÐÁÒÁÍÅÔÒÁ É ×ÙÓÔÁ×ÌÑÀÔ defaulValue
53     //int ReadString(const std::string & param, char * val, int * maxLen, const char * defaultVal) const;
54     int ReadString(const std::string & param, std::string * val, const std::string & defaultVal) const;
55     int ReadTime(const std::string & param, time_t *, time_t) const;
56     int ReadShortInt(const std::string & param, short int *, short int) const;
57     int ReadInt(const std::string & param, int *, int) const;
58     int ReadLongInt(const std::string & param, long int *, long int) const;
59     int ReadLongLongInt(const std::string & param, int64_t *, int64_t) const;
60     int ReadUShortInt(const std::string & param, unsigned short int *, unsigned short int) const;
61     int ReadUInt(const std::string & param, unsigned int *, unsigned int) const;
62     int ReadULongInt(const std::string & param, unsigned long int *, unsigned long int) const;
63     int ReadULongLongInt(const std::string & param, uint64_t *, uint64_t) const;
64     int ReadDouble(const std::string & param, double * val, double defaultVal) const;
65
66     void WriteString(const std::string & param, const char * val) { return WriteString(param, std::string(val)); }
67     void WriteString(const std::string & param, const std::string& val);
68     void WriteInt(const std::string & param, int64_t val);
69     void WriteDouble(const std::string & param, double val);
70     void WriteTime(const std::string & param, time_t val);
71
72     int Error() const;
73     int Flush() const;
74
75 private:
76     std::map<std::string, std::string, StringCaseCmp_t> param_val;
77     std::string fileName;
78     mutable int error;
79     mutable bool changed;
80
81     int Flush(const std::string & path) const;
82 };
83 //---------------------------------------------------------------------------
84 #endif