param.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "clish/pargv.h"
  18. /**
  19. * The means by which the param is interpreted.
  20. */
  21. typedef enum {
  22. /**
  23. * A common parameter.
  24. */
  25. CLISH_PARAM_COMMON,
  26. /**
  27. * A swich parameter.
  28. * Choose the only one of nested parameters.
  29. */
  30. CLISH_PARAM_SWITCH,
  31. /**
  32. * A subcomand.
  33. * Identified by it's name.
  34. */
  35. CLISH_PARAM_SUBCOMMAND
  36. } clish_param_mode_e;
  37. /*=====================================
  38. * PARAM INTERFACE
  39. *===================================== */
  40. /*-----------------
  41. * meta functions
  42. *----------------- */
  43. clish_param_t *clish_param_new(const char *name,
  44. const char *text, clish_ptype_t * ptype);
  45. /*-----------------
  46. * methods
  47. *----------------- */
  48. void clish_param_delete(clish_param_t * instance);
  49. void clish_param_help(const clish_param_t * instance, size_t offset);
  50. void clish_param_help_arrow(const clish_param_t * instance, size_t offset);
  51. char *clish_param_validate(const clish_param_t * instance, const char *text);
  52. void clish_param_dump(const clish_param_t * instance);
  53. void clish_param_insert_param(clish_param_t * instance, clish_param_t * param);
  54. /*-----------------
  55. * attributes
  56. *----------------- */
  57. const char *clish_param__get_name(const clish_param_t * instance);
  58. const char *clish_param__get_text(const clish_param_t * instance);
  59. const char *clish_param__get_range(const clish_param_t * instance);
  60. const char *clish_param__get_default(const clish_param_t * instance);
  61. clish_ptype_t *clish_param__get_ptype(const clish_param_t * instance);
  62. void clish_param__set_default(clish_param_t * instance, const char *defval);
  63. void clish_param__set_mode(clish_param_t * instance, clish_param_mode_e mode);
  64. clish_param_mode_e clish_param__get_mode(const clish_param_t * instance);
  65. clish_param_t *clish_param__get_param(const clish_param_t * instance,
  66. unsigned index);
  67. const unsigned clish_param__get_param_count(const clish_param_t * instance);
  68. clish_paramv_t *clish_param__get_paramv(clish_param_t * instance);
  69. void clish_param__set_optional(clish_param_t * instance, bool_t optional);
  70. bool_t clish_param__get_optional(const clish_param_t * instance);
  71. void clish_param__set_value(clish_param_t * instance, const char * value);
  72. char *clish_param__get_value(const clish_param_t * instance);
  73. void clish_param__set_hidden(clish_param_t * instance, bool_t hidden);
  74. bool_t clish_param__get_hidden(const clish_param_t * instance);
  75. void clish_param__set_test(clish_param_t * instance, const char *test);
  76. char *clish_param__get_test(const clish_param_t * instance,
  77. const char * viewid, const clish_command_t * cmd,
  78. clish_pargv_t * pargv);
  79. /* paramv methods */
  80. clish_paramv_t *clish_paramv_new(void);
  81. void clish_paramv_delete(clish_paramv_t * instance);
  82. void clish_paramv_insert(clish_paramv_t * instance, clish_param_t * param);
  83. clish_param_t *clish_paramv__get_param(const clish_paramv_t * instance,
  84. unsigned index);
  85. const unsigned clish_paramv__get_count(const clish_paramv_t * instance);
  86. #endif /* _clish_param_h */
  87. /** @} clish_param */