No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

64 líneas
2.0 KiB

  1. #pragma once
  2. #include <string>
  3. #include <cppargs/misc/context.h>
  4. namespace cppargs
  5. {
  6. /**
  7. * @brief Class to store all meta data for a option.
  8. */
  9. struct option_meta
  10. {
  11. char short_name { '\0' }; //!< short option of the option (without the prependding -)
  12. std::string long_name { "" }; //!< long name of the option (without the prepending --)
  13. std::string description { "" }; //!< description for this option
  14. std::string arguments { "" }; //!< arguments to pass to this option
  15. std::string default_value { "" }; //!< default value for this option
  16. bool mandatory { false }; //!< TRUE if this option is optional, FALSE otherwise
  17. inline option_meta& set_short_name (char value);
  18. inline option_meta& set_long_name (const std::string& value);
  19. inline option_meta& set_description (const std::string& value);
  20. inline option_meta& set_arguments (const std::string& value);
  21. inline option_meta& set_default_value (const std::string& value);
  22. inline option_meta& set_mandatory (bool value = true);
  23. template<typename T_value>
  24. static option_meta prepare_arguments(const option_meta& meta);
  25. };
  26. /**
  27. * @brief Option to parse from command line arguments
  28. */
  29. struct option
  30. {
  31. public:
  32. const option_meta meta; //!< meta data of the option
  33. protected:
  34. /**
  35. * @brief Constructor.
  36. *
  37. * @param[in] p_long_name Long name of the option.
  38. * @param[in] p_short_name Short name of the option.
  39. */
  40. inline option(const option_meta& meta);
  41. public:
  42. /**
  43. * @brief Destructor.
  44. */
  45. virtual ~option() = default;
  46. /**
  47. * @brief Parse the option using the current context.
  48. *
  49. * @param[in|out] c Context to use for parsing.
  50. */
  51. virtual void parse(context& c) const = 0;
  52. };
  53. }