Go to the documentation of this file.
24 #ifndef GOBY_MIDDLEWARE_APPLICATION_CONFIGURATOR_H
25 #define GOBY_MIDDLEWARE_APPLICATION_CONFIGURATOR_H
42 const Config&
cfg()
const {
return cfg_; }
56 std::cerr <<
"Invalid configuration: " <<
e.what() << std::endl;
60 virtual std::string
str()
const = 0;
95 virtual std::string str()
const override {
return this->
cfg().DebugString(); }
99 if (tool_has_help_action())
101 std::cerr <<
"Invalid command: " <<
e.what() << std::endl;
105 std::cerr <<
"Invalid configuration: use --help and/or --example_config for more help: "
106 <<
e.what() << std::endl;
110 protobuf::AppConfig& mutable_app_configuration()
override
115 void merge_app_base_cfg(protobuf::AppConfig* base_cfg,
116 const boost::program_options::variables_map& var_map);
118 bool tool_has_help_action()
const
120 return Config::descriptor()
129 template <
typename Config>
135 Config& cfg = this->mutable_cfg();
137 boost::program_options::variables_map var_map;
140 std::string application_name;
141 std::string binary_name;
144 bool check_required_cfg =
false;
145 boost::program_options::options_description od{
"All options"};
147 argc, argv, &cfg, &application_name, &binary_name, &od, &var_map, check_required_cfg);
150 for (
int a = read_argc; a < argc; ++a)
151 cfg.mutable_app()->mutable_tool_cfg()->add_extra_cli_param(argv[a]);
153 cfg.mutable_app()->set_name(application_name);
154 cfg.mutable_app()->set_binary(binary_name);
157 merge_app_base_cfg(cfg.mutable_app(), var_map);
161 handle_config_error(
e);
164 if (!tool_has_help_action())
169 this->mutable_app_configuration() = *cfg.mutable_app();
172 template <
typename Config>
175 const boost::program_options::variables_map& var_map)
177 if (var_map.count(
"ncurses"))
182 if (var_map.count(
"verbose"))
184 switch (var_map[
"verbose"].as<std::size_t>())
207 if (var_map.count(
"glog_file_verbose"))
209 switch (var_map[
"glog_file_verbose"].as<std::size_t>())
233 if (var_map.count(
"glog_file_dir"))
236 var_map[
"glog_file_dir"].as<std::string>());
static const Verbosity DEBUG3
static const Verbosity VERBOSE
static int read_cfg(int argc, char *argv[], google::protobuf::Message *message, std::string *application_name, std::string *binary_name, boost::program_options::options_description *od_all, boost::program_options::variables_map *var_map, bool check_required_configuration=true)
Read the configuration into a Protobuf message using the command line parameters.
void set_file_dir(const ::std::string &value)
ProtobufConfigurator(int argc, char *argv[])
Constructs a ProtobufConfigurator. Typically passed as a parameter to goby::run.
The global namespace for the Goby project.
virtual void handle_config_error(middleware::ConfigException &e) const
Override to customize how ConfigException errors are handled.
void set_verbosity(::goby::util::protobuf::GLogConfig_Verbosity value)
::goby::util::protobuf::GLogConfig_FileLog * mutable_file_log()
virtual std::string str() const =0
Override to output the configuration object as a string.
indicates a problem with the runtime command line or .cfg file configuration (or –help was given)
::goby::util::protobuf::GLogConfig * mutable_glog_config()
Implementation of ConfiguratorInterface for Google Protocol buffers.
void set_tty_verbosity(::goby::util::protobuf::GLogConfig_Verbosity value)
static const Verbosity DEBUG2
void set_show_gui(bool value)
static const Verbosity DEBUG1
const Config & cfg() const
The configuration object produced from the command line parameters.
virtual const protobuf::AppConfig & app_configuration() const
Subset of the configuration used to configure the Application itself.
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
static void check_required_cfg(const google::protobuf::Message &message, const std::string &binary)
Checks that all required fields are set (either via the command line or the configuration file) in th...
virtual void validate() const
Override to validate the configuration.
const protobuf::AppConfig & app_configuration() const override
Subset of the configuration used to configure the Application itself.
virtual void validate() const override
Override to validate the configuration.
virtual protobuf::AppConfig & mutable_app_configuration()
Derived classes can modify the application configuration as needed in their constructor.
Config & mutable_cfg()
Derived classes can modify the configuration as needed in their constructor.
Defines the interface to a "configurator", a class that can read command line parameters (argc,...