21 #ifndef mia_core_cmdlineparser_hh 22 #define mia_core_cmdlineparser_hh 103 template <
typename T>
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;
154 virtual const std::string do_get_value_as_string()
const;
204 void add(
const std::string& group,
PCmdOption opt);
227 EHelpRequested parse(
size_t argc,
char *args[],
const std::string& additional_type,
229 __attribute__((warn_unused_result));
242 EHelpRequested parse(
size_t argc, const
char *args[], const
std::
string& additional_type,
244 __attribute__((warn_unused_result));
251 EHelpRequested parse(
size_t argc,
char *args[]) __attribute__((warn_unused_result));
258 EHelpRequested parse(
size_t argc, const
char *args[]) __attribute__((warn_unused_result));
261 const
std::vector<
std::
string>& get_remaining() const;
272 void set_group(const
std::
string& group);
278 void set_logstream(
std::ostream& os);
283 void set_stdout_is_result();
285 EHelpRequested do_parse(
size_t argc, const
char *args[],
bool has_additional,
287 __attribute__((warn_unused_result));
288 int handle_shortargs(const
char *arg,
size_t argc, const
char *args[]);
289 struct CCmdOptionListData *m_impl;
307 template <typename T>
308 struct __dispatch_opt {
312 static void init(T& ){
320 static bool apply(
const char *svalue, T& value) {
321 std::istringstream sval(svalue);
324 while (isspace(sval.peek())) {
331 static size_t size(
const T ) {
340 static void apply(std::ostream& os,
const T& value,
bool ) {
341 os <<
"=" << value <<
" ";
349 static const std::string get_as_string(
const T& value) {
350 std::ostringstream os;
361 template <
typename T>
362 struct __dispatch_opt<
std::vector<T> > {
363 static void init(std::vector<T>& ){
366 static bool apply(
const char *svalue, std::vector<T>& value) {
367 std::string h(svalue);
369 for(std::string::iterator hb = h.begin(); hb != h.end(); ++hb)
376 if (!value.empty()) {
377 if (n > value.size()) {
378 throw create_exception<std::invalid_argument>(
"Expect only ", value.size(),
379 " coma separated values, but '",
380 svalue,
"' provides ", n);
386 std::istringstream sval(h);
387 auto i = value.begin();
388 while (!sval.eof()) {
395 static size_t size(
const std::vector<T>& ) {
399 static void apply(std::ostream& os,
const std::vector<T>& value,
bool required) {
405 for (
auto i = value.begin(); i != value.end(); ++i) {
406 if (i != value.begin())
414 static const std::string get_as_string(
const std::vector<T>& value) {
415 std::ostringstream os;
416 for (
auto i = value.begin(); i != value.end(); ++i) {
417 if (i != value.begin())
434 struct __dispatch_opt<bool> {
435 static void init(
bool& value) {
438 static bool apply(
const char *,
bool& value) {
442 static size_t size(
bool ) {
445 static void apply(std::ostream& ,
bool ,
bool ) {
447 static const std::string get_as_string(
const bool& value) {
448 return value ?
"true" :
"false";
462 struct __dispatch_opt<
std::string> {
463 static void init(std::string& ) {
465 static bool apply(
const char *svalue, std::string& value) {
466 value = std::string(svalue);
469 static size_t size(std::string ) {
472 static void apply(std::ostream& os,
const std::string& value,
bool required) {
481 static const std::string get_as_string(
const std::string& value) {
491 template <
typename T>
493 const char *
long_help,
const char *short_help,
495 CCmdOption(short_opt, long_opt, long_help, short_help, flags),
498 __dispatch_opt<T>::init(m_value);
501 template <
typename T>
504 return __dispatch_opt<T>::apply(svalue, m_value);
507 template <
typename T>
510 return __dispatch_opt<T>::size(m_value);
513 template <
typename T>
516 __dispatch_opt<T>::apply( os, m_value,
is_required());
519 template <
typename T>
527 template <
typename T>
530 return __dispatch_opt<T>::get_as_string(m_value);
549 template <
typename T>
572 template <
typename T>
574 const char *long_opt,
char short_opt,
599 template <
typename T>
621 PCmdOption make_opt(
bool& value,
const char *long_opt,
char short_opt,
const char *help,
639 template <
typename T>
641 const char *long_opt,
char short_opt,
const char *help)
666 const char *short_help,
685 PCmdOption make_opt(std::string& value,
const char *long_opt,
char short_opt,
const char *long_help,
705 template <
typename T>
707 const char *long_opt,
char short_opt,
736 template <
typename T>
737 PCmdOption make_opt(
typename std::shared_ptr<T>& value,
const char *default_value,
const char *long_opt,
738 char short_opt,
const char *help,
742 typedef typename FactoryTrait<T>::type F;
765 template <
typename T>
766 PCmdOption make_opt(
typename std::unique_ptr<T>& value,
const char *default_value,
const char *long_opt,
770 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
void set_attribute(const char *name, const std::string &value)
Set an attribute of the node.
A parameter that get's initialized by a factory to a shared or unique pointer.
bool has_flag(CCmdOptionFlags test_flags) const
A parameter that can only assume values out of a limited set.
The base class for all command line options.
class EXPORT_CORE CMeans private
#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.
Templated version based on CCmdOptionValue for values that can be converted to and from strings by st...
Generic type of a complex paramter.
EParameterBounds
Scalar parameter with an expected value range.
command line option that handles a parameter
This class implements a facade for the xml Element.
const mia::SProgramDescription description
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
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