37 g_table_entry_constructor constructor;
38 g_table_entry_destroyer destroyer;
45 g_table_entry_constructor constructor,
46 g_table_entry_destroyer destroyer,
53 gtable->array = g_array_new(FALSE, FALSE, entry_size);
55 gtable->entry_size = entry_size;
60 gtable->constructor = constructor;
61 gtable->destroyer = destroyer;
63 gtable->user_data = user_data;
76 g_array_free (gtable->array, TRUE);
86 guint index = row * gtable->cols + col;
87 guint offset = index * gtable->entry_size;
91 if ((row < 0) || (col < 0))
93 if (row >= gtable->rows)
95 if (col >= gtable->cols)
98 g_return_val_if_fail (gtable->array != NULL, NULL);
99 g_return_val_if_fail (gtable->array->len > index, NULL);
100 return >able->array->data[offset];
111 if ((rows < 0) || (cols < 0))
114 old_len = gtable->array->len;
115 new_len = rows * cols;
117 if (new_len == old_len)
121 if ((new_len < old_len) && gtable->destroyer)
126 entry = >able->array->data[new_len * gtable->entry_size];
127 for (i = new_len; i < old_len; i++)
129 gtable->destroyer(entry, gtable->user_data);
130 entry += gtable->entry_size;
135 g_array_set_size(gtable->array, new_len);
138 if ((new_len > old_len) && gtable->constructor)
143 entry = >able->array->data[old_len * gtable->entry_size];
144 for (i = old_len; i < new_len; i++)
146 gtable->constructor(entry, gtable->user_data);
147 entry += gtable->entry_size;
int g_table_cols(GTable *gtable)
Return the number of table columns.
GTable * g_table_new(guint entry_size, g_table_entry_constructor constructor, g_table_entry_destroyer destroyer, gpointer user_data)
Create a new table with the given entry constructor and destroyer.
gpointer g_table_index(GTable *gtable, int row, int col)
Return the element at the given row and column.
int g_table_rows(GTable *gtable)
Return the number of table rows.
void g_table_destroy(GTable *gtable)
Free the table and all associated table elements.
void g_table_resize(GTable *gtable, int rows, int cols)
Resize the table, allocating and deallocating extra table members if needed.
This is the API for GTables, a datatype for 2-dimensional tables with automatic resizing and memory m...