epoc32/include/stdapis/glib-2.0/glib/gnode.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 0 061f57f2323e
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
/* GLIB - Library of useful routines for C programming
williamr@2
     2
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
williamr@2
     3
 * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
williamr@2
     4
 *
williamr@2
     5
 * This library is free software; you can redistribute it and/or
williamr@2
     6
 * modify it under the terms of the GNU Lesser General Public
williamr@2
     7
 * License as published by the Free Software Foundation; either
williamr@2
     8
 * version 2 of the License, or (at your option) any later version.
williamr@2
     9
 *
williamr@2
    10
 * This library is distributed in the hope that it will be useful,
williamr@2
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
williamr@2
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
williamr@2
    13
 * Lesser General Public License for more details.
williamr@2
    14
 *
williamr@2
    15
 * You should have received a copy of the GNU Lesser General Public
williamr@2
    16
 * License along with this library; if not, write to the
williamr@2
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
williamr@2
    18
 * Boston, MA 02111-1307, USA.
williamr@2
    19
 */
williamr@2
    20
williamr@2
    21
/*
williamr@2
    22
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
williamr@2
    23
 * file for a list of people on the GLib Team.  See the ChangeLog
williamr@2
    24
 * files for a list of changes.  These files are distributed with
williamr@2
    25
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
williamr@2
    26
 */
williamr@2
    27
williamr@2
    28
#ifndef __G_NODE_H__
williamr@2
    29
#define __G_NODE_H__
williamr@2
    30
williamr@2
    31
#include <_ansi.h>
williamr@2
    32
#include <glib/gmem.h>
williamr@2
    33
williamr@2
    34
G_BEGIN_DECLS
williamr@2
    35
williamr@2
    36
typedef struct _GNode		GNode;
williamr@2
    37
williamr@2
    38
/* Tree traverse flags */
williamr@2
    39
typedef enum
williamr@2
    40
{
williamr@2
    41
  G_TRAVERSE_LEAVES     = 1 << 0,
williamr@2
    42
  G_TRAVERSE_NON_LEAVES = 1 << 1,
williamr@2
    43
  G_TRAVERSE_ALL        = G_TRAVERSE_LEAVES | G_TRAVERSE_NON_LEAVES,
williamr@2
    44
  G_TRAVERSE_MASK       = 0x03,
williamr@2
    45
  G_TRAVERSE_LEAFS      = G_TRAVERSE_LEAVES,
williamr@2
    46
  G_TRAVERSE_NON_LEAFS  = G_TRAVERSE_NON_LEAVES
williamr@2
    47
} GTraverseFlags;
williamr@2
    48
williamr@2
    49
/* Tree traverse orders */
williamr@2
    50
typedef enum
williamr@2
    51
{
williamr@2
    52
  G_IN_ORDER,
williamr@2
    53
  G_PRE_ORDER,
williamr@2
    54
  G_POST_ORDER,
williamr@2
    55
  G_LEVEL_ORDER
williamr@2
    56
} GTraverseType;
williamr@2
    57
williamr@2
    58
typedef gboolean	(*GNodeTraverseFunc)	(GNode	       *node,
williamr@2
    59
						 gpointer	data);
williamr@2
    60
typedef void		(*GNodeForeachFunc)	(GNode	       *node,
williamr@2
    61
						 gpointer	data);
williamr@2
    62
typedef gpointer	(*GCopyFunc)            (gconstpointer  src,
williamr@2
    63
                                                 gpointer       data);
williamr@2
    64
williamr@2
    65
/* N-way tree implementation
williamr@2
    66
 */
williamr@2
    67
struct _GNode
williamr@2
    68
{
williamr@2
    69
  gpointer data;
williamr@2
    70
  GNode	  *next;
williamr@2
    71
  GNode	  *prev;
williamr@2
    72
  GNode	  *parent;
williamr@2
    73
  GNode	  *children;
williamr@2
    74
};
williamr@2
    75
williamr@2
    76
#define	 G_NODE_IS_ROOT(node)	(((GNode*) (node))->parent == NULL && \
williamr@2
    77
				 ((GNode*) (node))->prev == NULL && \
williamr@2
    78
				 ((GNode*) (node))->next == NULL)
williamr@2
    79
#define	 G_NODE_IS_LEAF(node)	(((GNode*) (node))->children == NULL)
williamr@2
    80
williamr@2
    81
IMPORT_C GNode*	 g_node_new		(gpointer	   data);
williamr@2
    82
IMPORT_C void	 g_node_destroy		(GNode		  *root);
williamr@2
    83
IMPORT_C void	 g_node_unlink		(GNode		  *node);
williamr@2
    84
IMPORT_C GNode*   g_node_copy_deep       (GNode            *node,
williamr@2
    85
				 GCopyFunc         copy_func,
williamr@2
    86
				 gpointer          data);
williamr@2
    87
IMPORT_C GNode*   g_node_copy            (GNode            *node);
williamr@2
    88
IMPORT_C GNode*	 g_node_insert		(GNode		  *parent,
williamr@2
    89
				 gint		   position,
williamr@2
    90
				 GNode		  *node);
williamr@2
    91
IMPORT_C GNode*	 g_node_insert_before	(GNode		  *parent,
williamr@2
    92
				 GNode		  *sibling,
williamr@2
    93
				 GNode		  *node);
williamr@2
    94
IMPORT_C GNode*   g_node_insert_after    (GNode            *parent,
williamr@2
    95
				 GNode            *sibling,
williamr@2
    96
				 GNode            *node); 
williamr@2
    97
IMPORT_C GNode*	 g_node_prepend		(GNode		  *parent,
williamr@2
    98
				 GNode		  *node);
williamr@2
    99
IMPORT_C guint	 g_node_n_nodes		(GNode		  *root,
williamr@2
   100
				 GTraverseFlags	   flags);
williamr@2
   101
IMPORT_C GNode*	 g_node_get_root	(GNode		  *node);
williamr@2
   102
IMPORT_C gboolean g_node_is_ancestor	(GNode		  *node,
williamr@2
   103
				 GNode		  *descendant);
williamr@2
   104
IMPORT_C guint	 g_node_depth		(GNode		  *node);
williamr@2
   105
IMPORT_C GNode*	 g_node_find		(GNode		  *root,
williamr@2
   106
				 GTraverseType	   order,
williamr@2
   107
				 GTraverseFlags	   flags,
williamr@2
   108
				 gpointer	   data);
williamr@2
   109
williamr@2
   110
/* convenience macros */
williamr@2
   111
#define g_node_append(parent, node)				\
williamr@2
   112
     g_node_insert_before ((parent), NULL, (node))
williamr@2
   113
#define	g_node_insert_data(parent, position, data)		\
williamr@2
   114
     g_node_insert ((parent), (position), g_node_new (data))
williamr@2
   115
#define	g_node_insert_data_before(parent, sibling, data)	\
williamr@2
   116
     g_node_insert_before ((parent), (sibling), g_node_new (data))
williamr@2
   117
#define	g_node_prepend_data(parent, data)			\
williamr@2
   118
     g_node_prepend ((parent), g_node_new (data))
williamr@2
   119
#define	g_node_append_data(parent, data)			\
williamr@2
   120
     g_node_insert_before ((parent), NULL, g_node_new (data))
williamr@2
   121
williamr@2
   122
/* traversal function, assumes that `node' is root
williamr@2
   123
 * (only traverses `node' and its subtree).
williamr@2
   124
 * this function is just a high level interface to
williamr@2
   125
 * low level traversal functions, optimized for speed.
williamr@2
   126
 */
williamr@2
   127
IMPORT_C void	 g_node_traverse	(GNode		  *root,
williamr@2
   128
				 GTraverseType	   order,
williamr@2
   129
				 GTraverseFlags	   flags,
williamr@2
   130
				 gint		   max_depth,
williamr@2
   131
				 GNodeTraverseFunc func,
williamr@2
   132
				 gpointer	   data);
williamr@2
   133
williamr@2
   134
/* return the maximum tree height starting with `node', this is an expensive
williamr@2
   135
 * operation, since we need to visit all nodes. this could be shortened by
williamr@2
   136
 * adding `guint height' to struct _GNode, but then again, this is not very
williamr@2
   137
 * often needed, and would make g_node_insert() more time consuming.
williamr@2
   138
 */
williamr@2
   139
IMPORT_C guint	 g_node_max_height	 (GNode *root);
williamr@2
   140
williamr@2
   141
IMPORT_C void	 g_node_children_foreach (GNode		  *node,
williamr@2
   142
				  GTraverseFlags   flags,
williamr@2
   143
				  GNodeForeachFunc func,
williamr@2
   144
				  gpointer	   data);
williamr@2
   145
IMPORT_C void	 g_node_reverse_children (GNode		  *node);
williamr@2
   146
IMPORT_C guint	 g_node_n_children	 (GNode		  *node);
williamr@2
   147
IMPORT_C GNode*	 g_node_nth_child	 (GNode		  *node,
williamr@2
   148
				  guint		   n);
williamr@2
   149
IMPORT_C GNode*	 g_node_last_child	 (GNode		  *node);
williamr@2
   150
IMPORT_C GNode*	 g_node_find_child	 (GNode		  *node,
williamr@2
   151
				  GTraverseFlags   flags,
williamr@2
   152
				  gpointer	   data);
williamr@2
   153
IMPORT_C gint	 g_node_child_position	 (GNode		  *node,
williamr@2
   154
				  GNode		  *child);
williamr@2
   155
IMPORT_C gint	 g_node_child_index	 (GNode		  *node,
williamr@2
   156
				  gpointer	   data);
williamr@2
   157
williamr@2
   158
IMPORT_C GNode*	 g_node_first_sibling	 (GNode		  *node);
williamr@2
   159
IMPORT_C GNode*	 g_node_last_sibling	 (GNode		  *node);
williamr@2
   160
williamr@2
   161
#define	 g_node_prev_sibling(node)	((node) ? \
williamr@2
   162
					 ((GNode*) (node))->prev : NULL)
williamr@2
   163
#define	 g_node_next_sibling(node)	((node) ? \
williamr@2
   164
					 ((GNode*) (node))->next : NULL)
williamr@2
   165
#define	 g_node_first_child(node)	((node) ? \
williamr@2
   166
					 ((GNode*) (node))->children : NULL)
williamr@2
   167
williamr@2
   168
#ifndef G_DISABLE_DEPRECATED
williamr@2
   169
IMPORT_C void     g_node_push_allocator  (gpointer          dummy);
williamr@2
   170
IMPORT_C void     g_node_pop_allocator   (void);
williamr@2
   171
#endif
williamr@2
   172
G_END_DECLS
williamr@2
   173
williamr@2
   174
#endif /* __G_NODE_H__ */