Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F121307455
ConfigFileParser.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 9, 23:46
Size
2 KB
Mime Type
text/x-c
Expires
Fri, Jul 11, 23:46 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27308701
Attached To
R8929 Conjugate Gradient Solver
ConfigFileParser.cpp
View Options
/** @file ConfigFileParser.cpp
* @author Sergio Hernandez
*
* This file is part of the Conjugate Gradient Project
*
*
* This class performs the parsing of a standard configuration file.
*
*/
#include "ConfigFileParser.hpp"
ConfigFileParser::ConfigFileParser() {
defaultKeys.push_back("type_input");
defaultKeys.push_back("N");
defaultKeys.push_back("tol");
defaultKeys.push_back("max_iter");
defaultKeys.push_back("type_output");
defaultKeys.push_back("outputFile");
defaultKeys.push_back("number_outputs");
}
ConfigFileParser::~ConfigFileParser(){}
std::map<std::string,std::string> ConfigFileParser::getData(){
return data;
}
void ConfigFileParser::setData(std::map<std::string,std::string> pData)
{
data=pData;
}
std::string ConfigFileParser::getFName(){
return fName;
}
void ConfigFileParser::parseFile(std::string pFname){
fName = pFname;
std::cout<<"Parsing file: " << fName << std::endl;
std::ifstream file;
file.open(fName.c_str());
if (!file)
throw FileNotFoundException();
std::string line;
while (std::getline(file, line))
{
std::string temp = line;
if (temp.empty()) //Empty Line
continue;
if(temp.front() =='#') //Comment Line
continue;
std::istringstream str_line(temp);
std::string key;
if( std::getline(str_line, key, '=') )
{
std::string value;
if( std::getline(str_line, value) ){
if (!key.empty() && !value.empty()) { //Verify that the two values exist
data[key] = value;
//std::cout << "key: " << key << std::endl;
//std::cout << "value: " << value << std::endl;
}
else
throw FileParserException();
}
}
}
file.close();
}
void ConfigFileParser::verify(){
for(int i=0;i<defaultKeys.size();++i){
std::string defaultKey = defaultKeys[i];
valueExistsForKey(defaultKey);
}
}
bool ConfigFileParser::valueExistsForKey(std::string key){
auto iter = data.find(key);
if (iter == data.end())
throw FileParserException();
else
return true;
}
Event Timeline
Log In to Comment