00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ConfigLoader.h"
00025
00026
00027
00028 ConfigLoader::ConfigLoader(string configPath){
00029
00030
00031 ifstream configReader;
00032 configReader.open(configPath.data());
00033
00034
00035 if(!configReader){
00036 cout<<"Configuration file not found!"<<endl;
00037 throw 0;
00038 }
00039
00040
00041 char row[200];
00042 while(!configReader.eof()){
00043 configReader.getline(row, 200);
00044
00045
00046 if (!(row[0] == '#' | row[0] == ' ' | row[0] == 13 | row[0] == 0)){
00047 string key = "";
00048 int j=0;
00049 while((row[j] != ' ') && (row[j]!= '=') && j<200){
00050 key += row[j];
00051 j++;
00052 }
00053 while(row[j] == ' ' | row [j] == '=')
00054 j++;
00055 string value = "";
00056 while(row[j] != 0 && row [j] != ' ' && row[j] != 13 && row[j] != 0){
00057 value += row[j];
00058 j++;
00059 }
00060
00061
00062 configMap[key] = value;
00063 }
00064 }
00065 configReader.close();
00066 }
00067
00068
00069
00070 ConfigLoader::~ConfigLoader(){
00071 #ifdef MEMORY_DEBUG
00072 cout<<"DELETING CONFIG LOADER"<<endl;
00073 #endif//MEMORY_DEBUG
00074 }
00075
00076
00077
00078
00079
00080
00081
00082 const char* ConfigLoader::getCharData(string key){
00083 string s = configMap[key];
00084 if(s.empty()){
00085 cerr<<"Key \""<<key<<"\" not present in config file"<<endl;
00086 throw 0;
00087 }
00088 return s.data();
00089 }
00090
00091
00092
00093 string ConfigLoader::getStringData(string key){
00094 string s = configMap[key];
00095 if(s.empty()){
00096 cerr<<"Key \""<<key<<"\" not present in config file"<<endl;
00097 throw 0;
00098 }
00099 return s;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 void ConfigLoader::printConfig(){
00109 cout<<"Configuration for Neuron Application"<<endl;
00110 cout<<"---------------------------------------"<<endl;
00111 map<string, string>::iterator iter;
00112 for (iter = configMap.begin(); iter != configMap.end(); ++iter) {
00113 cout << "Key: " << iter->first << "; "
00114 << "Value: " << iter->second << endl;
00115 }
00116 }
00117
00118