mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51:45 +00:00
FairMQProgOptions: initialize defaults in the constructor, not in ParseAll
This commit is contained in:
committed by
Mohammad Al-Turany
parent
778c8e16bb
commit
efdec0f6ba
@@ -30,6 +30,8 @@ FairMQProgOptions::FairMQProgOptions()
|
||||
, fChannelInfo()
|
||||
, fMQKeyMap()
|
||||
{
|
||||
InitOptionDescription();
|
||||
ParseDefaults(fCmdLineOptions);
|
||||
}
|
||||
|
||||
FairMQProgOptions::~FairMQProgOptions()
|
||||
@@ -50,8 +52,6 @@ int FairMQProgOptions::ParseAll(const vector<string>& cmdLineArgs, bool allowUnr
|
||||
|
||||
int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool allowUnregistered)
|
||||
{
|
||||
InitOptionDescription();
|
||||
|
||||
if (FairProgOptions::ParseCmdLine(argc, argv, fCmdLineOptions, fVarMap, allowUnregistered))
|
||||
{
|
||||
// ParseCmdLine returns 0 if no immediate switches found.
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -87,6 +88,21 @@ int FairProgOptions::ParseCmdLine(const int argc, char const* const* argv, const
|
||||
return ParseCmdLine(argc, argv, desc, fVarMap, allowUnregistered);
|
||||
}
|
||||
|
||||
void FairProgOptions::ParseDefaults(const po::options_description& desc)
|
||||
{
|
||||
vector<string> emptyArgs;
|
||||
emptyArgs.push_back("dummy");
|
||||
|
||||
vector<const char*> argv(emptyArgs.size());
|
||||
|
||||
transform(emptyArgs.begin(), emptyArgs.end(), argv.begin(), [](const string& str)
|
||||
{
|
||||
return str.c_str();
|
||||
});
|
||||
|
||||
po::store(po::parse_command_line(argv.size(), const_cast<char**>(argv.data()), desc), fVarMap);
|
||||
}
|
||||
|
||||
int FairProgOptions::PrintOptions()
|
||||
{
|
||||
// Method to overload.
|
||||
|
@@ -161,6 +161,7 @@ class FairProgOptions
|
||||
// boost prog options parsers
|
||||
int ParseCmdLine(const int argc, char const* const* argv, const po::options_description& desc, po::variables_map& varmap, bool allowUnregistered = false);
|
||||
int ParseCmdLine(const int argc, char const* const* argv, const po::options_description& desc, bool allowUnregistered = false);
|
||||
void ParseDefaults(const po::options_description& desc);
|
||||
|
||||
virtual int ParseAll(const int argc, char const* const* argv, bool allowUnregistered = false) = 0;// TODO change return type to bool and propagate to executable
|
||||
|
||||
|
Reference in New Issue
Block a user