Implemented configfilemanager
This commit is contained in:
40
src/configFileManager.h
Normal file
40
src/configFileManager.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef _CONFIGFILEMANAGER_H
|
||||
#define _CONFIGFILEMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "usermanager.h"
|
||||
|
||||
class configFileManager{
|
||||
private:
|
||||
std::map<std::string, std::string> configs;
|
||||
|
||||
public:
|
||||
configFileManager(std::string filepath = "./ncsambawatcher.config")
|
||||
{
|
||||
std::ifstream is(filepath);
|
||||
std::string tmp;
|
||||
while(std::getline(is, tmp))
|
||||
{
|
||||
std::vector<std::string> splited = splitString(tmp, '=');
|
||||
if (splited.size() != 2)
|
||||
{
|
||||
std::cerr << "Invalid line: " << tmp << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
configs.insert(std::make_pair(splited.at(0), splited.at(1)));
|
||||
}
|
||||
}
|
||||
|
||||
std::string at(std::string &config)
|
||||
{
|
||||
return configs.at(config);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // _CONFIGFILEMANAGER_H
|
||||
Reference in New Issue
Block a user