-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyConf.cc
60 lines (50 loc) · 1017 Bytes
/
MyConf.cc
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
///
/// @file MyConf.cc
/// @author sgzed([email protected])
/// @date 2018-03-26 21:43:47
///
#include "MyConf.h"
#include <string>
#include <fstream>
#include <sstream>
#include <utility>
#include <iostream>
using std::map;
using std::ifstream;
using std::cout; using std::endl;
using std::istringstream;
map<string,string> MyConf::_configMap ;
pthread_once_t MyConf::_ponce = PTHREAD_ONCE_INIT;
MyConf* MyConf::_value =NULL;
void MyConf::init()
{
_value = new MyConf();
string filepath("./conf/my.conf");
ifstream ifs(filepath);
string line,key,value;
if(!ifs.good())
{
cout << "open " << filepath << " failed" << endl;
return ;
}
else
{
while(getline(ifs,line))
{
istringstream iss(line);
iss >> key >> value;
_configMap.insert(make_pair(key,value));
}
ifs.close();
}
::atexit(destroy);
}
map<string,string>& MyConf::getConfigMap()
{
return _configMap;
}
void MyConf::show()
{
for(auto iter : _configMap)
cout << iter.first << " " << iter.second << endl;;
}