MCPcopy Create free account
hub / github.com/caozhiyi/CppNet / LoadFile

Method LoadFile

base/Config.cpp:16–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16bool CConfig::LoadFile(const std::string& path) {
17 SetFilePath(path);
18 std::fstream file(path);
19 if (!file) {
20 LOG_ERROR("load config file failed, can't open file.");
21 return false;
22 }
23 std::string line;
24 std::string key;
25 std::string value;
26 std::map<std::string, std::string> temp_map;
27 while (!file.eof()) {
28 char buf[1024] = { 0 };
29 file.getline(buf, 1024);
30 if (strlen(buf) < 3) {
31 continue;
32 }
33 line = buf;
34 _Trim(line);
35 if (line[0] == '#') {
36 continue;
37 }
38
39 key = line.substr(0, line.find_first_of("="));
40 value = line.substr(line.find_first_of("=") + 1);
41 _Trim(key);
42 _Trim(value);
43 LOG_INFO("load config key : %s, value : %s", key.c_str(), value.c_str());
44 temp_map[key] = value;
45 }
46
47 std::unique_lock<std::mutex> lock(_mutex);
48 _config_map = temp_map;
49 return true;
50}
51
52int CConfig::GetIntValue(const std::string& key) {
53 try {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected