1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Relations-and-Tuples.html
27  * outPack = glib
28  * outFile = Relation
29  * strct   = GRelation
30  * realStrct=
31  * ctorStrct=
32  * clss    = Relation
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_relation_
41  * omit structs:
42  * omit prefixes:
43  * 	- g_tuples_
44  * omit code:
45  * 	- g_relation_print
46  * omit signals:
47  * imports:
48  * 	- glib.Tuples
49  * structWrap:
50  * 	- GTuples* -> Tuples
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module glib.Relation;
57 
58 public  import gtkc.glibtypes;
59 
60 private import gtkc.glib;
61 private import glib.ConstructionException;
62 
63 
64 private import glib.Tuples;
65 
66 
67 
68 
69 /**
70  * A GRelation is a table of data which can be indexed on any number
71  * of fields, rather like simple database tables. A GRelation contains
72  * a number of records, called tuples. Each record contains a number of
73  * fields. Records are not ordered, so it is not possible to find the
74  * record at a particular index.
75  *
76  * Note that GRelation tables are currently limited to 2 fields.
77  *
78  * To create a GRelation, use g_relation_new().
79  *
80  * To specify which fields should be indexed, use g_relation_index().
81  * Note that this must be called before any tuples are added to the
82  * GRelation.
83  *
84  * To add records to a GRelation use g_relation_insert().
85  *
86  * To determine if a given record appears in a GRelation, use
87  * g_relation_exists(). Note that fields are compared directly, so
88  * pointers must point to the exact same position (i.e. different
89  * copies of the same string will not match.)
90  *
91  * To count the number of records which have a particular value in a
92  * given field, use g_relation_count().
93  *
94  * To get all the records which have a particular value in a given
95  * field, use g_relation_select(). To access fields of the resulting
96  * records, use g_tuples_index(). To free the resulting records use
97  * g_tuples_destroy().
98  *
99  * To delete all records which have a particular value in a given
100  * field, use g_relation_delete().
101  *
102  * To destroy the GRelation, use g_relation_destroy().
103  *
104  * To help debug GRelation objects, use g_relation_print().
105  *
106  * GRelation has been marked as deprecated, since this API has never
107  * been fully implemented, is not very actively maintained and rarely
108  * used.
109  */
110 public class Relation
111 {
112 	
113 	/** the main Gtk struct */
114 	protected GRelation* gRelation;
115 	
116 	
117 	public GRelation* getRelationStruct()
118 	{
119 		return gRelation;
120 	}
121 	
122 	
123 	/** the main Gtk struct as a void* */
124 	protected void* getStruct()
125 	{
126 		return cast(void*)gRelation;
127 	}
128 	
129 	/**
130 	 * Sets our main struct and passes it to the parent class
131 	 */
132 	public this (GRelation* gRelation)
133 	{
134 		this.gRelation = gRelation;
135 	}
136 	
137 	/**
138 	 * Outputs information about all records in a GRelation, as well as the indexes.
139 	 * It is for debugging.
140 	 */
141 	version(Tango)
142 	{
143 		public void print()
144 		{
145 			// void g_relation_print (GRelation *relation);
146 			g_relation_print(gRelation);
147 		}
148 	}
149 	else version(D_Version2)
150 	{
151 		public void print()
152 		{
153 			// void g_relation_print (GRelation *relation);
154 			g_relation_print(gRelation);
155 		}
156 	}
157 	else
158 	{
159 		public override void print()
160 		{
161 			// void g_relation_print (GRelation *relation);
162 			g_relation_print(gRelation);
163 		}
164 	}
165 	
166 	/**
167 	 */
168 	
169 	/**
170 	 * Warning
171 	 * g_relation_new has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
172 	 * Creates a new GRelation with the given number of fields. Note that
173 	 * currently the number of fields must be 2.
174 	 * Params:
175 	 * fields = the number of fields.
176 	 * Throws: ConstructionException GTK+ fails to create the object.
177 	 */
178 	public this (int fields)
179 	{
180 		// GRelation * g_relation_new (gint fields);
181 		auto p = g_relation_new(fields);
182 		if(p is null)
183 		{
184 			throw new ConstructionException("null returned by g_relation_new(fields)");
185 		}
186 		this(cast(GRelation*) p);
187 	}
188 	
189 	/**
190 	 * Warning
191 	 * g_relation_index has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
192 	 * Creates an index on the given field. Note that this must be called
193 	 * before any records are added to the GRelation.
194 	 * Params:
195 	 * field = the field to index, counting from 0.
196 	 * hashFunc = a function to produce a hash value from the field data.
197 	 * keyEqualFunc = a function to compare two values of the given field.
198 	 */
199 	public void index(int field, GHashFunc hashFunc, GEqualFunc keyEqualFunc)
200 	{
201 		// void g_relation_index (GRelation *relation,  gint field,  GHashFunc hash_func,  GEqualFunc key_equal_func);
202 		g_relation_index(gRelation, field, hashFunc, keyEqualFunc);
203 	}
204 	
205 	/**
206 	 * Warning
207 	 * g_relation_count has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
208 	 * Returns the number of tuples in a GRelation that have the given
209 	 * value in the given field.
210 	 * Params:
211 	 * key = the value to compare with.
212 	 * field = the field of each record to match.
213 	 * Returns: the number of matches.
214 	 */
215 	public int count(void* key, int field)
216 	{
217 		// gint g_relation_count (GRelation *relation,  gconstpointer key,  gint field);
218 		return g_relation_count(gRelation, key, field);
219 	}
220 	
221 	/**
222 	 * Warning
223 	 * g_relation_select has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
224 	 * Returns all of the tuples which have the given key in the given
225 	 * field. Use g_tuples_index() to access the returned records. The
226 	 * returned records should be freed with g_tuples_destroy().
227 	 * Params:
228 	 * key = the value to compare with.
229 	 * field = the field of each record to match.
230 	 * Returns: the records (tuples) that matched.
231 	 */
232 	public Tuples select(void* key, int field)
233 	{
234 		// GTuples * g_relation_select (GRelation *relation,  gconstpointer key,  gint field);
235 		auto p = g_relation_select(gRelation, key, field);
236 		
237 		if(p is null)
238 		{
239 			return null;
240 		}
241 		
242 		return new Tuples(cast(GTuples*) p);
243 	}
244 	
245 	/**
246 	 * Warning
247 	 * g_relation_delete has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
248 	 * Deletes any records from a GRelation that have the given key value
249 	 * in the given field.
250 	 * Params:
251 	 * key = the value to compare with.
252 	 * field = the field of each record to match.
253 	 * Returns: the number of records deleted.
254 	 */
255 	public int delet(void* key, int field)
256 	{
257 		// gint g_relation_delete (GRelation *relation,  gconstpointer key,  gint field);
258 		return g_relation_delete(gRelation, key, field);
259 	}
260 	
261 	/**
262 	 * Warning
263 	 * g_relation_destroy has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
264 	 * Destroys the GRelation, freeing all memory allocated. However, it
265 	 * does not free memory allocated for the tuple data, so you should
266 	 * free that first if appropriate.
267 	 */
268 	public void destroy()
269 	{
270 		// void g_relation_destroy (GRelation *relation);
271 		g_relation_destroy(gRelation);
272 	}
273 }