- fix coverity issues

- clean code and typo in comments
This commit is contained in:
winckler 2015-06-26 12:17:54 +02:00 committed by Florian Uhlig
parent 4db91a52eb
commit b855f77060
2 changed files with 24 additions and 46 deletions

View File

@ -76,6 +76,21 @@ int FairProgOptions::AddToEnvironmentOptions(const po::options_description& optd
return 0; return 0;
} }
void FairProgOptions::UseConfigFile(const std::string& filename)
{
fUseConfigFile = true;
if (filename.empty())
{
fCmdline_options.add_options()
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
}
else
{
fConfigFile = filename;
}
}
/// ////////////////////////////////////////////////////////////////////////////////////////////////////// /// //////////////////////////////////////////////////////////////////////////////////////////////////////
/// Parser /// Parser
@ -235,7 +250,7 @@ std::string FairProgOptions::GetStringValue(const std::string& key)
} }
catch(std::exception& e) catch(std::exception& e)
{ {
MQLOG(ERROR) << "Problem in boost variable map for the key '" << key << "'"; MQLOG(ERROR) << "Exception thrown for the key '" << key << "'";
MQLOG(ERROR) << e.what(); MQLOG(ERROR) << e.what();
} }
@ -243,18 +258,6 @@ std::string FairProgOptions::GetStringValue(const std::string& key)
} }
/*
int FairProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregistered)
{
// //////////////////////////////////
// Method to overload.
ParseCmdLine(argc,argv,fGenericDesc,fvarmap,AllowUnregistered);
PrintOptions();
return 0;
}
*/
/// ////////////////////////////////////////////////////////////////////////////////////////////////////// /// //////////////////////////////////////////////////////////////////////////////////////////////////////
/// Print/notify options /// Print/notify options

View File

@ -74,39 +74,13 @@ public:
int AddToCfgFileOptions(const po::options_description& optdesc, bool visible = true); int AddToCfgFileOptions(const po::options_description& optdesc, bool visible = true);
int AddToEnvironmentOptions(const po::options_description& optdesc); int AddToEnvironmentOptions(const po::options_description& optdesc);
void EnableCfgFile(const std::string& filename = "") void UseConfigFile(const std::string& filename = "");
{
fUseConfigFile = true;
if (filename.empty())
{
fCmdline_options.add_options()
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
}
else
{
fConfigFile = filename;
}
}
void UseConfigFile(const std::string& filename = "") // get value corresponding to the key
{
fUseConfigFile = true;
if (filename.empty())
{
fCmdline_options.add_options()
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
}
else
{
fConfigFile = filename;
}
}
// set value corresponding to the key
template<typename T> template<typename T>
T GetValue(const std::string& key) const T GetValue(const std::string& key) const
{ {
T val; T val = T();
try try
{ {
if (fvarmap.count(key)) if (fvarmap.count(key))
@ -122,7 +96,7 @@ public:
} }
catch(std::exception& e) catch(std::exception& e)
{ {
LOG(ERROR) << "Exception thorwn for the key '" << key << "'"; LOG(ERROR) << "Exception thrown for the key '" << key << "'";
LOG(ERROR) << e.what(); LOG(ERROR) << e.what();
this->PrintHelp(); this->PrintHelp();
} }
@ -132,6 +106,7 @@ public:
// convert value to string that corresponds to the key // convert value to string that corresponds to the key
std::string GetStringValue(const std::string& key); std::string GetStringValue(const std::string& key);
const po::variables_map& GetVarMap() const {return fvarmap;} const po::variables_map& GetVarMap() const {return fvarmap;}
// boost prog options parsers // boost prog options parsers
@ -172,7 +147,7 @@ protected:
std::string fConfigFile; std::string fConfigFile;
virtual int NotifySwitchOption(); virtual int NotifySwitchOption();
// UpadateVarMap() and replace() --> to modify the value of variable map after calling po::store // UpadateVarMap() and replace() --> helper functions to modify the value of variable map after calling po::store
template<typename T> template<typename T>
void UpadateVarMap(const std::string& key, const T& val) void UpadateVarMap(const std::string& key, const T& val)
{ {