Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtmail / dtmail / Node.C
1 /*
2  *+SNOTICE
3  *
4  *      $XConsortium: Node.C /main/4 1996/04/21 19:42:41 drk $
5  *
6  *      RESTRICTED CONFIDENTIAL INFORMATION:
7  *      
8  *      The information in this document is subject to special
9  *      restrictions in a confidential disclosure agreement between
10  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
11  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
12  *      Sun's specific written approval.  This document and all copies
13  *      and derivative works thereof must be returned or destroyed at
14  *      Sun's request.
15  *
16  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
17  *
18  *+ENOTICE
19  */
20
21 #include <stdio.h>
22
23 #include        "Node.h"
24
25 // In the design, we had abstracted out the DOMF related activities
26 // (insertion in lookup table, creation of the objref corresponding to
27 // servant...) into <>Impl classes.
28 // The <>Servant classes derive from the <>Impl classes.
29 // Note how, in the constructor of the NodeServant class, we call the 
30 // constructor of the parent NodeImpl class passing in "this".
31 // The NodeImpl constructor uses "this" to insert into the lookup table...
32
33
34 Node::Node()
35 {
36
37     my_message_handle    = NULL;
38     my_message_header    = NULL;
39
40     homep = DTM_FALSE;
41     deleted_p = DTM_FALSE;
42     my_previous_node = NULL;
43     my_next_node  = NULL;
44 }
45
46 Node::Node(
47     DtMailMessageHandle msg_num,
48     char*     hdr
49 )
50 {
51     my_message_handle    = msg_num;
52     my_message_header    = hdr;
53
54     homep = DTM_FALSE;
55     deleted_p = DTM_FALSE;
56     my_previous_node = NULL;
57     my_next_node  = NULL;
58 }
59
60 Node::~Node() {}
61
62 void 
63 Node::set_homep(
64 )
65 {
66     homep = DTM_TRUE;
67 }
68
69 boolean
70 Node::is_home(
71 )
72 {
73     return(homep);
74 }
75
76 // Starting with the current node "this", traverse nodes until
77 // home node is reached.
78
79 Node*
80 Node::get_home(
81 )
82 {
83     Node* a_node;
84     unsigned char  is_home_p;
85
86
87     a_node = this;
88
89     is_home_p = a_node->is_home();
90
91     if (is_home_p) {
92         return (this);
93     }
94     else {
95         Node* n;
96         
97         n = a_node->next();
98         n->get_home();
99     }
100 }
101
102 void
103 Node::set_message_handle(
104     DtMailMessageHandle a_hndl
105 )
106 {
107     my_message_handle = a_hndl;
108 }
109
110
111 DtMailMessageHandle
112 Node::get_message_handle()
113 {
114     return(my_message_handle);
115 }
116
117 void
118 Node::set_message_header(
119     char* hdr
120 )
121 {
122     my_message_header = hdr;
123 }
124
125 char* 
126 Node::get_message_header()
127 {
128     return(my_message_header);
129 }
130
131 Node* 
132 Node::next(
133 )
134 {
135
136     return(my_next_node);
137
138 }
139
140 // Don't attempt duplicating a nil objref!
141
142 Node* 
143 Node::prev(
144 )
145 {
146
147     return(my_previous_node);
148
149 }
150
151 // Don't attempt duplicating a nil objref!
152
153 void
154 Node::set_previous_node(
155         Node* a_node
156 )
157 {
158     my_previous_node = a_node;
159
160 }
161
162 // Don't attempt duplicating a nil objref!
163
164 void
165 Node::set_next_node(
166         Node* a_node
167 )
168 {
169     my_next_node = a_node;
170 }
171
172 // append anyNode to self
173
174 void 
175 Node::append(
176         Node* anyNode
177 )
178 {
179
180     Node* tmpNext;
181     Node* tmpSelf;
182     Node* inNode;
183
184     if (anyNode == NULL) {
185         printf("Cannot append NIL node!");
186         return;
187     }
188
189     inNode = anyNode;
190
191     tmpSelf = this;
192
193     if (my_next_node)
194       {
195           tmpNext = my_next_node;
196           my_next_node = inNode;
197           inNode->set_previous_node(tmpSelf);
198           inNode->set_next_node(my_next_node);
199           tmpNext->set_previous_node(inNode);
200       }
201     else
202       {
203           my_next_node = inNode;
204           my_previous_node      = inNode;
205           inNode->set_previous_node(tmpSelf);
206           inNode->set_next_node(tmpSelf);
207       }
208 }
209
210 // prepend anyNode to self
211
212 void
213 Node::prepend(
214         Node* anyNode
215 )
216 {
217     
218     Node* tmpPrev;
219     Node* inNode;
220     Node* tmpSelf;
221
222     if (anyNode == NULL) {
223         printf("Cannot prepend NIL node!");
224         return;
225     }
226
227     inNode  = anyNode;
228     tmpSelf = this;
229
230     if (my_previous_node)
231       {
232           tmpPrev = my_previous_node;
233           my_previous_node = inNode;
234           inNode->set_next_node(tmpSelf);
235           inNode->set_previous_node(tmpPrev);
236           tmpPrev->set_next_node(inNode);
237       }
238     else
239       {
240           my_next_node = inNode;
241           my_previous_node = inNode;
242           inNode->set_previous_node(tmpSelf);
243           inNode->set_next_node(tmpSelf);
244       }
245
246 }
247
248 // Good etiquette requires that clients remove() a node
249 // before destroy()-ing it.
250     
251 void 
252 Node::remove(
253 )
254 {
255
256     my_previous_node->set_next_node(my_next_node);
257
258     my_next_node->set_previous_node(my_previous_node);
259
260 }
261
262
263 void
264 Node::set_number(int i)
265 {
266     bogus_number = i;
267
268 }
269
270 int
271 Node::get_number()
272 {
273     return(bogus_number);
274 }
275
276
277
278