cst_features.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 1999 */
  6. /* All Rights Reserved. */
  7. /* */
  8. /* Permission is hereby granted, free of charge, to use and distribute */
  9. /* this software and its documentation without restriction, including */
  10. /* without limitation the rights to use, copy, modify, merge, publish, */
  11. /* distribute, sublicense, and/or sell copies of this work, and to */
  12. /* permit persons to whom this work is furnished to do so, subject to */
  13. /* the following conditions: */
  14. /* 1. The code must retain the above copyright notice, this list of */
  15. /* conditions and the following disclaimer. */
  16. /* 2. Any modifications must be clearly marked as such. */
  17. /* 3. Original authors' names are not deleted. */
  18. /* 4. The authors' names are not used to endorse or promote products */
  19. /* derived from this software without specific prior written */
  20. /* permission. */
  21. /* */
  22. /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
  23. /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
  24. /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
  25. /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
  26. /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
  27. /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
  28. /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
  29. /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
  30. /* THIS SOFTWARE. */
  31. /* */
  32. /*************************************************************************/
  33. /* Author: Alan W Black (awb@cs.cmu.edu) */
  34. /* Date: December 1999 */
  35. /*************************************************************************/
  36. /* */
  37. /* feature-values lists */
  38. /* */
  39. /*************************************************************************/
  40. #ifndef _CST_FEATURES_H__
  41. #define _CST_FEATURES_H__
  42. #include "cst_alloc.h"
  43. #include "cst_val.h"
  44. #include "cst_string.h"
  45. typedef struct cst_featvalpair_struct {
  46. const char *name;
  47. cst_val *val;
  48. struct cst_featvalpair_struct *next;
  49. } cst_featvalpair;
  50. typedef struct cst_features_struct {
  51. struct cst_featvalpair_struct *head;
  52. cst_alloc_context ctx;
  53. cst_val *owned_strings; /* fnames that are owned by this struct */
  54. /* Link to other cst_features that we search too */
  55. const struct cst_features_struct *linked;
  56. } cst_features;
  57. /* Constructor functions */
  58. cst_features *new_features(void);
  59. cst_features *new_features_local(cst_alloc_context ctx);
  60. void delete_features(cst_features *f);
  61. /* Accessor functions */
  62. int feat_int(const cst_features *f, const char *name);
  63. float feat_float(const cst_features *f, const char *name);
  64. const char *feat_string(const cst_features *f, const char *name);
  65. const cst_val *feat_val(const cst_features *f, const char *name);
  66. int get_param_int(const cst_features *f, const char *name,int def);
  67. float get_param_float(const cst_features *f, const char *name, float def);
  68. const char *get_param_string(const cst_features *f, const char *name, const char *def);
  69. const cst_val *get_param_val(const cst_features *f, const char *name, cst_val *def);
  70. /* Setting functions */
  71. void feat_set_int(cst_features *f, const char *name, int v);
  72. void feat_set_float(cst_features *f, const char *name, float v);
  73. void feat_set_string(cst_features *f, const char *name, const char *v);
  74. void feat_set(cst_features *f, const char *name,const cst_val *v);
  75. int feat_remove(cst_features *f,const char *name);
  76. int feat_present(const cst_features *f,const char *name);
  77. int feat_length(const cst_features *f);
  78. /* Feature names are expected to be literals -- its *much* faster to do */
  79. /* look ups and less alloc/frees are necesssary. Almosts always this is */
  80. /* fine, but when you are making up new fnames, you can get a copy of the */
  81. /* string that will be deleted when the cst_features is deleted */
  82. const char *feat_own_string(cst_features *f,const char *name);
  83. CST_VAL_USER_TYPE_DCLS(features,cst_features)
  84. int feat_copy_into(const cst_features *from,cst_features *to);
  85. /* Link FROM into TO so FROM's features will be searched after TO's features */
  86. int feat_link_into(const cst_features *from,cst_features *to);
  87. /* For debugging */
  88. int cst_feat_print(cst_file fd,const cst_features *f);
  89. #endif