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