param.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * param.h
  3. */
  4. /**
  5. \ingroup clish
  6. \defgroup clish_param param
  7. @{
  8. \brief This class represents an instance of a parameter type.
  9. Parameter instances are assocated with a command line and used to validate the
  10. the arguments which a user is inputing for a command.
  11. */
  12. #ifndef _clish_param_h
  13. #define _clish_param_h
  14. typedef struct clish_paramv_s clish_paramv_t;
  15. typedef struct clish_param_s clish_param_t;
  16. #include "clish/ptype.h"
  17. /**
  18. * The means by which the param is interpreted.
  19. */
  20. typedef enum {
  21. /**
  22. * A common parameter.
  23. */
  24. CLISH_PARAM_COMMON,
  25. /**
  26. * A swich parameter.
  27. * Choose the only one of nested parameters.
  28. */
  29. CLISH_PARAM_SWITCH,
  30. /**
  31. * A subcomand.
  32. * Identified by it's name.
  33. */
  34. CLISH_PARAM_SUBCOMMAND
  35. } clish_param_mode_e;
  36. /*=====================================
  37. * PARAM INTERFACE
  38. *===================================== */
  39. /*-----------------
  40. * meta functions
  41. *----------------- */
  42. clish_param_t *clish_param_new(const char *name,
  43. const char *text, clish_ptype_t * ptype);
  44. /*-----------------
  45. * methods
  46. *----------------- */
  47. void clish_param_delete(clish_param_t * instance);
  48. void clish_param_help(const clish_param_t * instance, size_t offset);
  49. void clish_param_help_arrow(const clish_param_t * instance, size_t offset);
  50. char *clish_param_validate(const clish_param_t * instance, const char *text);
  51. void clish_param_dump(const clish_param_t * instance);
  52. void clish_param_insert_param(clish_param_t * instance, clish_param_t * param);
  53. /*-----------------
  54. * attributes
  55. *----------------- */
  56. const char *clish_param__get_name(const clish_param_t * instance);
  57. const char *clish_param__get_text(const clish_param_t * instance);
  58. const char *clish_param__get_range(const clish_param_t * instance);
  59. const char *clish_param__get_default(const clish_param_t * instance);
  60. clish_ptype_t *clish_param__get_ptype(const clish_param_t * instance);
  61. void clish_param__set_default(clish_param_t * instance, const char *defval);
  62. void clish_param__set_mode(clish_param_t * instance, clish_param_mode_e mode);
  63. clish_param_mode_e clish_param__get_mode(const clish_param_t * instance);
  64. clish_param_t *clish_param__get_param(const clish_param_t * instance,
  65. unsigned index);
  66. const unsigned clish_param__get_param_count(const clish_param_t * instance);
  67. clish_paramv_t *clish_param__get_paramv(clish_param_t * instance);
  68. void clish_param__set_optional(clish_param_t * instance, bool_t optional);
  69. bool_t clish_param__get_optional(const clish_param_t * instance);
  70. /* paramv methods */
  71. clish_paramv_t *clish_paramv_new(void);
  72. void clish_paramv_delete(clish_paramv_t * instance);
  73. void clish_paramv_insert(clish_paramv_t * instance, clish_param_t * param);
  74. clish_param_t *clish_paramv__get_param(const clish_paramv_t * instance,
  75. unsigned index);
  76. const unsigned clish_paramv__get_count(const clish_paramv_t * instance);
  77. #endif /* _clish_param_h */
  78. /** @} clish_param */