23 #ifndef CONFIGURATIONREADER20100929H 24 #define CONFIGURATIONREADER20100929H 31 #include <boost/cstdint.hpp> 32 #include <boost/foreach.hpp> 33 #include <boost/program_options.hpp> 35 #include <google/protobuf/descriptor.h> 36 #include <google/protobuf/descriptor.pb.h> 37 #include <google/protobuf/io/zero_copy_stream.h> 38 #include <google/protobuf/io/zero_copy_stream_impl.h> 39 #include <google/protobuf/message.h> 40 #include <google/protobuf/text_format.h> 42 #include "goby/common/exception.h" 43 #include "goby/util/as.h" 58 void set_error(
bool b) { error_ = b; }
59 bool error() {
return error_; }
69 std::string* application_name,
70 boost::program_options::options_description* od_all,
71 boost::program_options::variables_map* var_map);
73 static void get_protobuf_program_options(boost::program_options::options_description& po_desc,
74 const google::protobuf::Descriptor* desc);
76 static void set_protobuf_program_option(
const boost::program_options::variables_map& vm,
78 const std::string& full_name,
79 const boost::program_options::variable_value& value);
82 std::ostream* human_desc_ss,
const std::string& indent =
"");
87 MAX_CHAR_PER_LINE = 66
94 static void build_description(
const google::protobuf::Descriptor* desc,
95 std::ostream& human_desc,
const std::string& indent =
"",
96 bool use_color =
true);
98 static void build_description_field(
const google::protobuf::FieldDescriptor* desc,
99 std::ostream& human_desc,
const std::string& indent,
102 static void wrap_description(std::string* description,
int num_blanks);
104 static std::string label(
const google::protobuf::FieldDescriptor* field_desc);
106 static std::string word_wrap(std::string s,
unsigned width,
const std::string& delim);
108 template <
typename T>
109 static void set_single_option(boost::program_options::options_description& po_desc,
110 const google::protobuf::FieldDescriptor* field_desc,
111 const T& default_value,
const std::string& name,
112 const std::string& description)
114 if (!field_desc->is_repeated())
116 if (field_desc->has_default_value())
118 po_desc.add_options()(
119 name.c_str(), boost::program_options::value<T>()->default_value(default_value),
120 description.c_str());
124 po_desc.add_options()(name.c_str(), boost::program_options::value<T>(),
125 description.c_str());
130 if (field_desc->has_default_value())
132 po_desc.add_options()(
134 boost::program_options::value<std::vector<T> >()->default_value(
135 std::vector<T>(1, default_value),
136 goby::util::as<std::string>(default_value)),
137 description.c_str());
141 po_desc.add_options()(name.c_str(),
142 boost::program_options::value<std::vector<T> >(),
143 description.c_str());
indicates a problem with the runtime command line or .cfg file configuration (or –help was given) ...
The global namespace for the Goby project.
simple exception class for goby applications