ptype.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * ptype.h
  3. */
  4. /**
  5. \ingroup clish
  6. \defgroup clish_ptype ptype
  7. @{
  8. \brief This class represents a parameter type.
  9. Types are a syntatical template which parameters reference.
  10. */
  11. #ifndef _clish_ptype_h
  12. #define _clish_ptype_h
  13. typedef struct clish_ptype_s clish_ptype_t;
  14. #include "lub/types.h"
  15. #include "lub/bintree.h"
  16. #include "lub/argv.h"
  17. #include <stddef.h>
  18. /*=====================================
  19. * PTYPE INTERFACE
  20. *===================================== */
  21. /*-----------------
  22. * public types
  23. *----------------- */
  24. /**
  25. * The means by which the pattern is interpreted and
  26. * validated.
  27. */
  28. typedef enum {
  29. /**
  30. * [default] - A POSIX regular expression.
  31. */
  32. CLISH_PTYPE_REGEXP,
  33. /**
  34. * A numeric definition "min..max" signed and unsigned versions
  35. */
  36. CLISH_PTYPE_INTEGER,
  37. CLISH_PTYPE_UNSIGNEDINTEGER,
  38. /**
  39. * A list of possible values.
  40. * The syntax of the string is of the form:
  41. * "valueOne(ONE) valueTwo(TWO) valueThree(THREE)"
  42. * where the text before the parethesis defines the syntax
  43. * that the user must use, and the value within the parenthesis
  44. * is the result expanded as a parameter value.
  45. */
  46. CLISH_PTYPE_SELECT
  47. } clish_ptype_method_e;
  48. /**
  49. * This defines the pre processing which is to be
  50. * performed before a string is validated.
  51. */
  52. typedef enum {
  53. /**
  54. * [default] - do nothing
  55. */
  56. CLISH_PTYPE_NONE,
  57. /**
  58. * before validation convert to uppercase.
  59. */
  60. CLISH_PTYPE_TOUPPER,
  61. /**
  62. * before validation convert to lowercase.
  63. */
  64. CLISH_PTYPE_TOLOWER
  65. } clish_ptype_preprocess_e;
  66. /*-----------------
  67. * meta functions
  68. *----------------- */
  69. int clish_ptype_bt_compare(const void *clientnode, const void *clientkey);
  70. void clish_ptype_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
  71. size_t clish_ptype_bt_offset(void);
  72. const char *clish_ptype_method__get_name(clish_ptype_method_e method);
  73. clish_ptype_method_e clish_ptype_method_resolve(const char *method_name);
  74. const char *clish_ptype_preprocess__get_name(clish_ptype_preprocess_e
  75. preprocess);
  76. clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char
  77. *preprocess_name);
  78. clish_ptype_t *clish_ptype_new(const char *name, const char *text,
  79. const char *pattern, clish_ptype_method_e method,
  80. clish_ptype_preprocess_e preprocess);
  81. /*-----------------
  82. * methods
  83. *----------------- */
  84. void clish_ptype_delete(clish_ptype_t * instance);
  85. /**
  86. * This is the validation method for the specified type.
  87. * \return
  88. * - NULL if the validation is negative.
  89. * - A pointer to a string containing the validated text. NB. this
  90. * may not be identical to that passed in. e.g. it may have been
  91. * a case-modified "select" or a preprocessed value.
  92. */
  93. char *clish_ptype_validate(const clish_ptype_t * instance, const char *text);
  94. /**
  95. * This is the translation method for the specified type. The text is
  96. * first validated then translated into the form which should be used
  97. * for variable substitutions in ACTION or VIEW_ID fields.
  98. * \return
  99. * - NULL if the validation is negative.
  100. * - A pointer to a string containing the translated text. NB. this
  101. * may not be identical to that passed in. e.g. it may have been
  102. * a translated "select" value.
  103. */
  104. char *clish_ptype_translate(const clish_ptype_t * instance, const char *text);
  105. /**
  106. * This is used to perform parameter auto-completion
  107. */
  108. void clish_ptype_word_generator(clish_ptype_t * instance,
  109. lub_argv_t *matches, const char *text);
  110. void clish_ptype_dump(clish_ptype_t *instance);
  111. void clish_ptype_xml2c(clish_ptype_t *instance);
  112. /*-----------------
  113. * attributes
  114. *----------------- */
  115. const char *clish_ptype__get_name(const clish_ptype_t * instance);
  116. const char *clish_ptype__get_text(const clish_ptype_t * instance);
  117. const char *clish_ptype__get_range(const clish_ptype_t * instance);
  118. void clish_ptype__set_preprocess(clish_ptype_t * instance,
  119. clish_ptype_preprocess_e preprocess);
  120. void clish_ptype__set_pattern(clish_ptype_t * instance,
  121. const char *pattern, clish_ptype_method_e method);
  122. void clish_ptype__set_text(clish_ptype_t * instance, const char *text);
  123. #endif /* _clish_ptype_h */
  124. /** @} clish_ptype */