Browse Source

fixing some more documentation, adding dummy implementation

tempestpy_adaptions
gereon 12 years ago
parent
commit
f6c88b3801
  1. 24
      src/utility/settings.cpp
  2. 19
      src/utility/settings.h

24
src/utility/settings.cpp

@ -45,14 +45,14 @@ Settings::Settings(const int argc, const char* argv[], const char* filename)
Settings::binaryName = std::string(argv[0]);
try
{
//! Initially fill description objects and call register callbacks
// Initially fill description objects
this->initDescriptions();
//! Take care of positional arguments
// Take care of positional arguments
Settings::positional.add("trafile", 1);
Settings::positional.add("labfile", 1);
//! Check module triggers, add corresponding options
// Check module triggers, add corresponding options
std::map< std::string, std::list< std::string > > options;
for (auto it : Settings::modules)
@ -69,10 +69,10 @@ Settings::Settings(const int argc, const char* argv[], const char* filename)
;
}
//! Perform first parse run
// Perform first parse run
this->firstRun(argc, argv, filename);
//! Check module triggers
// Check module triggers
for (auto it : Settings::modules)
{
std::pair< std::string, std::string > trigger = it.first;
@ -87,16 +87,16 @@ Settings::Settings(const int argc, const char* argv[], const char* filename)
}
//! Stop if help is set
// Stop if help is set
if ((this->vm.count("help") > 0) || (this->vm.count("help-config") > 0))
{
return;
}
//! Perform second run and call checker callbacks
// Perform second run
this->secondRun(argc, argv, filename);
//! Finalize parsed options, check for specified requirements
// Finalize parsed options, check for specified requirements
bpo::notify(this->vm);
LOG4CPLUS_DEBUG(logger, "Finished loading config.");
}
@ -154,13 +154,11 @@ void Settings::initDescriptions()
* Perform a sloppy parsing run: parse command line and config file (if
* given), but allow for unregistered options, do not check requirements
* from options_description objects, do not check positional arguments.
*
* Call all intermediate callbacks afterwards.
*/
void Settings::firstRun(const int argc, const char* argv[], const char* filename)
{
LOG4CPLUS_DEBUG(logger, "Performing first run.");
//! parse command line
// parse command line
bpo::store(bpo::command_line_parser(argc, argv).options(*(Settings::desc)).allow_unregistered().run(), this->vm);
/*
@ -180,13 +178,11 @@ void Settings::firstRun(const int argc, const char* argv[], const char* filename
* Perform the second parser run: parse command line and config file (if
* given) and check for unregistered options, requirements from
* options_description objects and positional arguments.
*
* Call all checker callbacks afterwards.
*/
void Settings::secondRun(const int argc, const char* argv[], const char* filename)
{
LOG4CPLUS_DEBUG(logger, "Performing second run.");
//! Parse command line
// Parse command line
bpo::store(bpo::command_line_parser(argc, argv).options(*(Settings::desc)).positional(this->positional).run(), this->vm);
/*
* load config file if specified

19
src/utility/settings.h

@ -87,19 +87,30 @@ namespace settings {
*
* Furthermore, it will generate the option specified by the
* trigger.
*
* The functions could look like this:
* @code
* static std::string getModuleName() { return "Backend A"; }
* static std::pair<std::string, std::string> getOptionTrigger() {
* return std::pair<std::string, std::string>("backend", "a");
* }
* static void putOptions(boost::program_options::options_description* desc) {
* desc->add_options()("foo", "bar");
* }
* @endcode
*/
template <typename T>
static void registerModule()
{
//! get trigger
// get trigger
std::pair< std::string, std::string > trigger = T::getOptionTrigger();
//! build description name
// build description name
std::stringstream str;
str << T::getModuleName() << " (" << trigger.first << " = " << trigger.second << ")";
bpo::options_description* desc = new bpo::options_description(str.str());
//! but options
// but options
T::putOptions(desc);
//! store
// store
Settings::modules[ trigger ] = desc;
}

Loading…
Cancel
Save