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 * Description 71 * A GRelation is a table of data which can be indexed on any number 72 * of fields, rather like simple database tables. A GRelation contains 73 * a number of records, called tuples. Each record contains a number of 74 * fields. Records are not ordered, so it is not possible to find the 75 * record at a particular index. 76 * Note that GRelation tables are currently limited to 2 fields. 77 * To create a GRelation, use g_relation_new(). 78 * To specify which fields should be indexed, use g_relation_index(). 79 * Note that this must be called before any tuples are added to the 80 * GRelation. 81 * To add records to a GRelation use g_relation_insert(). 82 * To determine if a given record appears in a GRelation, use 83 * g_relation_exists(). Note that fields are compared directly, so 84 * pointers must point to the exact same position (i.e. different 85 * copies of the same string will not match.) 86 * To count the number of records which have a particular value in a 87 * given field, use g_relation_count(). 88 * To get all the records which have a particular value in a given 89 * field, use g_relation_select(). To access fields of the resulting 90 * records, use g_tuples_index(). To free the resulting records use 91 * g_tuples_destroy(). 92 * To delete all records which have a particular value in a given 93 * field, use g_relation_delete(). 94 * To destroy the GRelation, use g_relation_destroy(). 95 * To help debug GRelation objects, use g_relation_print(). 96 * GRelation has been marked as deprecated, since this API has never 97 * been fully implemented, is not very actively maintained and rarely 98 * used. 99 */ 100 public class Relation 101 { 102 103 /** the main Gtk struct */ 104 protected GRelation* gRelation; 105 106 107 public GRelation* getRelationStruct() 108 { 109 return gRelation; 110 } 111 112 113 /** the main Gtk struct as a void* */ 114 protected void* getStruct() 115 { 116 return cast(void*)gRelation; 117 } 118 119 /** 120 * Sets our main struct and passes it to the parent class 121 */ 122 public this (GRelation* gRelation) 123 { 124 this.gRelation = gRelation; 125 } 126 127 /** 128 * Outputs information about all records in a GRelation, as well as the indexes. 129 * It is for debugging. 130 */ 131 version(Tango) 132 { 133 public void print() 134 { 135 // void g_relation_print (GRelation *relation); 136 g_relation_print(gRelation); 137 } 138 } 139 else version(D_Version2) 140 { 141 public void print() 142 { 143 // void g_relation_print (GRelation *relation); 144 g_relation_print(gRelation); 145 } 146 } 147 else 148 { 149 public override void print() 150 { 151 // void g_relation_print (GRelation *relation); 152 g_relation_print(gRelation); 153 } 154 } 155 156 /** 157 */ 158 159 /** 160 * Warning 161 * g_relation_new has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API 162 * Creates a new GRelation with the given number of fields. Note that 163 * currently the number of fields must be 2. 164 * Params: 165 * fields = the number of fields. 166 * Throws: ConstructionException GTK+ fails to create the object. 167 */ 168 public this (int fields) 169 { 170 // GRelation * g_relation_new (gint fields); 171 auto p = g_relation_new(fields); 172 if(p is null) 173 { 174 throw new ConstructionException("null returned by g_relation_new(fields)"); 175 } 176 this(cast(GRelation*) p); 177 } 178 179 /** 180 * Warning 181 * g_relation_index has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API 182 * Creates an index on the given field. Note that this must be called 183 * before any records are added to the GRelation. 184 * Params: 185 * field = the field to index, counting from 0. 186 * hashFunc = a function to produce a hash value from the field data. 187 * keyEqualFunc = a function to compare two values of the given field. 188 */ 189 public void index(int field, GHashFunc hashFunc, GEqualFunc keyEqualFunc) 190 { 191 // void g_relation_index (GRelation *relation, gint field, GHashFunc hash_func, GEqualFunc key_equal_func); 192 g_relation_index(gRelation, field, hashFunc, keyEqualFunc); 193 } 194 195 /** 196 * Warning 197 * g_relation_count has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API 198 * Returns the number of tuples in a GRelation that have the given 199 * value in the given field. 200 * Params: 201 * key = the value to compare with. 202 * field = the field of each record to match. 203 * Returns: the number of matches. 204 */ 205 public int count(void* key, int field) 206 { 207 // gint g_relation_count (GRelation *relation, gconstpointer key, gint field); 208 return g_relation_count(gRelation, key, field); 209 } 210 211 /** 212 * Warning 213 * g_relation_select has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API 214 * Returns all of the tuples which have the given key in the given 215 * field. Use g_tuples_index() to access the returned records. The 216 * returned records should be freed with g_tuples_destroy(). 217 * Params: 218 * key = the value to compare with. 219 * field = the field of each record to match. 220 * Returns: the records (tuples) that matched. 221 */ 222 public Tuples select(void* key, int field) 223 { 224 // GTuples * g_relation_select (GRelation *relation, gconstpointer key, gint field); 225 auto p = g_relation_select(gRelation, key, field); 226 227 if(p is null) 228 { 229 return null; 230 } 231 232 return new Tuples(cast(GTuples*) p); 233 } 234 235 /** 236 * Warning 237 * g_relation_delete has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API 238 * Deletes any records from a GRelation that have the given key value 239 * in the given field. 240 * Params: 241 * key = the value to compare with. 242 * field = the field of each record to match. 243 * Returns: the number of records deleted. 244 */ 245 public int delet(void* key, int field) 246 { 247 // gint g_relation_delete (GRelation *relation, gconstpointer key, gint field); 248 return g_relation_delete(gRelation, key, field); 249 } 250 251 /** 252 * Warning 253 * g_relation_destroy has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API 254 * Destroys the GRelation, freeing all memory allocated. However, it 255 * does not free memory allocated for the tuple data, so you should 256 * free that first if appropriate. 257 */ 258 public void destroy() 259 { 260 // void g_relation_destroy (GRelation *relation); 261 g_relation_destroy(gRelation); 262 } 263 }