GnuCash 2.4.99
gtable.h
00001 /********************************************************************\
00002  * gtable.h -- glib -- basic datatype for 2D array of values        *
00003  *                                                                  *
00004  * This program is free software; you can redistribute it and/or    *
00005  * modify it under the terms of the GNU General Public License as   *
00006  * published by the Free Software Foundation; either version 2 of   *
00007  * the License, or (at your option) any later version.              *
00008  *                                                                  *
00009  * This program is distributed in the hope that it will be useful,  *
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00012  * GNU General Public License for more details.                     *
00013  *                                                                  *
00014  * You should have received a copy of the GNU General Public License*
00015  * along with this program; if not, contact:                        *
00016  *                                                                  *
00017  * Free Software Foundation           Voice:  +1-617-542-5942       *
00018  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00019  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00020  *                                                                  *
00021 \********************************************************************/
00022 
00023 #ifndef G_TABLE_H
00024 #define G_TABLE_H
00025 
00026 #include <glib.h>
00027 
00028 
00029 /* This is the API for GTables, a datatype for 2-dimensional tables
00030  * with automatic resizing and memory management.
00031  *
00032  * HACK ALERT -- this thing should proably become a part of glib (??)
00033  */
00034 
00035 typedef struct GTable GTable;
00036 
00037 typedef void (*g_table_entry_constructor) (gpointer entry, gpointer user_data);
00038 typedef void (*g_table_entry_destroyer)   (gpointer entry, gpointer user_data);
00039 
00040 
00041 /* Create a new table with the given entry constructor and destroyer.
00042  * Both functions must be given. They are used to initialize the table
00043  * entries and free unneeded memory when resizing and destroying. */
00044 GTable * g_table_new (guint entry_size,
00045                       g_table_entry_constructor constructor,
00046                       g_table_entry_destroyer destroyer,
00047                       gpointer user_data);
00048 
00049 /* Free the table and all associated table elements. */
00050 void     g_table_destroy (GTable *gtable);
00051 
00052 /* Return the element at the given row and column. If the coordinates
00053  * are out-of-bounds, return NULL */
00054 gpointer g_table_index (GTable *gtable, int row, int col);
00055 
00056 /* Resize the table, allocating and deallocating extra table
00057  * members if needed. The relationship between table members
00058  * before and after resizing is undefined, except in the case
00059  * where the number of rows changes, but not the number of
00060  * columns. In that case, higher-numbered rows are discarded
00061  * first. */
00062 void     g_table_resize (GTable *gtable, int rows, int cols);
00063 
00064 /* Return the number of table rows. */
00065 int      g_table_rows (GTable *gtable);
00066 
00067 /* Return the number of table columns. */
00068 int      g_table_cols (GTable *gtable);
00069 
00070 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines