Added g_array_length
[platform/upstream/glib.git] / glib / glib.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #ifndef __G_LIB_H__
20 #define __G_LIB_H__
21
22 #include <glibconfig.h>
23
24 #ifdef USE_DMALLOC
25 #include "dmalloc.h"
26 #endif
27
28
29 /* glib provides definitions for the extrema of many
30  *  of the standard types. These are:
31  * G_MINFLOAT
32  * G_MAXFLOAT
33  * G_MINDOUBLE
34  * G_MAXDOUBLE
35  * G_MINSHORT
36  * G_MAXSHORT
37  * G_MININT
38  * G_MAXINT
39  * G_MINLONG
40  * G_MAXLONG
41  */
42
43 #ifdef HAVE_FLOAT_H
44
45 #include <float.h>
46
47 #define G_MINFLOAT   FLT_MIN
48 #define G_MAXFLOAT   FLT_MAX
49 #define G_MINDOUBLE  DBL_MIN
50 #define G_MAXDOUBLE  DBL_MAX
51
52 #elif HAVE_VALUES_H
53
54 #include <values.h>
55
56 #define G_MINFLOAT  MINFLOAT
57 #define G_MAXFLOAT  MAXFLOAT
58 #define G_MINDOUBLE MINDOUBLE
59 #define G_MAXDOUBLE MAXDOUBLE
60
61 #endif /* HAVE_VALUES_H */
62
63
64 #ifdef HAVE_LIMITS_H
65
66 #include <limits.h>
67
68 #define G_MINSHORT  SHRT_MIN
69 #define G_MAXSHORT  SHRT_MAX
70 #define G_MININT    INT_MIN
71 #define G_MAXINT    INT_MAX
72 #define G_MINLONG   LONG_MIN
73 #define G_MAXLONG   LONG_MAX
74
75 #elif HAVE_VALUES_H
76
77 #ifdef HAVE_FLOAT_H
78 #include <values.h>
79 #endif /* HAVE_FLOAT_H */
80
81 #define G_MINSHORT  MINSHORT
82 #define G_MAXSHORT  MAXSHORT
83 #define G_MININT    MININT
84 #define G_MAXINT    MAXINT
85 #define G_MINLONG   MINLONG
86 #define G_MAXLONG   MAXLONG
87
88 #endif /* HAVE_VALUES_H */
89
90
91 /* Provide definitions for some commonly used macros.
92  *  Some of them are only provided if they haven't already
93  *  been defined. It is assumed that if they are already
94  *  defined then the current definition is correct.
95  */
96 #ifndef NULL
97 #define NULL    ((void*) 0)
98 #endif
99
100 #ifndef FALSE
101 #define FALSE   (0)
102 #endif
103
104 #ifndef TRUE
105 #define TRUE    (!FALSE)
106 #endif
107
108 #undef  MAX
109 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
110
111 #undef  MIN
112 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
113
114 #undef  ABS
115 #define ABS(a)     (((a) < 0) ? -(a) : (a))
116
117 #undef  CLAMP
118 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
119
120
121 /* Provide simple enum value macro wrappers that ease automated enum value
122  * stringification code.
123  */
124 #if     !defined (G_CODE_GENERATION)
125 #define G_ENUM( EnumerationName )               EnumerationName
126 #define G_FLAGS( EnumerationName )              EnumerationName
127 #define G_NV( VALUE_NAME , value_nick, VALUE)   VALUE_NAME = (VALUE)
128 #define G_SV( VALUE_NAME, value_nick )          VALUE_NAME
129 #else   /* G_CODE_GENERATION */
130 #define G_ENUM( EnumerationName )               G_ENUM_E + EnumerationName +
131 #define G_FLAGS( EnumerationName )              G_ENUM_F + EnumerationName +
132 #define G_NV( VALUE_NAME , value_nick, VALUE)   G_ENUM_V + VALUE_NAME + value_nick +
133 #define G_SV( VALUE_NAME, value_nick )          G_ENUM_V + VALUE_NAME + value_nick +
134 #endif  /* G_CODE_GENERATION */
135
136
137 /* Provide simple macro statement wrappers (adapted from Pearl):
138  *  G_STMT_START { statements; } G_STMT_END;
139  *  can be used as a single statement, as in
140  *  if (x) G_STMT_START { ... } G_STMT_END; else ...
141  *
142  *  For gcc we will wrap the statements within `({' and `})' braces.
143  *  For SunOS they will be wrapped within `if (1)' and `else (void) 0',
144  *  and otherwise within `do' and `while (0)'.
145  */
146 #if !(defined (G_STMT_START) && defined (G_STMT_END))
147 #  if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
148 #    define G_STMT_START        (void)(
149 #    define G_STMT_END          )
150 #  else
151 #    if (defined (sun) || defined (__sun__))
152 #      define G_STMT_START      if (1)
153 #      define G_STMT_END        else (void)0
154 #    else
155 #      define G_STMT_START      do
156 #      define G_STMT_END        while (0)
157 #    endif
158 #  endif
159 #endif
160
161 /* Provide macros to feature the GCC function attribute.
162  */
163 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
164 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
165   __attribute__((format (printf, format_idx, arg_idx)))
166 #define G_GNUC_SCANF( format_idx, arg_idx )     \
167   __attribute__((format (scanf, format_idx, arg_idx)))
168 #define G_GNUC_FORMAT( arg_idx )                \
169   __attribute__((format_arg (arg_idx)))
170 #define G_GNUC_NORETURN                         \
171   __attribute__((noreturn))
172 #define G_GNUC_CONST                            \
173   __attribute__((const))
174 #else   /* !__GNUC__ */
175 #define G_GNUC_PRINTF( format_idx, arg_idx )
176 #define G_GNUC_SCANF( format_idx, arg_idx )
177 #define G_GNUC_FORMAT( arg_idx )
178 #define G_GNUC_NORETURN
179 #define G_GNUC_CONST
180 #endif  /* !__GNUC__ */
181
182 /* Hacker macro to place breakpoints for x86 machines.
183  * Actuall use is strongly deprecated of course ;)
184  */
185 #if     defined (__i386__)
186 #define G_BREAKPOINT()          G_STMT_START{ __asm__ ("int $03"); }G_STMT_END
187 #else   /* !__i386__ */
188 #define G_BREAKPOINT()
189 #endif  /* __i386__ */
190
191 /* Wrap the __PRETTY_FUNCTION__ and __FUNCTION__ variables with macros,
192  * so we can refer to them as strings unconditionally.
193  */
194 #ifdef  __GNUC__
195 #define G_GNUC_FUNCTION         (__FUNCTION__)
196 #define G_GNUC_PRETTY_FUNCTION  (__PRETTY_FUNCTION__)
197 #else   /* !__GNUC__ */
198 #define G_GNUC_FUNCTION         ("")
199 #define G_GNUC_PRETTY_FUNCTION  ("")
200 #endif  /* !__GNUC__ */
201
202
203 #ifndef ATEXIT
204 #  ifdef HAVE_ATEXIT
205 #    define ATEXIT(proc)   (atexit (proc))
206 #  elif defined (HAVE_ON_EXIT)
207 #    define ATEXIT(proc)   (on_exit ((void (*)(int, void *))(proc), NULL))
208 #  endif    
209 #endif /* ATEXIT */
210
211
212 /* Provide macros for easily allocating memory. The macros
213  *  will cast the allocated memory to the specified type
214  *  in order to avoid compiler warnings. (Makes the code neater).
215  */
216
217 #ifdef __DMALLOC_H__
218
219 #define g_new(type,count)        ALLOC(type,count)
220 #define g_new0(type,count)       CALLOC(type,count)
221
222 #else /* __DMALLOC_H__ */
223
224 #define g_new(type, count)        \
225     ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
226 #define g_new0(type, count)       \
227     ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
228 #endif /* __DMALLOC_H__ */
229
230 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
231   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
232                    sizeof (type), \
233                    sizeof (type) * (pre_alloc), \
234                    (alloc_type)) \
235 )
236 #define g_chunk_new(type, chunk)        ( \
237   (type *) g_mem_chunk_alloc (chunk) \
238 )
239 #define g_chunk_new0(type, chunk)       ( \
240   (type *) memset (g_mem_chunk_alloc (chunk), 0, sizeof (type)) \
241 )
242 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
243   g_mem_chunk_free ((mem_chunk), (mem)); \
244 } G_STMT_END
245
246 #define g_string(x) #x
247
248
249 /* Provide macros for error handling. The "assert" macros will
250  *  exit on failure. The "return" macros will exit the current
251  *  function. Two different definitions are given for the macros
252  *  in order to support gcc's __PRETTY_FUNCTION__ capability.
253  */
254
255 #ifdef G_DISABLE_ASSERT
256
257 #define g_assert(expr)
258 #define g_assert_not_reached()
259
260 #else /* !G_DISABLE_ASSERT */
261
262 #ifdef __GNUC__
263
264 #define g_assert(expr)                  G_STMT_START{\
265      if (!(expr))                                    \
266        g_error ("file %s: line %d (%s): \"%s\"",     \
267                 __FILE__,                            \
268                 __LINE__,                            \
269                 __PRETTY_FUNCTION__,                 \
270                 #expr);                 }G_STMT_END
271
272 #define g_assert_not_reached()          G_STMT_START{                 \
273      g_error ("file %s: line %d (%s): \"should not be reached\"",     \
274               __FILE__,                                               \
275               __LINE__,                                               \
276               __PRETTY_FUNCTION__);     }G_STMT_END
277
278 #else /* !__GNUC__ */
279
280 #define g_assert(expr)                  G_STMT_START{\
281      if (!(expr))                                    \
282        g_error ("file %s: line %d: \"%s\"",          \
283                 __FILE__,                            \
284                 __LINE__,                            \
285                 #expr);                 }G_STMT_END
286
287 #define g_assert_not_reached()          G_STMT_START{                 \
288      g_error ("file %s: line %d: \"should not be reached\"",          \
289               __FILE__,                                               \
290               __LINE__);                }G_STMT_END
291
292 #endif /* __GNUC__ */
293
294 #endif /* G_DISABLE_ASSERT */
295
296 #ifdef G_DISABLE_CHECKS
297
298 #define g_return_if_fail(expr)
299 #define g_return_val_if_fail(expr,val)
300
301 #else /* !G_DISABLE_CHECKS */
302
303 #ifdef __GNUC__
304
305 #define g_return_if_fail(expr)          G_STMT_START{                  \
306      if (!(expr))                                                      \
307        {                                                               \
308          g_warning ("file %s: line %d (%s): assertion \"%s\" failed.", \
309                     __FILE__,                                          \
310                     __LINE__,                                          \
311                     __PRETTY_FUNCTION__,                               \
312                     #expr);                                            \
313          return;                                                       \
314        };                               }G_STMT_END
315
316 #define g_return_val_if_fail(expr,val)  G_STMT_START{                  \
317      if (!(expr))                                                      \
318        {                                                               \
319          g_warning ("file %s: line %d (%s): assertion \"%s\" failed.", \
320                     __FILE__,                                          \
321                     __LINE__,                                          \
322                     __PRETTY_FUNCTION__,                               \
323                     #expr);                                            \
324          return val;                                                   \
325        };                               }G_STMT_END
326
327 #else /* !__GNUC__ */
328
329 #define g_return_if_fail(expr)          G_STMT_START{             \
330      if (!(expr))                                                 \
331        {                                                          \
332          g_warning ("file %s: line %d: assertion. \"%s\" failed", \
333                     __FILE__,                                     \
334                     __LINE__,                                     \
335                     #expr);                                       \
336          return;                                                  \
337        };                               }G_STMT_END
338
339 #define g_return_val_if_fail(expr, val) G_STMT_START{             \
340      if (!(expr))                                                 \
341        {                                                          \
342          g_warning ("file %s: line %d: assertion \"%s\" failed.", \
343                     __FILE__,                                     \
344                     __LINE__,                                     \
345                     #expr);                                       \
346          return val;                                              \
347        };                               }G_STMT_END
348
349 #endif /* !__GNUC__ */
350
351 #endif /* G_DISABLE_CHECKS */
352
353
354 #ifdef __cplusplus
355 extern "C" {
356 #pragma }
357 #endif /* __cplusplus */
358
359 /* Provide type definitions for commonly used types.
360  *  These are useful because a "gint8" can be adjusted
361  *  to be 1 byte (8 bits) on all platforms. Similarly and
362  *  more importantly, "gint32" can be adjusted to be
363  *  4 bytes (32 bits) on all platforms.
364  */
365
366 typedef char   gchar;
367 typedef short  gshort;
368 typedef long   glong;
369 typedef int    gint;
370 typedef gint   gboolean;
371
372 typedef unsigned char   guchar;
373 typedef unsigned short  gushort;
374 typedef unsigned long   gulong;
375 typedef unsigned int    guint;
376
377 typedef float   gfloat;
378 typedef double  gdouble;
379
380 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms. 
381  * Since gldouble isn't used anywhere, just disable it for now */
382
383 #if 0
384 #ifdef HAVE_LONG_DOUBLE
385 typedef long double gldouble;
386 #else /* HAVE_LONG_DOUBLE */
387 typedef double gldouble;
388 #endif /* HAVE_LONG_DOUBLE */
389 #endif /* 0 */
390
391 typedef void* gpointer;
392 typedef const void *gconstpointer;
393
394 #if (SIZEOF_CHAR == 1)
395 typedef signed char     gint8;
396 typedef unsigned char   guint8;
397 #endif /* SIZEOF_CHAR */
398
399
400 #if (SIZEOF_SHORT == 2)
401 typedef signed short    gint16;
402 typedef unsigned short  guint16;
403 #endif /* SIZEOF_SHORT */
404
405
406 #if (SIZEOF_INT == 4)
407 typedef signed int      gint32;
408 typedef unsigned int    guint32;
409 #elif (SIZEOF_LONG == 4)
410 typedef signed long     gint32;
411 typedef unsigned long   guint32;
412 #endif /* SIZEOF_INT */
413
414 /* Define macros for storing integers inside pointers */
415
416 #if (SIZEOF_INT == SIZEOF_VOID_P)
417
418 #define GPOINTER_TO_INT(p) ((gint)(p))
419 #define GPOINTER_TO_UINT(p) ((guint)(p))
420
421 #define GINT_TO_POINTER(i) ((gpointer)(i))
422 #define GUINT_TO_POINTER(u) ((gpointer)(u))
423
424 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
425
426 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
427 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
428
429 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
430 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
431
432 #else
433 /* This should never happen */
434 #endif
435
436 typedef gint32  gssize;
437 typedef guint32 gsize;
438 typedef gint32  gtime;
439 typedef guint32 GQuark;
440
441 typedef struct _GList           GList;
442 typedef struct _GSList          GSList;
443 typedef struct _GHashTable      GHashTable;
444 typedef struct _GCache          GCache;
445 typedef struct _GTree           GTree;
446 typedef struct _GTimer          GTimer;
447 typedef struct _GMemChunk       GMemChunk;
448 typedef struct _GListAllocator  GListAllocator;
449 typedef struct _GStringChunk    GStringChunk;
450 typedef struct _GString         GString;
451 typedef struct _GArray          GArray;
452 typedef struct _GPtrArray       GPtrArray;
453 typedef struct _GByteArray      GByteArray;
454 typedef struct _GDebugKey       GDebugKey;
455 typedef struct _GScannerConfig  GScannerConfig;
456 typedef struct _GScanner        GScanner;
457 typedef union  _GValue          GValue;
458 typedef struct _GRelation      GRelation;
459 typedef struct _GTuples        GTuples;
460
461
462 typedef void            (*GFunc)                (gpointer  data,
463                                                  gpointer  user_data);
464 typedef void            (*GHFunc)               (gpointer  key,
465                                                  gpointer  value,
466                                                  gpointer  user_data);
467 typedef gpointer        (*GCacheNewFunc)        (gpointer  key);
468 typedef gpointer        (*GCacheDupFunc)        (gpointer  value);
469 typedef void            (*GCacheDestroyFunc)    (gpointer  value);
470 typedef gint            (*GTraverseFunc)        (gpointer  key,
471                                                  gpointer  value,
472                                                  gpointer  data);
473 typedef gint            (*GSearchFunc)          (gpointer  key,
474                                                  gpointer  data);
475 typedef void            (*GErrorFunc)           (gchar    *str);
476 typedef void            (*GWarningFunc)         (gchar    *str);
477 typedef void            (*GPrintFunc)           (gchar    *str);
478 typedef void            (*GScannerMsgFunc)      (GScanner *scanner,
479                                                  gchar    *message,
480                                                  gint      error);
481 typedef void            (*GDestroyNotify)       (gpointer  data);
482
483 typedef guint           (*GHashFunc)            (gconstpointer    key);
484 typedef gint            (*GCompareFunc)         (gconstpointer    a,
485                                                  gconstpointer    b);
486
487 struct _GList
488 {
489   gpointer data;
490   GList *next;
491   GList *prev;
492 };
493
494 struct _GSList
495 {
496   gpointer data;
497   GSList *next;
498 };
499
500 struct _GString
501 {
502   gchar *str;
503   gint len;
504 };
505
506 struct _GArray
507 {
508   gchar *data;
509   guint len;
510 };
511
512 struct _GByteArray
513 {
514   guint8 *data;
515   guint   len;
516 };
517
518 struct _GPtrArray
519 {
520   gpointer *pdata;
521   guint     len;
522 };
523
524 struct _GTuples
525 {
526   guint len;
527 };
528
529 struct _GDebugKey
530 {
531   gchar *key;
532   guint  value;
533 };
534
535 struct _GHashTable { gint dummy; };
536 struct _GCache { gint dummy; };
537 struct _GTree { gint dummy; };
538 struct _GTimer { gint dummy; };
539 struct _GMemChunk { gint dummy; };
540 struct _GListAllocator { gint dummy; };
541 struct _GStringChunk { gint dummy; };
542
543 typedef enum
544 {
545   G_IN_ORDER,
546   G_PRE_ORDER,
547   G_POST_ORDER
548 } GTraverseType;
549
550 /* Doubly linked lists
551  */
552 GList* g_list_alloc             (void);
553 void   g_list_free              (GList          *list);
554 void   g_list_free_1            (GList          *list);
555 GList* g_list_append            (GList          *list,
556                                  gpointer        data);
557 GList* g_list_prepend           (GList          *list,
558                                  gpointer        data);
559 GList* g_list_insert            (GList          *list,
560                                  gpointer        data,
561                                  gint            position);
562 GList* g_list_insert_sorted     (GList          *list,
563                                  gpointer        data,
564                                  GCompareFunc    func);                     
565 GList* g_list_concat            (GList          *list1, 
566                                  GList          *list2);
567 GList* g_list_remove            (GList          *list,
568                                  gpointer        data);
569 GList* g_list_remove_link       (GList          *list,
570                                  GList          *link);
571 GList* g_list_reverse           (GList          *list);
572 GList* g_list_nth               (GList          *list,
573                                  guint           n);
574 GList* g_list_find              (GList          *list,
575                                  gpointer        data);
576 GList* g_list_find_custom       (GList          *list,
577                                  gpointer        data,
578                                  GCompareFunc    func);
579 gint   g_list_position          (GList          *list,
580                                  GList          *link);
581 gint   g_list_index             (GList          *list,
582                                  gpointer        data);
583 GList* g_list_last              (GList          *list);
584 GList* g_list_first             (GList          *list);
585 guint  g_list_length            (GList          *list);
586 void   g_list_foreach           (GList          *list,
587                                  GFunc           func,
588                                  gpointer        user_data);
589 gpointer g_list_nth_data        (GList          *list,
590                                  guint           n);
591
592 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
593 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
594
595 /* Singly linked lists
596  */
597 GSList* g_slist_alloc           (void);
598 void    g_slist_free            (GSList         *list);
599 void    g_slist_free_1          (GSList         *list);
600 GSList* g_slist_append          (GSList         *list,
601                                  gpointer        data);
602 GSList* g_slist_prepend         (GSList         *list,
603                                  gpointer        data);
604 GSList* g_slist_insert          (GSList         *list,
605                                  gpointer        data,
606                                  gint            position);
607 GSList* g_slist_insert_sorted   (GSList         *list,
608                                  gpointer        data,
609                                  GCompareFunc    func);                     
610 GSList* g_slist_concat          (GSList         *list1, 
611                                  GSList         *list2);
612 GSList* g_slist_remove          (GSList         *list,
613                                  gpointer        data);
614 GSList* g_slist_remove_link     (GSList         *list,
615                                  GSList         *link);
616 GSList* g_slist_reverse         (GSList         *list);
617 GSList* g_slist_nth             (GSList         *list,
618                                  guint           n);
619 GSList* g_slist_find            (GSList         *list,
620                                  gpointer        data);
621 GSList* g_slist_find_custom     (GSList         *list,
622                                  gpointer        data,
623                                  GCompareFunc    func);
624 gint    g_slist_position        (GSList         *list,
625                                  GSList         *link);
626 gint    g_slist_index           (GSList         *list,
627                                  gpointer        data);
628 GSList* g_slist_last            (GSList         *list);
629 guint   g_slist_length          (GSList         *list);
630 void    g_slist_foreach         (GSList         *list,
631                                  GFunc           func,
632                                  gpointer        user_data);
633 gpointer g_slist_nth_data       (GSList         *list,
634                                  guint           n);
635
636 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
637
638 /* List Allocators
639  */
640 GListAllocator* g_list_allocator_new  (void);
641 void            g_list_allocator_free (GListAllocator* allocator);
642 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
643 GListAllocator* g_list_set_allocator  (GListAllocator* allocator);
644
645
646 /* Hash tables
647  */
648 GHashTable* g_hash_table_new     (GHashFunc       hash_func,
649                                   GCompareFunc    key_compare_func);
650 void        g_hash_table_destroy (GHashTable     *hash_table);
651 void        g_hash_table_insert  (GHashTable     *hash_table,
652                                   gpointer        key,
653                                   gpointer        value);
654 void        g_hash_table_remove  (GHashTable     *hash_table,
655                                   gconstpointer   key);
656 gpointer    g_hash_table_lookup  (GHashTable     *hash_table,
657                                   gconstpointer    key);
658 void        g_hash_table_freeze  (GHashTable     *hash_table);
659 void        g_hash_table_thaw    (GHashTable     *hash_table);
660 void        g_hash_table_foreach (GHashTable     *hash_table,
661                                   GHFunc          func,
662                                   gpointer        user_data);
663 gint        g_hash_table_size    (GHashTable     *hash_table);
664
665
666 /* Caches
667  */
668 GCache*  g_cache_new           (GCacheNewFunc      value_new_func,
669                                 GCacheDestroyFunc  value_destroy_func,
670                                 GCacheDupFunc      key_dup_func,
671                                 GCacheDestroyFunc  key_destroy_func,
672                                 GHashFunc          hash_key_func,
673                                 GHashFunc          hash_value_func,
674                                 GCompareFunc       key_compare_func);
675 void     g_cache_destroy       (GCache            *cache);
676 gpointer g_cache_insert        (GCache            *cache,
677                                 gpointer           key);
678 void     g_cache_remove        (GCache            *cache,
679                                 gpointer           value);
680 void     g_cache_key_foreach   (GCache            *cache,
681                                 GHFunc             func,
682                                 gpointer           user_data);
683 void     g_cache_value_foreach (GCache            *cache,
684                                 GHFunc             func,
685                                 gpointer           user_data);
686
687
688 /* Trees
689  */
690 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
691 void     g_tree_destroy  (GTree         *tree);
692 void     g_tree_insert   (GTree         *tree,
693                           gpointer       key,
694                           gpointer       value);
695 void     g_tree_remove   (GTree         *tree,
696                           gpointer       key);
697 gpointer g_tree_lookup   (GTree         *tree,
698                           gpointer       key);
699 void     g_tree_traverse (GTree         *tree,
700                           GTraverseFunc  traverse_func,
701                           GTraverseType  traverse_type,
702                           gpointer       data);
703 gpointer g_tree_search   (GTree         *tree,
704                           GSearchFunc    search_func,
705                           gpointer       data);
706 gint     g_tree_height   (GTree         *tree);
707 gint     g_tree_nnodes   (GTree         *tree);
708
709
710 /* Memory
711  */
712
713 #ifdef USE_DMALLOC
714
715 #define g_malloc(size)       (gpointer) MALLOC(size)
716 #define g_malloc0(size)      (gpointer) CALLOC(char,size)
717 #define g_realloc(mem,size)  (gpointer) REALLOC(mem,char,size)
718 #define g_free(mem)          FREE(mem)
719
720 #else /* USE_DMALLOC */
721
722 gpointer g_malloc      (gulong    size);
723 gpointer g_malloc0     (gulong    size);
724 gpointer g_realloc     (gpointer  mem,
725                         gulong    size);
726 void     g_free        (gpointer  mem);
727
728 #endif /* USE_DMALLOC */
729
730 void     g_mem_profile (void);
731 void     g_mem_check   (gpointer  mem);
732
733
734 /* "g_mem_chunk_new" creates a new memory chunk.
735  * Memory chunks are used to allocate pieces of memory which are
736  *  always the same size. Lists are a good example of such a data type.
737  * The memory chunk allocates and frees blocks of memory as needed.
738  *  Just be sure to call "g_mem_chunk_free" and not "g_free" on data
739  *  allocated in a mem chunk. ("g_free" will most likely cause a seg
740  *  fault...somewhere).
741  *
742  * Oh yeah, GMemChunk is an opaque data type. (You don't really
743  *  want to know what's going on inside do you?)
744  */
745
746 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
747  *  is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
748  *  atom. (They are also useful for lists which use MemChunk to allocate
749  *  memory but are also part of the MemChunk implementation).
750  * ALLOC_AND_FREE MemChunk's can allocate and free memory.
751  */
752
753 #define G_ALLOC_ONLY      1
754 #define G_ALLOC_AND_FREE  2
755
756 GMemChunk* g_mem_chunk_new     (gchar     *name,
757                                 gint       atom_size,
758                                 gulong     area_size,
759                                 gint       type);
760 void       g_mem_chunk_destroy (GMemChunk *mem_chunk);
761 gpointer   g_mem_chunk_alloc   (GMemChunk *mem_chunk);
762 void       g_mem_chunk_free    (GMemChunk *mem_chunk,
763                                 gpointer   mem);
764 void       g_mem_chunk_clean   (GMemChunk *mem_chunk);
765 void       g_mem_chunk_reset   (GMemChunk *mem_chunk);
766 void       g_mem_chunk_print   (GMemChunk *mem_chunk);
767 void       g_mem_chunk_info    (void);
768
769 /* Ah yes...we have a "g_blow_chunks" function.
770  * "g_blow_chunks" simply compresses all the chunks. This operation
771  *  consists of freeing every memory area that should be freed (but
772  *  which we haven't gotten around to doing yet). And, no,
773  *  "g_blow_chunks" doesn't follow the naming scheme, but it is a
774  *  much better name than "g_mem_chunk_clean_all" or something
775  *  similar.
776  */
777 void g_blow_chunks (void);
778
779
780 /* Timer
781  */
782 GTimer* g_timer_new     (void);
783 void    g_timer_destroy (GTimer  *timer);
784 void    g_timer_start   (GTimer  *timer);
785 void    g_timer_stop    (GTimer  *timer);
786 void    g_timer_reset   (GTimer  *timer);
787 gdouble g_timer_elapsed (GTimer  *timer,
788                          gulong  *microseconds);
789
790
791 /* Output
792  */
793 void g_error   (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
794 void g_warning (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
795 void g_message (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
796 void g_print   (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
797
798 /* Utility functions
799  */
800 #define G_STR_DELIMITERS     "_-|> <."
801 void    g_strdelimit            (gchar       *string,
802                                  const gchar *delimiters,
803                                  gchar        new_delimiter);
804 gchar*  g_strdup                (const gchar *str);
805 gchar*  g_strconcat             (const gchar *string1,
806                                  ...); /* NULL terminated */
807 gdouble g_strtod                (const gchar *nptr,
808                                  gchar      **endptr);
809 gchar*  g_strerror              (gint         errnum);
810 gchar*  g_strsignal             (gint         signum);
811 gint    g_strcasecmp            (const gchar *s1,
812                                  const gchar *s2);
813 void    g_strdown               (gchar       *string);
814 void    g_strup                 (gchar       *string);
815 void    g_strreverse            (gchar       *string);
816 guint   g_parse_debug_string    (const gchar *string, 
817                                  GDebugKey   *keys, 
818                                  guint        nkeys);
819 gint    g_snprintf              (gchar       *string,
820                                  gulong       n,
821                                  gchar const *format,
822                                  ...) G_GNUC_PRINTF (3, 4);
823
824 /* We make the assumption that if memmove isn't available, then
825  * bcopy will do the job. This isn't safe everywhere. (bcopy can't
826  * necessarily handle overlapping copies) */
827 #ifdef HAVE_MEMMOVE
828 #define g_memmove memmove
829 #else 
830 #define g_memmove(a,b,c) bcopy(b,a,c)
831 #endif
832
833 /* Errors
834  */
835 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
836 GWarningFunc g_set_warning_handler (GWarningFunc func);
837 GPrintFunc   g_set_message_handler (GPrintFunc func);
838 GPrintFunc   g_set_print_handler   (GPrintFunc func);
839
840 void g_debug          (const gchar *progname);
841 void g_attach_process (const gchar *progname,
842                        gint         query);
843 void g_stack_trace    (const gchar *progname,
844                        gint         query);
845
846
847 /* String Chunks
848  */
849 GStringChunk* g_string_chunk_new           (gint size);
850 void          g_string_chunk_free          (GStringChunk *chunk);
851 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
852                                             const gchar  *string);
853 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
854                                             const gchar  *string);
855
856 /* Strings
857  */
858 GString* g_string_new       (const gchar *init);
859 GString* g_string_sized_new (guint        dfl_size);
860 void     g_string_free      (GString     *string,
861                              gint         free_segment);
862 GString* g_string_assign    (GString     *lval,
863                              const gchar *rval);
864 GString* g_string_truncate  (GString     *string,
865                              gint         len);
866 GString* g_string_append    (GString     *string,
867                              const gchar *val);
868 GString* g_string_append_c  (GString     *string,
869                              gchar        c);
870 GString* g_string_prepend   (GString     *string,
871                              const gchar *val);
872 GString* g_string_prepend_c (GString     *string,
873                              gchar        c);
874 GString* g_string_insert    (GString     *string, 
875                              gint         pos, 
876                              const gchar *val);
877 GString* g_string_insert_c  (GString     *string, 
878                              gint         pos, 
879                              gchar        c);
880 GString* g_string_erase     (GString     *string, 
881                              gint         pos, 
882                              gint         len);
883 GString* g_string_down      (GString     *string);
884 GString* g_string_up        (GString     *string);
885 void     g_string_sprintf   (GString     *string,
886                              const gchar *format,
887                              ...) G_GNUC_PRINTF (2, 3);
888 void     g_string_sprintfa  (GString     *string,
889                              const gchar *format,
890                              ...) G_GNUC_PRINTF (2, 3);
891
892 /* Resizable arrays
893  */
894 #define g_array_length(array,type) \
895      (((array)->len)/sizeof(type))
896 #define g_array_append_val(array,type,val) \
897      g_rarray_append (array, (gpointer) &val, sizeof (type))
898 #define g_array_append_vals(array,type,vals,nvals) \
899      g_rarray_append (array, (gpointer) vals, sizeof (type) * nvals)
900 #define g_array_prepend_val(array,type,val) \
901      g_rarray_prepend (array, (gpointer) &val, sizeof (type))
902 #define g_array_prepend_vals(array,type,vals,nvals) \
903      g_rarray_prepend (array, (gpointer) vals, sizeof (type) * nvals)
904 #define g_array_truncate(array,type,length) \
905      g_rarray_truncate (array, length, sizeof (type))
906 #define g_array_index(array,type,index) \
907      ((type*) array->data)[index]
908
909 GArray* g_array_new       (gint      zero_terminated);
910 void    g_array_free      (GArray   *array,
911                            gint      free_segment);
912 GArray* g_rarray_append   (GArray   *array,
913                            gpointer  data,
914                            gint      size);
915 GArray* g_rarray_prepend  (GArray   *array,
916                            gpointer  data,
917                            gint      size);
918 GArray* g_rarray_truncate (GArray   *array,
919                            gint      length,
920                            gint      size);
921
922 /* Resizable pointer array.  This interface is much less complicated
923  * than the above.  Add appends appends a pointer.  Remove fills any
924  * cleared spot and shortens the array.
925  */
926
927 #define     g_ptr_array_index(array,index) (array->pdata)[index]
928
929 GPtrArray*  g_ptr_array_new                (void);
930 void        g_ptr_array_free               (GPtrArray   *array,
931                                             gboolean     free_seg);
932 void        g_ptr_array_set_size           (GPtrArray   *array,
933                                             gint         length);
934 void        g_ptr_array_remove_index       (GPtrArray   *array,
935                                             gint         index);
936 gboolean    g_ptr_array_remove             (GPtrArray   *array,
937                                             gpointer     data);
938 void        g_ptr_array_add                (GPtrArray   *array,
939                                             gpointer     data);
940
941 /* Byte arrays, an array of guint8.  Implemented as a GArray,
942  * but type-safe.
943  */
944
945 GByteArray* g_byte_array_new      (void);
946 void        g_byte_array_free     (GByteArray *array,
947                                    gint        free_segment);
948
949 GByteArray* g_byte_array_append   (GByteArray   *array,
950                                    const guint8 *data,
951                                    guint         len);
952
953 GByteArray* g_byte_array_prepend  (GByteArray   *array,
954                                    const guint8 *data,
955                                    guint         len);
956
957 GByteArray* g_byte_array_truncate (GByteArray *array,
958                                    gint        length);
959
960
961 /* Hash Functions
962  */
963 gint  g_str_equal (gconstpointer   v,
964                    gconstpointer   v2);
965 guint g_str_hash  (gconstpointer v);
966
967 gint  g_int_equal (gconstpointer v,
968                    gconstpointer v2);
969 guint g_int_hash  (gconstpointer v);
970
971 /* This "hash" function will just return the key's adress as an
972  * unsigned integer. Useful for hashing on plain adresses or
973  * simple integer values.
974  */
975 guint g_direct_hash  (gconstpointer v);
976 gint  g_direct_equal (gconstpointer v,
977                       gconstpointer v2);
978
979
980 /* Quarks (string<->id association)
981  */
982 GQuark    g_quark_try_string            (const gchar    *string);
983 GQuark    g_quark_from_static_string    (const gchar    *string);
984 GQuark    g_quark_from_string           (const gchar    *string);
985 gchar*    g_quark_to_string             (GQuark          quark);
986
987 /* Location Associated Data
988  */
989 void      g_dataset_destroy             (gconstpointer   dataset_location);
990 gpointer  g_dataset_id_get_data         (gconstpointer   dataset_location,
991                                          GQuark          key_id);
992 void      g_dataset_id_set_data_full    (gconstpointer   dataset_location,
993                                          GQuark          key_id,
994                                          gpointer        data,
995                                          GDestroyNotify  destroy_func);
996 void      g_dataset_id_set_destroy      (gconstpointer   dataset_location,
997                                          GQuark          key_id,
998                                          GDestroyNotify  destroy_func);
999
1000 #define   g_dataset_id_set_data(l,k,d)  G_STMT_START{g_dataset_id_set_data_full((l),(k),(d),NULL);}G_STMT_END
1001 #define   g_dataset_id_remove_data(l,k) G_STMT_START{g_dataset_id_set_data((l),(k),NULL);}G_STMT_END
1002 #define   g_dataset_get_data(l,k)       (g_dataset_id_get_data((l),g_quark_try_string(k)))
1003 #define   g_dataset_set_data_full(l,k,d,f) G_STMT_START{g_dataset_id_set_data_full((l),g_quark_from_string(k),(d),(f));}G_STMT_END
1004 #define   g_dataset_set_destroy(l,k,f)  G_STMT_START{g_dataset_id_set_destroy((l),g_quark_from_string(k),(f));}G_STMT_END
1005 #define   g_dataset_set_data(l,k,d)     G_STMT_START{g_dataset_set_data_full((l),(k),(d),NULL);}G_STMT_END
1006 #define   g_dataset_remove_data(l,k)    G_STMT_START{g_dataset_set_data((l),(k),NULL);}G_STMT_END
1007
1008
1009 /* GScanner: Flexible lexical scanner for general purpose.
1010  */
1011
1012 /* Character sets */
1013 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1014 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
1015 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
1016                         "\307\310\311\312\313\314\315\316\317\320"\
1017                         "\321\322\323\324\325\326"\
1018                         "\330\331\332\333\334\335\336"
1019 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
1020                         "\347\350\351\352\353\354\355\356\357\360"\
1021                         "\361\362\363\364\365\366"\
1022                         "\370\371\372\373\374\375\376\377"
1023
1024 /* Error types */
1025 typedef enum
1026 {
1027   G_ERR_UNKNOWN,
1028   G_ERR_UNEXP_EOF,
1029   G_ERR_UNEXP_EOF_IN_STRING,
1030   G_ERR_UNEXP_EOF_IN_COMMENT,
1031   G_ERR_NON_DIGIT_IN_CONST,
1032   G_ERR_DIGIT_RADIX,
1033   G_ERR_FLOAT_RADIX,
1034   G_ERR_FLOAT_MALFORMED
1035 } GErrorType;
1036
1037 /* Token types */
1038 typedef enum
1039 {
1040   G_TOKEN_EOF                   =   0,
1041   
1042   G_TOKEN_LEFT_PAREN            = '(',
1043   G_TOKEN_RIGHT_PAREN           = ')',
1044   G_TOKEN_LEFT_CURLY            = '{',
1045   G_TOKEN_RIGHT_CURLY           = '}',
1046   G_TOKEN_LEFT_BRACE            = '[',
1047   G_TOKEN_RIGHT_BRACE           = ']',
1048   G_TOKEN_EQUAL_SIGN            = '=',
1049   G_TOKEN_COMMA                 = ',',
1050   
1051   G_TOKEN_NONE                  = 256,
1052   
1053   G_TOKEN_ERROR,
1054   
1055   G_TOKEN_CHAR,
1056   G_TOKEN_BINARY,
1057   G_TOKEN_OCTAL,
1058   G_TOKEN_INT,
1059   G_TOKEN_HEX,
1060   G_TOKEN_FLOAT,
1061   G_TOKEN_STRING,
1062   
1063   G_TOKEN_SYMBOL,
1064   G_TOKEN_IDENTIFIER,
1065   G_TOKEN_IDENTIFIER_NULL,
1066   
1067   G_TOKEN_COMMENT_SINGLE,
1068   G_TOKEN_COMMENT_MULTI,
1069   G_TOKEN_LAST
1070 } GTokenType;
1071
1072 union   _GValue
1073 {
1074   gpointer      v_symbol;
1075   gchar         *v_identifier;
1076   gulong        v_binary;
1077   gulong        v_octal;
1078   gulong        v_int;
1079   gdouble       v_float;
1080   gulong        v_hex;
1081   gchar         *v_string;
1082   gchar         *v_comment;
1083   guchar        v_char;
1084   guint         v_error;
1085 };
1086
1087 struct  _GScannerConfig
1088 {
1089   /* Character sets
1090    */
1091   gchar         *cset_skip_characters;          /* default: " \t\n" */
1092   gchar         *cset_identifier_first;
1093   gchar         *cset_identifier_nth;
1094   gchar         *cpair_comment_single;          /* default: "#\n" */
1095   
1096   /* Should symbol lookup work case sensitive?
1097    */
1098   guint         case_sensitive : 1;
1099   
1100   /* Boolean values to be adjusted "on the fly"
1101    * to configure scanning behaviour.
1102    */
1103   guint         skip_comment_multi : 1;         /* C like comment */
1104   guint         skip_comment_single : 1;        /* single line comment */
1105   guint         scan_comment_multi : 1;         /* scan multi line comments? */
1106   guint         scan_identifier : 1;
1107   guint         scan_identifier_1char : 1;
1108   guint         scan_identifier_NULL : 1;
1109   guint         scan_symbols : 1;
1110   guint         scan_binary : 1;
1111   guint         scan_octal : 1;
1112   guint         scan_float : 1;
1113   guint         scan_hex : 1;                   /* `0x0ff0' */
1114   guint         scan_hex_dollar : 1;            /* `$0ff0' */
1115   guint         scan_string_sq : 1;             /* string: 'anything' */
1116   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
1117   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
1118   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
1119   guint         identifier_2_string : 1;
1120   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
1121   guint         symbol_2_token : 1;
1122 };
1123
1124 struct  _GScanner
1125 {
1126   /* unused fields */
1127   gpointer              user_data;
1128   guint                 max_parse_errors;
1129
1130   /* g_scanner_error() increments this field */
1131   guint                 parse_errors;
1132
1133   /* name of input stream, featured by the default message handler */
1134   const gchar           *input_name;
1135
1136   /* data pointer for derived structures */
1137   gpointer              derived_data;
1138
1139   /* link into the scanner configuration */
1140   GScannerConfig        *config;
1141
1142   /* fields filled in after g_scanner_get_next_token() */
1143   GTokenType            token;
1144   GValue                value;
1145   guint                 line;
1146   guint                 position;
1147
1148   /* fields filled in after g_scanner_peek_next_token() */
1149   GTokenType            next_token;
1150   GValue                next_value;
1151   guint                 next_line;
1152   guint                 next_position;
1153
1154   /* to be considered private */
1155   GHashTable            *symbol_table;
1156   const gchar           *text;
1157   guint                 text_len;
1158   gint                  input_fd;
1159   gint                  peeked_char;
1160
1161   /* handler function for _warn and _error */
1162   GScannerMsgFunc       msg_handler;
1163 };
1164
1165 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
1166 void            g_scanner_destroy               (GScanner       *scanner);
1167 void            g_scanner_input_file            (GScanner       *scanner,
1168                                                  gint           input_fd);
1169 void            g_scanner_input_text            (GScanner       *scanner,
1170                                                  const  gchar   *text,
1171                                                  guint          text_len);
1172 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
1173 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
1174 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
1175 GValue          g_scanner_cur_value             (GScanner       *scanner);
1176 guint           g_scanner_cur_line              (GScanner       *scanner);
1177 guint           g_scanner_cur_position          (GScanner       *scanner);
1178 gboolean        g_scanner_eof                   (GScanner       *scanner);
1179 void            g_scanner_add_symbol            (GScanner       *scanner,
1180                                                  const gchar    *symbol,
1181                                                  gpointer       value);
1182 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
1183                                                  const gchar    *symbol);
1184 void            g_scanner_foreach_symbol        (GScanner       *scanner,
1185                                                  GHFunc          func,
1186                                                  gpointer        func_data);
1187 void            g_scanner_remove_symbol         (GScanner       *scanner,
1188                                                  const gchar    *symbol);
1189 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
1190 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
1191 void            g_scanner_unexp_token           (GScanner       *scanner,
1192                                                  GTokenType     expected_token,
1193                                                  const gchar    *identifier_spec,
1194                                                  const gchar    *symbol_spec,
1195                                                  const gchar    *symbol_name,
1196                                                  const gchar    *message,
1197                                                  gint            is_error);
1198 void            g_scanner_error                 (GScanner       *scanner,
1199                                                  const gchar    *format,
1200                                                  ...) G_GNUC_PRINTF (2,3);
1201 void            g_scanner_warn                  (GScanner       *scanner,
1202                                                  const gchar    *format,
1203                                                  ...) G_GNUC_PRINTF (2,3);
1204 gint            g_scanner_stat_mode             (const gchar    *filename);
1205
1206
1207 /* Completion */
1208
1209 typedef gchar* (*GCompletionFunc)(gpointer);
1210
1211 typedef struct _GCompletion GCompletion;
1212
1213 struct _GCompletion {
1214         GList* items;
1215         GCompletionFunc func;
1216
1217         gchar* prefix;
1218         GList* cache;
1219
1220 };
1221
1222 GCompletion* g_completion_new          (GCompletionFunc func);
1223 void         g_completion_add_items    (GCompletion* cmp, 
1224                                         GList* items);
1225 void         g_completion_remove_items (GCompletion* cmp, 
1226                                         GList* items);
1227 void         g_completion_clear_items  (GCompletion* cmp);
1228 GList*       g_completion_complete     (GCompletion* cmp, 
1229                                         gchar* prefix,
1230                                         gchar** new_prefix);
1231 void         g_completion_free         (GCompletion* cmp);
1232
1233 /* GRelation: Indexed Relations.  Imagine a really simple table in a
1234  * database.  Relations are not ordered.  This data type is meant for
1235  * maintaining a N-way mapping.
1236  *
1237  * g_relation_new() creates a relation with FIELDS fields
1238  *
1239  * g_relation_destroy() frees all resources
1240  * g_tuples_destroy() frees the result of g_relation_select()
1241  *
1242  * g_relation_index() indexes relation FIELD with the provided
1243  *   equality and hash functions.  this must be done before any
1244  *   calls to insert are made.
1245  *
1246  * g_relation_insert() inserts a new tuple.  you are expected to
1247  *   provide the right number of fields.
1248  *
1249  * g_relation_delete() deletes all relations with KEY in FIELD
1250  * g_relation_select() returns ...
1251  * g_relation_count() counts ...
1252  */
1253
1254 GRelation* g_relation_new     (gint         fields);
1255 void       g_relation_destroy (GRelation   *relation);
1256 void       g_relation_index   (GRelation   *relation,
1257                                gint         field,
1258                                GHashFunc    hash_func,
1259                                GCompareFunc key_compare_func);
1260 void       g_relation_insert  (GRelation   *relation,
1261                                ...);
1262 gint       g_relation_delete  (GRelation   *relation,
1263                                gconstpointer  key,
1264                                gint         field);
1265 GTuples*   g_relation_select  (GRelation   *relation,
1266                                gconstpointer  key,
1267                                gint         field);
1268 gint       g_relation_count   (GRelation   *relation,
1269                                gconstpointer  key,
1270                                gint         field);
1271 gboolean   g_relation_exists  (GRelation   *relation,
1272                                ...);
1273 void       g_relation_print   (GRelation   *relation);
1274
1275 void       g_tuples_destroy   (GTuples     *tuples);
1276 gpointer   g_tuples_index     (GTuples     *tuples,
1277                                gint         index,
1278                                gint         field);
1279
1280
1281 /* Glib version.
1282  */
1283 extern const guint glib_major_version;
1284 extern const guint glib_minor_version;
1285 extern const guint glib_micro_version;
1286
1287 #ifdef __cplusplus
1288 }
1289 #endif /* __cplusplus */
1290
1291
1292 #endif /* __G_LIB_H__ */