/src/wrappers/glib/library/data_types/glib_relations.e

http://github.com/tybor/Liberty · Specman e · 183 lines · 7 code · 46 blank · 130 comment · 0 complexity · e466fff476ab449ed2feb22f30a04668 MD5 · raw file

  1. indexing
  2. copyright: "(C) 2005 Paolo Redaelli "
  3. license: "LGPL v2 or later"
  4. date: "$Date:$"
  5. revision: "$REvision:$"
  6. class GLIB_RELATIONS
  7. -- Prev Up Home GLib Reference Manual Next
  8. -- Top | Description
  9. -- Relations and Tuples
  10. -- Relations and Tuples %G —%@ tables of data which can be indexed on any number of fields.
  11. -- Synopsis
  12. -- #include <glib.h>
  13. -- GRelation;
  14. -- GRelation* g_relation_new (gint fields);
  15. -- void g_relation_index (GRelation *relation,
  16. -- gint field,
  17. -- GHashFunc hash_func,
  18. -- GEqualFunc key_equal_func);
  19. -- void g_relation_insert (GRelation *relation,
  20. -- ...);
  21. -- gboolean g_relation_exists (GRelation *relation,
  22. -- ...);
  23. -- gint g_relation_count (GRelation *relation,
  24. -- gconstpointer key,
  25. -- gint field);
  26. -- GTuples* g_relation_select (GRelation *relation,
  27. -- gconstpointer key,
  28. -- gint field);
  29. -- gint g_relation_delete (GRelation *relation,
  30. -- gconstpointer key,
  31. -- gint field);
  32. -- void g_relation_destroy (GRelation *relation);
  33. -- void g_relation_print (GRelation *relation);
  34. -- GTuples;
  35. -- void g_tuples_destroy (GTuples *tuples);
  36. -- gpointer g_tuples_index (GTuples *tuples,
  37. -- gint index_,
  38. -- gint field);
  39. -- Description
  40. -- A GRelation is a table of data which can be indexed on any number of fields, rather like simple database tables. A GRelation contains a number of records, called tuples. Each record contains a number of fields. Records are not ordered, so it is not possible to find the record at a particular index.
  41. -- Note that GRelation tables are currently limited to 2 fields.
  42. -- To create a GRelation, use g_relation_new().
  43. -- To specify which fields should be indexed, use g_relation_index(). Note that this must be called before any tuples are added to the GRelation.
  44. -- To add records to a GRelation use g_relation_insert().
  45. -- To determine if a given record appears in a GRelation, use g_relation_exists(). Note that fields are compared directly, so pointers must point to the exact same position (i.e. different copies of the same string will not match.)
  46. -- To count the number of records which have a particular value in a given field, use g_relation_count().
  47. -- To get all the records which have a particular value in a given field, use g_relation_select(). To access fields of the resulting records, use g_tuples_index(). To free the resulting records use g_tuples_destroy().
  48. -- To delete all records which have a particular value in a given field, use g_relation_delete().
  49. -- To destroy the GRelation, use g_relation_destroy().
  50. -- To help debug GRelation objects, use g_relation_print().
  51. -- Details
  52. -- GRelation
  53. -- typedef struct _GRelation GRelation;
  54. -- The GRelation struct is an opaque data structure to represent a Relation. It should only be accessed via the following functions.
  55. -- g_relation_new ()
  56. -- GRelation* g_relation_new (gint fields);
  57. -- Creates a new GRelation with the given number of fields. Note that currently the number of fields must be 2.
  58. -- fields : the number of fields.
  59. -- Returns : a new GRelation.
  60. -- g_relation_index ()
  61. -- void g_relation_index (GRelation *relation,
  62. -- gint field,
  63. -- GHashFunc hash_func,
  64. -- GEqualFunc key_equal_func);
  65. -- Creates an index on the given field. Note that this must be called before any records are added to the GRelation.
  66. -- relation : a GRelation.
  67. -- field : the field to index, counting from 0.
  68. -- hash_func : a function to produce a hash value from the field data.
  69. -- key_equal_func : a function to compare two values of the given field.
  70. -- g_relation_insert ()
  71. -- void g_relation_insert (GRelation *relation,
  72. -- ...);
  73. -- Inserts a record into a GRelation.
  74. -- relation : a GRelation.
  75. -- ... : the fields of the record to add. This must match the number of fields in the GRelation.
  76. -- g_relation_exists ()
  77. -- gboolean g_relation_exists (GRelation *relation,
  78. -- ...);
  79. -- Returns TRUE if a record with the given values exists in a GRelation. Note that the values are compared directly, so that, for example, two copies of the same string will not match.
  80. -- relation : a GRelation.
  81. -- ... : the fields of the record to compare. The number must match the number of fields in the GRelation.
  82. -- Returns : TRUE if a record matches.
  83. -- g_relation_count ()
  84. -- gint g_relation_count (GRelation *relation,
  85. -- gconstpointer key,
  86. -- gint field);
  87. -- Returns the number of tuples in a GRelation that have the given value in the given field.
  88. -- relation : a GRelation.
  89. -- key : the value to compare with.
  90. -- field : the field of each record to match.
  91. -- Returns : the number of matches.
  92. -- g_relation_select ()
  93. -- GTuples* g_relation_select (GRelation *relation,
  94. -- gconstpointer key,
  95. -- gint field);
  96. -- Returns all of the tuples which have the given key in the given field. Use g_tuples_index() to access the returned records. The returned records should be freed with g_tuples_destroy().
  97. -- relation : a GRelation.
  98. -- key : the value to compare with.
  99. -- field : the field of each record to match.
  100. -- Returns : the records (tuples) that matched.
  101. -- g_relation_delete ()
  102. -- gint g_relation_delete (GRelation *relation,
  103. -- gconstpointer key,
  104. -- gint field);
  105. -- Deletes any records from a GRelation that have the given key value in the given field.
  106. -- relation : a GRelation.
  107. -- key : the value to compare with.
  108. -- field : the field of each record to match.
  109. -- Returns : the number of records deleted.
  110. -- g_relation_destroy ()
  111. -- void g_relation_destroy (GRelation *relation);
  112. -- Destroys the GRelation, freeing all memory allocated. However, it does not free memory allocated for the tuple data, so you should free that first if appropriate.
  113. -- relation : a GRelation.
  114. -- g_relation_print ()
  115. -- void g_relation_print (GRelation *relation);
  116. -- Outputs information about all records in a GRelation, as well as the indexes. It is for debugging.
  117. -- relation : a GRelation.
  118. -- GTuples
  119. -- typedef struct {
  120. -- guint len;
  121. -- } GTuples;
  122. -- The GTuples struct is used to return records (or tuples) from the GRelation by g_relation_select(). It only contains one public member - the number of records that matched. To access the matched records, you must use g_tuples_index().
  123. -- guint len; the number of records that matched.
  124. -- g_tuples_destroy ()
  125. -- void g_tuples_destroy (GTuples *tuples);
  126. -- Frees the records which were returned by g_relation_select(). This should always be called after g_relation_select() when you are finished with the records. The records are not removed from the GRelation.
  127. -- tuples : the tuple data to free.
  128. -- g_tuples_index ()
  129. -- gpointer g_tuples_index (GTuples *tuples,
  130. -- gint index_,
  131. -- gint field);
  132. -- Gets a field from the records returned by g_relation_select(). It returns the given field of the record at the given index. The returned value should not be changed.
  133. -- tuples : the tuple data, returned by g_relation_select().
  134. -- index_ : the index of the record.
  135. -- field : the field to return.
  136. -- Returns : the field of the record.
  137. end