5 * Copyright (C) 2010 Christopher Li.
16 #define AST_TYPE_NODE (ast_get_type ())
17 #define AST_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AST_TYPE_NODE, AstNode))
18 #define AST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AST_TYPE_NODE, AstNodeClass))
19 #define AST_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AST_TYPE_NODE))
20 #define AST_IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AST_TYPE_NODE))
21 #define AST_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AST_TYPE_NODE, AstNodeClass))
31 typedef struct AstNode AstNode
;
32 typedef struct AstNodeClass AstNodeClass
;
36 /* AstNode: this structure contains everything we need for our
37 * model implementation. You can add extra fields to
38 * this structure, e.g. hashtables to quickly lookup
39 * rows or whatever else you might need, but it is
40 * crucial that 'parent' is the first member of the
45 GObject base
; /* this MUST be the first member */
50 void (*inspect
)(struct AstNode
* node
);
58 /* AstNodeClass: more boilerplate GObject stuff */
62 GObjectClass base_class
;
66 GType
ast_get_type(void);
67 AstNode
* ast_new(AstNode
*parent
, int index
, const char *prefix
, void *ptr
, void (*expand
)(AstNode
*));
71 void ast_append_child(AstNode
*parent
, const char *text
,
72 void *ptr
, void (*inspect
)(AstNode
*))
75 AstNode
*child
= ast_new(parent
, parent
->childnodes
->len
,
77 g_array_append_val(parent
->childnodes
, child
);
82 void ast_append_attribute(AstNode
*parent
, const char *text
)
84 AstNode
*child
= ast_new(parent
, parent
->childnodes
->len
, text
, NULL
, NULL
);
85 g_array_append_val(parent
->childnodes
, child
);