Browse Source

some cleanups

module selector options have a meaningful description
some code cleanup
tempestpy_adaptions
gereon 12 years ago
parent
commit
c93b325e19
  1. 18
      src/utility/settings.cpp
  2. 13
      src/utility/settings.h

18
src/utility/settings.cpp

@ -11,6 +11,8 @@
#include "log4cplus/loggingmacros.h"
extern log4cplus::Logger logger;
#include <boost/algorithm/string/join.hpp>
namespace mrmc {
namespace settings {
@ -50,12 +52,20 @@ Settings::Settings(const int argc, const char* argv[], const char* filename)
Settings::positional.add("trafile", 1);
Settings::positional.add("labfile", 1);
//! Check module triggers
//! Check module triggers, add corresponding options
std::map< std::string, std::list< std::string > > options;
for (auto it : Settings::modules)
{
std::pair< std::string, std::string > trigger = it.first;
options[it.first.first].push_back(it.first.second);
}
for (auto it : options)
{
std::stringstream str;
str << "select " << it.first << " module (" << boost::algorithm::join(it.second, ", ") << ")";
Settings::desc->add_options()
(trigger.first.c_str(), bpo::value<std::string>(), trigger.second.c_str())
(it.first.c_str(), bpo::value<std::string>(), str.str().c_str())
;
}
@ -205,8 +215,6 @@ std::ostream& help(std::ostream& os)
os << *(mrmc::settings::Settings::desc) << std::endl;
for (auto it : Settings::modules)
{
std::pair< std::string, std::string > trigger = it.first;
os << "If --" << trigger.first << " = " << trigger.second << ":" << std::endl;
os << *(it.second) << std::endl;
}
return os;

13
src/utility/settings.h

@ -9,6 +9,7 @@
#define SETTINGS_H_
#include <iostream>
#include <sstream>
#include <list>
#include <utility>
#include <memory>
@ -101,14 +102,20 @@ namespace settings {
*
* This function implicitly defines the following interface for any SettingsModule:
* @code
* static std::pair< std::string, std::string> getSettings(boost::program_options::options_description*);
* static std::string getModuleName();
* static std::pair< std::string, std::string > getOptionTrigger();
* static void putOptions(boost::program_options::options_description*);
* @endcode
*/
template <typename T>
static void registerModule()
{
bpo::options_description* desc = new bpo::options_description();
Settings::modules[ T::getSettings(desc) ] = desc;
std::pair< std::string, std::string > trigger = T::getOptionTrigger();
std::stringstream str;
str << T::getModuleName() << " (" << trigger.first << " = " << trigger.second << ")";
bpo::options_description* desc = new bpo::options_description(str.str());
T::putOptions(desc);
Settings::modules[ trigger ] = desc;
}
friend std::ostream& help(std::ostream& os);

Loading…
Cancel
Save