WSL/SLF GitLab Repository

Commit 9cc19d6d authored by Thomas Egger's avatar Thomas Egger
Browse files

Added a void write(const string& filename) procedure to the Config class. The...

Added a void write(const string& filename) procedure to the Config class. The Config object can thus be written into an ini file.
parent c7cc84d0
......@@ -197,6 +197,55 @@ unsigned int Config::findKeys(std::vector<std::string>& vecResult, std::string k
return vecResult.size();
}
std::string Config::extract_section(std::string& key)
{
string::size_type pos = key.find("::");
if (pos != string::npos){
string sectionname = key.substr(0, pos);
key.erase(key.begin(), key.begin() + pos + 2); //delete section name
return sectionname;
}
return "GENERAL";
}
void Config::write(const std::string& filename)
{
std::ofstream fout;
fout.open(filename.c_str());
if (fout.fail())
throw FileAccessException(filename, AT);
try {
map<string,string>::const_iterator it;
string current_section = "";
unsigned int sectioncount = 0;
for (it=properties.begin(); it != properties.end(); it++){
string tmp = it->first;
string section = extract_section(tmp);
if (current_section != section){
current_section = section;
if (sectioncount != 0)
fout << endl;
sectioncount++;
fout << "[" << section << "]" << endl;
}
fout << tmp << " = " << it->second << endl;
}
} catch(...) {
if (fout.is_open()) //close fout if open
fout.close();
throw;
}
if (fout.is_open()) //close fout if open
fout.close();
}
} //end namespace
#ifdef _POPC_
......
......@@ -70,6 +70,12 @@ class Config {
*/
Config(const std::string& filename_in);
/**
* @brief Write the Config object to a file
* @param filename The filename including the path, e.g. "/tmp/test.ini"
*/
void write(const std::string& filename);
/**
* @brief Add the content of a file to the internal key/value map object
* @param[in] filename_in string representing the absolute filename of the key/value file
......@@ -262,10 +268,10 @@ class Config {
void parseCmdLine(const std::string& cmd_line);
void parseFile(const std::string& filename);
void parseLine(const unsigned int& linenr, std::string& line, std::string& section);
std::string extract_section(std::string& key);
std::map<std::string, std::string> properties; //Save key value pairs
std::string sourcename; //description of the data source for the key/value pair
}; //end class definition Config
class ConfigProxy {
......
......@@ -102,7 +102,17 @@ class MeteoData {
*/
void addParameter(const std::string& i_paramname);
/**
* @brief Check whether a certain parameter is a part of this MeteoData instance
* @param paramname A string parameter, representing a meteo parameter, e.g. "VSWR"
* @return A boolean indicating whether the parameter is a part of the object
*/
bool param_exists(const std::string& parname) const;
/**
* @brief Resets all the meteo parameters to IOUtils::nodata
* NOTE: member vars date and resampled are not affected
*/
void reset();
bool isResampled();
......@@ -115,6 +125,7 @@ class MeteoData {
double& param(const std::string& parname);
const double& param(const std::string& parname) const;
const std::string& getNameForParameter(const unsigned int& parindex) const;
//unsigned int getParameterIndex(const std::string& parname) const;
friend std::ostream& operator<<(std::ostream& os, const MeteoData& data);
......@@ -144,6 +155,7 @@ class MeteoData {
static bool initStaticData();///<initialize the static map meteoparamname
unsigned int nrOfAllParameters;
std::map<std::string, double> extraparameters; ///<All non-standard meteo parameters will end up in this map
std::map<std::string, double*> mapParameterByName; ///<Associate name and meteo parameter
std::map<unsigned int, double*> meteoparam; ///<Associate an unsigned int with every meteo parameter
......
......@@ -85,8 +85,6 @@ void MeteoFilter::filterData(const std::vector<MeteoData>& vecM, const std::vect
vecWindowM, vecWindowS);
}
}
}
unsigned int MeteoFilter::getFiltersForParameter(const std::string& parname, std::vector<std::string>& vecFilters)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment