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  = libgda-GdaDataModelHash.html
27  * outPack = gda
28  * outFile = DataModelHash
29  * strct   = GdaDataModelHash
30  * realStrct=
31  * ctorStrct=GdaDataModel
32  * clss    = DataModelHash
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = GdaDataModel
38  * implements:
39  * prefixes:
40  * 	- gda_data_model_hash_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- gda.DataModel
47  * 	- gda.Value
48  * 	- gda.Row
49  * structWrap:
50  * 	- GdaDataModel* -> DataModel
51  * 	- GdaRow* -> Row
52  * 	- GdaValue* -> Value
53  * module aliases:
54  * local aliases:
55  * overrides:
56  */
57 
58 module gda.DataModelHash;
59 
60 public  import gdac.gdatypes;
61 
62 private import gdac.gda;
63 private import glib.ConstructionException;
64 private import gobject.ObjectG;
65 
66 private import gda.DataModel;
67 private import gda.Value;
68 private import gda.Row;
69 
70 
71 private import gda.DataModel;
72 
73 /**
74  * Unlike GdaDataModelArray, this data model implementation stores the GdaRow in
75  * a hash table. So it only retrieves from the database backend exactly the
76  * requested rows (while in GdaDataModelArray you have to retrieve all the rows
77  * until the one requested).
78  */
79 public class DataModelHash : DataModel
80 {
81 	
82 	/** the main Gtk struct */
83 	protected GdaDataModelHash* gdaDataModelHash;
84 	
85 	
86 	/** Get the main Gtk struct */
87 	public GdaDataModelHash* getDataModelHashStruct()
88 	{
89 		return gdaDataModelHash;
90 	}
91 	
92 	
93 	/** the main Gtk struct as a void* */
94 	protected override void* getStruct()
95 	{
96 		return cast(void*)gdaDataModelHash;
97 	}
98 	
99 	/**
100 	 * Sets our main struct and passes it to the parent class
101 	 */
102 	public this (GdaDataModelHash* gdaDataModelHash)
103 	{
104 		super(cast(GdaDataModel*)gdaDataModelHash);
105 		this.gdaDataModelHash = gdaDataModelHash;
106 	}
107 	
108 	protected override void setStruct(GObject* obj)
109 	{
110 		super.setStruct(obj);
111 		gdaDataModelHash = cast(GdaDataModelHash*)obj;
112 	}
113 	
114 	/**
115 	 */
116 	
117 	/**
118 	 * Params:
119 	 * cols = number of columns for rows in this data model.
120 	 * Throws: ConstructionException GTK+ fails to create the object.
121 	 */
122 	public this (int cols)
123 	{
124 		// GdaDataModel* gda_data_model_hash_new (gint cols);
125 		auto p = gda_data_model_hash_new(cols);
126 		if(p is null)
127 		{
128 			throw new ConstructionException("null returned by gda_data_model_hash_new(cols)");
129 		}
130 		this(cast(GdaDataModelHash*) p);
131 	}
132 	
133 	/**
134 	 * Retrieves the value at a specified column and row.
135 	 * Params:
136 	 * model = the GdaDataModelHash to retrieve the value from.
137 	 * col = column number (starting from 0).
138 	 * row = row number (starting from 0).
139 	 * Returns: a pointer to a GdaValue.
140 	 */
141 	public static Value getValueAt(DataModel model, int col, int row)
142 	{
143 		// const GdaValue* gda_data_model_hash_get_value_at (GdaDataModel *model,  gint col,  gint row);
144 		auto p = gda_data_model_hash_get_value_at((model is null) ? null : model.getDataModelStruct(), col, row);
145 		
146 		if(p is null)
147 		{
148 			return null;
149 		}
150 		
151 		return ObjectG.getDObject!(Value)(cast(GdaValue*) p);
152 	}
153 	
154 	/**
155 	 * Frees all the rows inserted in model.
156 	 */
157 	public void clear()
158 	{
159 		// void gda_data_model_hash_clear (GdaDataModelHash *model);
160 		gda_data_model_hash_clear(gdaDataModelHash);
161 	}
162 	
163 	/**
164 	 * Sets the number of columns for rows inserted in this model.
165 	 * cols must be greater than or equal to 0.
166 	 * This function calls gda_data_model_hash_clear to free the
167 	 * existing rows if any.
168 	 * Params:
169 	 * cols = the number of columns for rows inserted in model.
170 	 */
171 	public void setNColumns(int cols)
172 	{
173 		// void gda_data_model_hash_set_n_columns (GdaDataModelHash *model,  gint cols);
174 		gda_data_model_hash_set_n_columns(gdaDataModelHash, cols);
175 	}
176 	
177 	/**
178 	 * Inserts a row in the model.
179 	 * Params:
180 	 * rownum = the number of the row.
181 	 * row = the row to insert. The model is responsible of freeing it!
182 	 */
183 	public void insertRow(int rownum, Row row)
184 	{
185 		// void gda_data_model_hash_insert_row (GdaDataModelHash *model,  gint rownum,  GdaRow *row);
186 		gda_data_model_hash_insert_row(gdaDataModelHash, rownum, (row is null) ? null : row.getRowStruct());
187 	}
188 	
189 	/**
190 	 * Retrieves a row from the underlying hash table.
191 	 * Params:
192 	 * model = the GdaDataModelHash
193 	 * row = row number
194 	 * Returns: a GdaRow or NULL if the requested row is not in the hash table.
195 	 */
196 	public static Row getRow(DataModel model, int row)
197 	{
198 		// const GdaRow* gda_data_model_hash_get_row (GdaDataModel *model,  gint row);
199 		auto p = gda_data_model_hash_get_row((model is null) ? null : model.getDataModelStruct(), row);
200 		
201 		if(p is null)
202 		{
203 			return null;
204 		}
205 		
206 		return ObjectG.getDObject!(Row)(cast(GdaRow*) p);
207 	}
208 }