alternative to assert
[gtkD.git] / src / glib / Relation.d
blobe9d01b6497c8555a21a15529c181f2c72fc0316b
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Relations-and-Tuples.html
26 * outPack = glib
27 * outFile = Relation
28 * strct = GRelation
29 * realStrct=
30 * ctorStrct=
31 * clss = Relation
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_relation_
40 * omit structs:
41 * omit prefixes:
42 * - g_tuples_
43 * omit code:
44 * imports:
45 * - glib.HashTable
46 * - glib.Tuples
47 * structWrap:
48 * - GHashTable* -> HashTable
49 * - GTuples* -> Tuples
50 * local aliases:
53 module glib.Relation;
55 private import glib.glibtypes;
57 private import lib.glib;
59 private import glib.HashTable;
60 private import glib.Tuples;
62 /**
63 * Description
64 * A GRelation is a table of data which can be indexed on any number of fields,
65 * rather like simple database tables. A GRelation contains a number of
66 * records, called tuples. Each record contains a number of fields.
67 * Records are not ordered, so it is not possible to find the record at a
68 * particular index.
69 * Note that GRelation tables are currently limited to 2 fields.
70 * To create a GRelation, use g_relation_new().
71 * To specify which fields should be indexed, use g_relation_index().
72 * Note that this must be called before any tuples are added to the GRelation.
73 * To add records to a GRelation use g_relation_insert().
74 * To determine if a given record appears in a GRelation, use
75 * g_relation_exists(). Note that fields are compared directly, so pointers
76 * must point to the exact same position (i.e. different copies of the same
77 * string will not match.)
78 * To count the number of records which have a particular value in a given
79 * field, use g_relation_count().
80 * To get all the records which have a particular value in a given field,
81 * use g_relation_select(). To access fields of the resulting records,
82 * use g_tuples_index(). To free the resulting records use g_tuples_destroy().
83 * To delete all records which have a particular value in a given field,
84 * use g_relation_delete().
85 * To destroy the GRelation, use g_relation_destroy().
86 * To help debug GRelation objects, use g_relation_print().
88 public class Relation
91 /** the main Gtk struct */
92 protected GRelation* gRelation;
95 public GRelation* getRelationStruct()
97 return gRelation;
101 /** the main Gtk struct as a void* */
102 protected void* getStruct()
104 return cast(void*)gRelation;
108 * Sets our main struct and passes it to the parent class
110 public this (GRelation* gRelation)
112 this.gRelation = gRelation;
120 * Creates a new GRelation with the given number of fields.
121 * Note that currently the number of fields must be 2.
122 * fields:
123 * the number of fields.
124 * Returns:
125 * a new GRelation.
127 public this (int fields)
129 // GRelation* g_relation_new (gint fields);
130 this(cast(GRelation*)g_relation_new(fields) );
134 * Creates an index on the given field.
135 * Note that this must be called before any records are added to the GRelation.
136 * relation:
137 * a GRelation.
138 * field:
139 * the field to index, counting from 0.
140 * hash_func:
141 * a function to produce a hash value from the field data.
142 * key_equal_func:
143 * a function to compare two values of the given field.
145 public void index(int field, GHashFunc hashFunc, GEqualFunc keyEqualFunc)
147 // void g_relation_index (GRelation *relation, gint field, GHashFunc hash_func, GEqualFunc key_equal_func);
148 g_relation_index(gRelation, field, hashFunc, keyEqualFunc);
152 * Inserts a record into a GRelation.
153 * relation:
154 * a GRelation.
155 * ...:
156 * the fields of the record to add. These must match the number of
157 * fields in the GRelation, and of type gpointer or gconstpointer.
159 public void insert(... )
161 // void g_relation_insert (GRelation *relation, ...);
162 g_relation_insert(gRelation);
166 * Returns TRUE if a record with the given values exists in a GRelation.
167 * Note that the values are compared directly, so that, for example, two
168 * copies of the same string will not match.
169 * relation:
170 * a GRelation.
171 * ...:
172 * the fields of the record to compare. The number must match the
173 * number of fields in the GRelation.
174 * Returns:
175 * TRUE if a record matches.
177 public int exists(... )
179 // gboolean g_relation_exists (GRelation *relation, ...);
180 return g_relation_exists(gRelation);
184 * Returns the number of tuples in a GRelation that have the given value
185 * in the given field.
186 * relation:
187 * a GRelation.
188 * key:
189 * the value to compare with.
190 * field:
191 * the field of each record to match.
192 * Returns:
193 * the number of matches.
195 public int count(void* key, int field)
197 // gint g_relation_count (GRelation *relation, gconstpointer key, gint field);
198 return g_relation_count(gRelation, key, field);
202 * Returns all of the tuples which have the given key in the given field.
203 * Use g_tuples_index() to access the returned records.
204 * The returned records should be freed with g_tuples_destroy().
205 * relation:
206 * a GRelation.
207 * key:
208 * the value to compare with.
209 * field:
210 * the field of each record to match.
211 * Returns:
212 * the records (tuples) that matched.
214 public Tuples select(void* key, int field)
216 // GTuples* g_relation_select (GRelation *relation, gconstpointer key, gint field);
217 return new Tuples( g_relation_select(gRelation, key, field) );
221 * Deletes any records from a GRelation that have the given key value in
222 * the given field.
223 * relation:
224 * a GRelation.
225 * key:
226 * the value to compare with.
227 * field:
228 * the field of each record to match.
229 * Returns:
230 * the number of records deleted.
232 public int delet(void* key, int field)
234 // gint g_relation_delete (GRelation *relation, gconstpointer key, gint field);
235 return g_relation_delete(gRelation, key, field);
239 * Destroys the GRelation, freeing all memory allocated.
240 * However, it does not free memory allocated for the
241 * tuple data, so you should free that first if appropriate.
242 * relation:
243 * a GRelation.
245 public void destroy()
247 // void g_relation_destroy (GRelation *relation);
248 g_relation_destroy(gRelation);
252 * Outputs information about all records in a GRelation, as well as the indexes.
253 * It is for debugging.
254 * relation:
255 * a GRelation.
257 public void print()
259 // void g_relation_print (GRelation *relation);
260 g_relation_print(gRelation);