/************************************ * file enc : utf8 * author : wuyanyi09@gmail.com ************************************/ #ifndef LIMONP_CONFIG_H #define LIMONP_CONFIG_H #include #include #include #include "logger.hpp" #include "str_functs.hpp" namespace Limonp { using std::map; using std::string; using std::cout; using std::endl; using std::ifstream; class Config { public: Config(){_isInit = false;}; ~Config(){}; bool init(const string& configFile) { if(_isInit) { LogFatal("already have been initialized. "); return false; } ifstream ifile(configFile.c_str()); if(!ifile) { LogFatal("open configFile[%s] failed.", configFile.c_str()); return false; } string line, key, value; vector vecBuf; while(getline(ifile, line)) { //line = _stripComment(line); if(line.empty()) { continue; } vecBuf.clear(); if(!splitStr(line, vecBuf, "=") || 2 != vecBuf.size()) { LogFatal("line[%s] is illegal.", line.c_str()); return false; } key = vecBuf[0]; value = vecBuf[1]; if(_map.end() != _map.find(key)) { LogFatal("key[%s] already exists.", key.c_str()); return false; } _map[key] = value; } ifile.close(); _isInit = true; return true; } void display() { for(map::iterator it = _map.begin(); it != _map.end(); it++) { cout<<"("<first<<","<second<<")"< _map; bool _isInit; }; } namespace Limonp { extern Config gConfig; } #endif