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