param.h 4.2 KB

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