21 #ifndef mia_core_cmdlineparser_hh
22 #define mia_core_cmdlineparser_hh
103 template <
typename T>
120 virtual void do_get_long_help_xml(std::ostream& os, xmlpp::Element& parent,
HandlerHelpMap& handler_map)
const;
121 virtual bool do_set_value(
const char *str_value);
122 virtual size_t do_get_needed_args()
const;
123 virtual void do_write_value(std::ostream& os)
const;
124 virtual const std::string do_get_value_as_string()
const;
147 const char *
long_help,
const char *short_help,
150 virtual bool do_set_value(
const char *str_value);
151 virtual size_t do_get_needed_args()
const;
152 virtual void do_write_value(std::ostream& os)
const;
153 virtual void do_get_long_help(std::ostream& os)
const;
154 virtual const std::string do_get_value_as_string()
const;
182 virtual void print(std::ostream& os)
const = 0;
196 void print(std::ostream& os)
const;
199 std::unique_ptr<Callback> m_callback;
200 virtual bool do_set_value(
const char *str_value);
201 virtual size_t do_get_needed_args()
const;
202 virtual void do_write_value(std::ostream& os)
const;
204 virtual void do_get_long_help_xml(std::ostream& os, xmlpp::Element& parent,
214 template <
typename PluginHandler>
216 void print(std::ostream& os)
const{
217 PluginHandler::instance().print_help(os);
265 void add(
const std::string& group,
PCmdOption opt);
277 EHelpRequested parse(
size_t argc,
char *args[],
const std::string& additional_type,
279 __attribute__((warn_unused_result));
292 EHelpRequested parse(
size_t argc, const
char *args[], const
std::
string& additional_type,
294 __attribute__((warn_unused_result));
301 EHelpRequested parse(
size_t argc,
char *args[]) __attribute__((warn_unused_result));
308 EHelpRequested parse(
size_t argc, const
char *args[]) __attribute__((warn_unused_result));
311 const
std::vector<
std::
string>& get_remaining() const;
322 void set_group(const
std::
string& group);
328 void set_logstream(
std::ostream& os);
330 EHelpRequested do_parse(
size_t argc, const
char *args[],
bool has_additional,
332 __attribute__((warn_unused_result));
333 int handle_shortargs(const
char *arg,
size_t argc, const
char *args[]);
334 struct CCmdOptionListData *m_impl;
352 template <typename T>
353 struct __dispatch_opt {
357 static void init(T& ){
365 static bool apply(
const char *svalue, T& value) {
366 std::istringstream sval(svalue);
369 while (isspace(sval.peek())) {
376 static size_t size(
const T ) {
385 static void apply(std::ostream& os,
const T& value,
bool ) {
386 os <<
"=" << value <<
" ";
394 static const std::string get_as_string(
const T& value) {
395 std::ostringstream os;
406 template <
typename T>
407 struct __dispatch_opt<
std::vector<T> > {
408 static void init(std::vector<T>& ){
411 static bool apply(
const char *svalue, std::vector<T>& value) {
412 std::string h(svalue);
414 for(std::string::iterator hb = h.begin(); hb != h.end(); ++hb)
421 if (!value.empty()) {
422 if (n > value.size()) {
423 throw create_exception<std::invalid_argument>(
"Expect only ", value.size(),
424 " coma separated values, but '",
425 svalue,
"' provides ", n);
431 std::istringstream sval(h);
432 auto i = value.begin();
433 while (!sval.eof()) {
440 static size_t size(
const std::vector<T>& ) {
444 static void apply(std::ostream& os,
const std::vector<T>& value,
bool required) {
450 for (
auto i = value.begin(); i != value.end(); ++i) {
451 if (i != value.begin())
459 static const std::string get_as_string(
const std::vector<T>& value) {
460 std::ostringstream os;
461 for (
auto i = value.begin(); i != value.end(); ++i) {
462 if (i != value.begin())
479 struct __dispatch_opt<bool> {
480 static void init(
bool& value) {
483 static bool apply(
const char *,
bool& value) {
487 static size_t size(
bool ) {
490 static void apply(std::ostream& ,
bool ,
bool ) {
492 static const std::string get_as_string(
const bool& value) {
493 return value ?
"true" :
"false";
507 struct __dispatch_opt<
std::string> {
508 static void init(std::string& ) {
510 static bool apply(
const char *svalue, std::string& value) {
511 value = std::string(svalue);
514 static size_t size(std::string ) {
517 static void apply(std::ostream& os,
const std::string& value,
bool required) {
526 static const std::string get_as_string(
const std::string& value) {
536 template <
typename T>
538 const char *long_help,
const char *short_help,
540 CCmdOption(short_opt, long_opt, long_help, short_help, flags),
543 __dispatch_opt<T>::init(m_value);
546 template <
typename T>
549 return __dispatch_opt<T>::apply(svalue, m_value);
552 template <
typename T>
555 return __dispatch_opt<T>::size(m_value);
558 template <
typename T>
561 __dispatch_opt<T>::apply( os, m_value, is_required());
564 template <
typename T>
568 do_get_long_help(os);
569 parent.set_attribute(
"type", __type_descr<T>::value);
572 template <
typename T>
575 return __dispatch_opt<T>::get_as_string(m_value);
594 template <
typename T>
619 template <
typename T,
typename Tmin,
typename Tmax>
645 template <
typename T>
666 PCmdOption make_opt(
bool& value,
const char *long_opt,
char short_opt,
const char *help);
683 template <
typename T>
685 const char *long_opt,
char short_opt,
const char *help)
709 char short_opt,
const char *long_help,
710 const char *short_help,
729 PCmdOption make_opt(std::string& value,
const char *long_opt,
char short_opt,
const char *long_help,
749 template <
typename T>
751 const char *long_opt,
char short_opt,
780 template <
typename T>
781 PCmdOption make_opt(
typename std::shared_ptr<T>& value,
const char *default_value,
const char *long_opt,
782 char short_opt,
const char *help,
786 typedef typename FactoryTrait<T>::type F;
809 template <
typename T>
810 PCmdOption make_opt(
typename std::unique_ptr<T>& value,
const char *default_value,
const char *long_opt,
814 typedef typename FactoryTrait<T>::type F;
std::pair< std::string, CHistoryRecord > CHistoryEntry
EXPORT_CORE const char * g_help_optiongroup
the string defining the name of the help options
std::map< std::string, std::string > CHistoryRecord
PCmdOption make_help_opt(const char *long_opt, char short_opt, const char *long_help, CHelpOption::Callback *cb)
Create a command line help option.
A parameter that get's initialized by a factory to a shared or unique pointer.
A parameter that can only assume values out of a limited set.
The base class for all command line options.
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
std::map< std::string, const CPluginHandlerBase * > HandlerHelpMap
A map that is used to collect the plug-in handlers used in a program.
Command line option that translates a string to a set of flags.
TCmdOption(T &val, char short_opt, const char *long_opt, const char *long_help, const char *short_help, CCmdOptionFlags flags=CCmdOptionFlags::none)
std::map< EProgramDescriptionEntry, const char * > SProgramDescription
the map that holds a basic program description
The base class for all plugin handlers.
A command line option that will appear in the help group and exits the program after printing the hel...
Templated version based on CCmdOptionValue for values that can be converted to and from strings by st...
Generic type of a complex paramter.
CCmdFlagOption(int &val, const CFlagString &map, char short_opt, const char *long_opt, const char *long_help, const char *short_help, CCmdOptionFlags flags=CCmdOptionFlags::none)
Interface for the callback to print the help assositated with the given option.
command line option that handles a parameter
Help callback to print the help for the given plug-in.
const mia::SProgramDescription description
bool has_flag(CCmdOptionFlags flags, CCmdOptionFlags test)
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
Scalar parameter with an expected value range.
EProgramDescriptionEntry
program description entry identifiers
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
virtual void do_get_long_help(std::ostream &os) const
const char * long_help() const
PCmdOption make_opt(T &value, const char *long_opt, char short_opt, const char *help, CCmdOptionFlags flags=CCmdOptionFlags::none)
Create a standard option that sets a value of the give type.
The class to hold the list of options.
const std::map< EProgramDescriptionEntry, const char * > g_DescriptionEntryNames
A mapper from emums to string values. - usefull for names flags.
#define NS_MIA_END
conveniance define to end the mia namespace