-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathIniProcessor.h
82 lines (66 loc) · 1.61 KB
/
IniProcessor.h
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
73
74
75
76
77
78
79
80
81
82
/*
* IniProcessor class header file
* Author: Sun Junwen
* Version: 1.2.5
*/
#ifndef _INI_PROCESSOR_H_
#define _INI_PROCESSOR_H_
#include <cstdlib>
#include <string>
#include <istream>
#include <map>
#include "IniValue.h"
using namespace std;
const string SPACES(" \t\r\n");
class IniProcessor
{
public:
#if defined(UNICODE) || defined(_UNICODE)
typedef wstring tstring;
#else
typedef string tstring;
#endif
typedef map<string, IniValue> IniMap;
/*
* Constructor
* Specific the ini file name
*/
IniProcessor()
{}
// Set value into map
void SetMap(const IniMap& map)
{ m_iniMap = map; }
// Save value into file
virtual void Save() = 0;
// Convert value to string
inline string ToString() const
{ return ToString(m_iniMap); }
string ToString(IniMap map) const;
protected:
// Get info from file
IniMap GetInfo(istream& in, bool bProcSection, bool bRefresh);
private:
IniMap m_iniMap;
inline string strtrim_right(const string& s, const string& spaces = SPACES)
{
string d(s);
string::size_type i(d.find_last_not_of(spaces));
if(i == string::npos)
return "";
else
return d.erase(d.find_last_not_of(spaces) + 1);
} // end of trim_right
inline string strtrim_left(const string& s, const string& spaces = SPACES)
{
string d(s);
return d.erase(0, s.find_first_not_of(spaces));
} // end of trim_left
inline string strtrim(const string& s, const string& spaces = SPACES)
{
string d(s);
return strtrim_left(strtrim_right(d, spaces), spaces);
} // end
// Add a section to map
void AddSection(const string& sectionName, const IniValue::StrMap& sectionMap);
};
#endif