1
/****************************************************************************
3
GLUI User Interface Toolkit
4
---------------------------
6
glui_node.cpp - linked-list tree structure
9
--------------------------------------------------
11
Copyright (c) 1998 Paul Rademacher
13
This program is freely distributable without licensing fees and is
14
provided without guarantee or warrantee expressed or implied. This
15
program is -not- in the public domain.
17
*****************************************************************************/
23
/********************************************* GLUI_Node::first() *******/
24
/* Returns first sibling in 'this' node's sibling list */
26
GLUI_Node *GLUI_Node::first_sibling( void )
28
if ( parent_node == NULL )
29
return this; /* root node has no siblings */
31
return parent_node->child_head;
35
/******************************************** GLUI_Node::next() ********/
36
/* Returns next sibling in 'this' node's sibling list */
38
GLUI_Node *GLUI_Node::next( void )
44
/******************************************** GLUI_Node::prev() ********/
45
/* Returns prev sibling in 'this' node's sibling list */
47
GLUI_Node *GLUI_Node::prev( void )
53
/********************************************* GLUI_Node::last() *******/
54
/* Returns last sibling in 'this' node's sibling list */
56
GLUI_Node *GLUI_Node::last_sibling( void )
58
if ( parent_node == NULL )
59
return this; /* root node has no siblings */
61
return parent_node->child_tail;
65
/*************************** GLUI_Node::link_this_to_parent_last() *******/
66
/* Links as last child of parent */
68
void GLUI_Node::link_this_to_parent_last( GLUI_Node *new_parent )
70
if ( new_parent->child_tail == NULL ) { /* parent has no children */
71
new_parent->child_head = this;
72
new_parent->child_tail = this;
73
this->parent_node = new_parent;
74
this->parent_node = new_parent;
76
else { /* parent has children */
77
new_parent->child_tail->next_sibling = this;
78
this->prev_sibling = new_parent->child_tail;
79
new_parent->child_tail = this;
80
this->parent_node = new_parent;
85
/*************************** GLUI_Node::link_this_to_parent_first() *******/
86
/* Links as first child of parent */
88
void GLUI_Node::link_this_to_parent_first( GLUI_Node *new_parent )
90
if ( new_parent->child_head == NULL ) { /* parent has no children */
91
new_parent->child_head = this;
92
new_parent->child_tail = this;
93
this->parent_node = new_parent;
95
else { /* parent has children */
96
new_parent->child_head->prev_sibling = this;
97
this->next_sibling = new_parent->child_head;
98
new_parent->child_head = this;
99
this->parent_node = new_parent;
103
/**************************** GLUI_Node::link_this_to_sibling_next() *****/
105
void GLUI_Node::link_this_to_sibling_next( GLUI_Node *sibling )
107
if ( sibling->next_sibling == NULL ) { /* node has no next sibling */
108
sibling->next_sibling = this;
109
this->prev_sibling = sibling;
111
/* This was the parent's last child, so update that as well */
112
if ( sibling->parent_node != NULL ) {
113
sibling->parent_node->child_tail = this;
116
else { /* node already has a next sibling */
117
sibling->next_sibling->prev_sibling = this;
118
this->next_sibling = sibling->next_sibling;
119
sibling->next_sibling = this;
120
this->prev_sibling = sibling;
123
this->parent_node = sibling->parent_node;
127
/**************************** GLUI_Node::link_this_to_sibling_prev() *****/
129
void GLUI_Node::link_this_to_sibling_prev( GLUI_Node *sibling )
131
if ( sibling->prev_sibling == NULL ) { /* node has no prev sibling */
132
sibling->prev_sibling = this;
133
this->next_sibling = sibling;
135
/* This was the parent's first child, so update that as well */
136
if ( sibling->parent_node != NULL ) {
137
sibling->parent_node->child_head = this;
140
else { /* node already has a prev sibling */
141
sibling->prev_sibling->next_sibling = this;
142
this->prev_sibling = sibling->prev_sibling;
143
sibling->prev_sibling = this;
144
this->next_sibling = sibling;
147
this->parent_node = sibling->parent_node;
150
/**************************************** GLUI_Node::unlink() **************/
152
void GLUI_Node::unlink( void )
154
/* Unlink from prev sibling */
155
if ( this->prev_sibling != NULL ) {
156
this->prev_sibling->next_sibling = this->next_sibling;
158
else { /* No prev sibling: this was parent's first child */
159
this->parent_node->child_head = this->next_sibling;
162
/* Unlink from next sibling */
163
if ( this->next_sibling != NULL ) {
164
this->next_sibling->prev_sibling = this->prev_sibling;
166
else { /* No next sibling: this was parent's last child */
167
this->parent_node->child_tail = this->prev_sibling;
170
this->parent_node = NULL;
171
this->next_sibling = NULL;
172
this->prev_sibling = NULL;
173
this->child_head = NULL;
174
this->child_tail = NULL;