2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: dl_list.cc /main/5 1996/06/11 17:24:12 cde-hal $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "object/dl_list.h"
53 dl_list::dl_list(c_code_t c_cd) : composite(c_cd)
58 set_mode(SWAP_ALLOWED, false);
61 dl_list::dl_list(const dl_list& x) : composite(x)
63 throw(stringException("dl_list(const dl_list&) not done yet"));
69 MESSAGE(cerr, "in ~dl_list()");
70 debug(cerr, v_num_indices);
76 void dl_list::init_data_member(c_index_handlerPtr* index_arrray,
80 v_indices = index_arrray;
81 v_num_indices = iptrs;
83 set_mode(HEALTH, true);
86 set_mode(UPDATE, true);
91 //Boolean dl_list::value_LS(root& x, Boolean safe) const
93 // if ( safe == true &&
94 // ( my_oid().ccode() != DL_LIST_CODE ||
95 // x.my_oid().ccode() != DL_LIST_CODE
100 // dl_list &y = *(dl_list*)&x;
105 ///************************************************/
106 //// Note: the components are indexed from 1 to sz
107 ///************************************************/
109 // for ( int i=1; i<=sz; i++ ) {
111 // handler* rootPtr1 = get_component(i);
112 // handler* rootPtr2 = y.get_component(i);
114 // if ( (*rootPtr1) -> value_LS( *rootPtr2 ) == true ) {
118 // if ( (*rootPtr1) -> value_EQ( *rootPtr2 ) == false ) {
126 //Boolean dl_list::value_EQ(root& x, Boolean safe) const
128 // if ( safe == true &&
129 // ( my_oid().ccode() != DL_LIST_CODE ||
130 // x.my_oid().ccode() != DL_LIST_CODE
135 // dl_list &y = *(dl_list*)&x;
140 ///************************************************/
141 //// Note: the components are index from 1 to sz
142 ///************************************************/
144 // for ( int i=1; i<=sz; i++ ) {
146 // handler* rootPtr1 = get_component(i);
147 // handler* rootPtr2 = y.get_component(i);
149 // if ( (*rootPtr1) -> value_EQ( *rootPtr2 ) == false ) {
158 handler* dl_list::get_component(int index)
163 const oid_t* cell_ptr = &v_dl_list_head;
165 for ( int i=1; i<index-1; i++ ) {
167 if ( cell_ptr == 0 || cell_ptr -> icode() == 0 )
168 throw(stringException("broken chain"));
170 dl_list_cell_handler cell(*cell_ptr, storage_ptr);
173 cell_ptr = &cell -> get_forward_ptr();
177 return new handler (*cell_ptr, storage_ptr);
180 oid_list_handler* dl_list::get_locs(handler& query, int index)
182 if ( !INRANGE(index, 0, v_num_indices-1) )
183 throw(boundaryException(0, v_num_indices-1, index));
185 if ( v_indices[index] == 0 )
186 throw(stringException("NULL index handler ptr"));
188 return (*v_indices[index]) -> get_loc_list(query);
191 oid_t dl_list::first_cell_oid() const
193 return v_dl_list_head;
196 oid_t dl_list::last_cell_oid() const
198 return v_dl_list_tail;
203 dl_list::insert_before(dl_list_cell_handler& new_cell,
204 dl_list_cell_handler& old_cell
207 oid_t prev_oid(old_cell -> get_backward_ptr());
209 new_cell -> set_forward_ptr(old_cell.its_oid());
210 old_cell -> set_backward_ptr(new_cell.its_oid());
212 if ( prev_oid.icode() != 0 ) {
214 // NOTE: non-new-list-head case
215 dl_list_cell_handler prev_cell_hd(prev_oid, storage_ptr);
217 new_cell -> set_backward_ptr(prev_cell_hd.its_oid());
218 prev_cell_hd -> set_forward_ptr(new_cell.its_oid());
222 // NOTE: new-list-head case
223 v_dl_list_head.become(new_cell.its_oid());
228 set_mode(HEALTH, true);
230 insert_to_indices(new_cell);
236 dl_list::insert_after(dl_list_cell_handler& new_cell,
237 dl_list_cell_handler& old_cell
240 oid_t next_oid(old_cell -> get_forward_ptr());
242 new_cell -> set_backward_ptr(old_cell.its_oid());
243 old_cell -> set_forward_ptr(new_cell.its_oid());
245 if ( next_oid.icode() != 0 ) {
247 // NOTE: non-new-list-tail case
248 dl_list_cell_handler next_cell_hd(next_oid, storage_ptr);
250 new_cell -> set_forward_ptr(next_cell_hd.its_oid());
251 next_cell_hd -> set_backward_ptr(new_cell.its_oid());
255 // NOTE: new-list-tail case
256 new_cell -> get_forward_ptr().become(ground);
257 v_dl_list_tail.become(new_cell.its_oid());
262 set_mode(HEALTH, true);
264 insert_to_indices(new_cell);
270 dl_list::insert_as_head(const dl_list_cell_handler& new_cell)
273 dl_list_cell_handler* z = 0;
276 if ( v_dl_list_head.icode() != 0 ) {
278 dl_list_cell_handler first_cell(v_dl_list_head,
283 z = (dl_list_cell_handler*)&new_cell;
284 first_cell -> set_backward_ptr(z -> its_oid());
286 first_cell -> set_backward_ptr(new_cell.its_oid());
291 ((dl_list_cell_handler&)new_cell) -> set_forward_ptr(v_dl_list_head);
294 v_dl_list_head.become(z -> its_oid());
296 v_dl_list_head.become(new_cell.its_oid());
299 if ( v_dl_list_tail.icode() == 0 )
300 v_dl_list_tail.become(v_dl_list_head);
303 set_mode(HEALTH, true);
305 insert_to_indices(new_cell);
311 dl_list::insert_as_tail(dl_list_cell_handler& new_cell)
313 if ( v_dl_list_tail.icode() != 0 ) {
315 dl_list_cell_handler last_cell(v_dl_list_tail,
319 last_cell -> set_forward_ptr(new_cell.its_oid());
322 new_cell -> set_backward_ptr(v_dl_list_tail);
323 v_dl_list_tail.become(new_cell.its_oid());
325 if ( v_dl_list_head.icode() == 0 )
326 v_dl_list_head.become(v_dl_list_tail);
329 set_mode(HEALTH, true);
331 new_cell -> set_mode(UPDATE, true);
333 insert_to_indices(new_cell);
338 io_status dl_list::asciiOut(ostream& out)
341 MESSAGE(cerr, "HEAD");
342 v_dl_list_head.asciiOut(out); cerr << "\n";
344 MESSAGE(cerr, "TAIL");
345 v_dl_list_tail.asciiOut(out); cerr << "\n";
348 my_oid().asciiOut(out);
351 if ( v_sz == 0 ) return done;
353 oid_t* cell_ptr = &v_dl_list_head;
355 for ( int i=1; i<=v_sz; i++ ) {
357 if ( cell_ptr == 0 ) {
358 throw(stringException("broken chain"));
361 if ( cell_ptr -> icode() == 0 ) {
364 throw(stringException("dl_list::get_component(): broken chain"));
367 dl_list_cell_handler cell(*cell_ptr, storage_ptr);
370 cell -> asciiOut(cerr); cerr << "\n";
371 cell_ptr = &cell -> get_forward_ptr();
378 void dl_list::batch_index_begin()
380 for ( int i=0; i<v_num_indices; i++ ) {
381 if ( v_indices[i] != 0 ) {
382 (*v_indices[i]) -> batch_index_begin();
387 void dl_list::batch_index_end()
389 for ( int i=0; i<v_num_indices; i++ ) {
390 if ( v_indices[i] != 0 ) {
391 (*v_indices[i]) -> batch_index_end();
396 io_status dl_list::asciiIn(istream& in)
399 io_status ok = batch_asciiIn(in);
404 io_status dl_list::batch_asciiIn(istream& in)
406 char ccode_buf[LBUFSIZ];
410 while ( (c = in.get()) != EOF ) {
414 in.getline(ccode_buf, LBUFSIZ);
415 char* x = strrchr(ccode_buf, 'L');
419 sscanf(ccode_buf, "%u", &ccode);
421 hd_ptr = new handler(ccode, storage_ptr);
424 if ( filter::assigned() == false )
425 (*hd_ptr) -> asciiIn(in);
427 (*hd_ptr) -> asciiIn(filter::filter_func()(in));
430 MESSAGE(cerr, "dllist: ID read in");
431 hd_ptr -> its_oid().asciiOut(cerr); cerr << "\n";
435 insert_as_tail(*(dl_list_cell_handler*)hd_ptr) ;
443 dl_list::insert_to_indices(const dl_list_cell_handler& new_object)
446 dl_list_cell_handler* z = (dl_list_cell_handler*)&new_object;
449 if ( v_indices[0] != 0 ) {
452 (*v_indices[0]) -> insert_key_loc(new_object, z -> its_oid());
454 (*v_indices[0]) -> insert_key_loc(new_object, new_object.its_oid());
459 for ( int i = 1; i < v_num_indices; i++ ) {
461 if ( v_indices[i] == 0 ) continue;
463 handler* y = (*(composite_handler*)&new_object)
467 MESSAGE(cerr, "dlist: comp id:");
468 y -> its_oid().asciiOut(cerr); cerr << "\n";
469 MESSAGE(cerr, "obj id: (its_oid and my_oid)");
470 new_object.its_oid().asciiOut(cerr); cerr << "\n";
471 (*(dl_list_cell_handler*)&new_object) -> my_oid().asciiOut(cerr); cerr << "\n";
475 if ( y == 0 ) continue;
477 // A16 backward compatible
479 (*v_indices[i]) -> insert_key_loc(*y, z -> its_oid());
481 (*v_indices[i]) -> insert_key_loc(*y, new_object.its_oid());
484 //debug(cerr, y -> its_oid());
485 //debug(cerr, new_object.its_oid());
487 if ( !(y -> its_oid() == new_object.its_oid()) )
490 set_mode(HEALTH, true);
496 int dl_list::cdr_sizeof()
498 return composite::cdr_sizeof() +
499 v_dl_list_head.cdr_sizeof() +
500 v_dl_list_tail.cdr_sizeof() +
501 sizeof(v_num_indices);
504 io_status dl_list::cdrOut(buffer& buf)
506 composite::cdrOut(buf);
507 v_dl_list_head.cdrOut(buf);
508 v_dl_list_tail.cdrOut(buf);
509 buf.put(v_num_indices);
513 io_status dl_list::cdrIn(buffer& buf)
515 composite::cdrIn(buf);
516 v_dl_list_head.cdrIn(buf);
517 v_dl_list_tail.cdrIn(buf);
518 buf.get(v_num_indices);
522 oid_t dl_list::get_first_oid(const handler& query, int index)
524 if ( !INRANGE(index, 0, v_num_indices-1) ) {
525 MESSAGE(cerr, "cset::get_first_oid(): invalid index");
526 throw(boundaryException(0, v_num_indices-1, index));
529 if ( v_indices[index] == 0 ) {
530 throw(stringException("cset::get_first_oid(): NULL index ptr"));
533 return (*v_indices[index]) -> first_of_invlist(query);
536 void dl_list::commit()
538 for ( int i = 1; i < v_num_indices; i++ )
541 v_indices[i] -> commit() ;
547 HANDLER_BODIES(dl_list)