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: oid_list.cc /main/5 1996/07/18 14:43:28 drk $
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/oid_list.h"
53 void oid_list::init_persistent_info(persistent_info* x)
55 ostring* u = list_ptr.p;
57 root::init_persistent_info(x);
59 if ( get_mode(OLD_OBJECT) == false ) {
61 //MESSAGE(cerr, "oid_list::init_persistent_info");
62 //debug(cerr, (void*)this);
63 //debug(cerr, my_oid());
68 //MESSAGE(cerr, "oid_list::init_persistent_info(), new object case");
69 //debug(cerr, (void*)this);
70 //debug(cerr, (void*)list_ptr.p);
78 storage_ptr -> insertString(list_ptr.loc, w, v);
81 //debug(cerr, list_ptr.loc);
88 oid_list::oid_list(c_code_t c_id) : composite(c_id),
89 f_internal_index(false), chk_index(0)
95 oid_list::oid_list(int num_oids, c_code_t c_id) : composite(c_id),
96 f_internal_index(false), chk_index(0)
99 init_data_member(num_oids);
102 oid_list::oid_list(oid_list& x) :
103 composite(x), chk_index(0)
106 init_data_member(x.v_sz);
108 for ( unsigned int i=1; i<=v_sz; i++ )
109 update_component(i, x(i));
112 oid_list::~oid_list()
114 if ( get_mode(PERSISTENT) == false ) {
121 void oid_list::init_data_member(int leng)
123 int char_leng = leng * OID_T_SZ ;
124 char* ptr = new char[char_leng];
129 for ( int i=0; i<leng; i++ ) {
130 x.to_char_string(y, false);
134 list_ptr.loc = 0; // to please purify
135 list_ptr.p = new ostring(ptr, char_leng);
137 //MESSAGE(cerr, "oid_list::init_data_member(int leng)");
138 //debug(cerr, (void*)this);
139 //debug(cerr, (void*)list_ptr.p);
143 set_mode(UPDATE, true);
146 void oid_list::build_internal_index()
148 if ( get_mode(OLD_OBJECT) == true &&
149 get_mode(PERSISTENT) == true &&
152 chk_index = new chunks_index(storage_ptr, list_ptr.loc);
157 void oid_list::reqest_build_internal_index()
159 f_internal_index = true;
162 Boolean oid_list::expand_space(int extra_oids)
165 MESSAGE(cerr, "in expand_space()");
166 debug(cerr, my_oid());
167 debug(cerr, extra_oids);
169 debug(cerr, int(list_ptr.loc));
170 debug(cerr, int(&list_ptr.loc));
175 int extra_char_leng = extra_oids * OID_T_SZ;
177 if ( get_mode(PERSISTENT) == true ) {
179 int total_char_leng = extra_char_leng + v_sz * OID_T_SZ;
181 char* ptr = new char[total_char_leng];
183 memset(ptr, (char)0, total_char_leng);
185 if ( list_ptr.loc == 0 ) {
186 storage_ptr -> insertString(list_ptr.loc, ptr, total_char_leng);
188 storage_ptr -> appendString(list_ptr.loc, ptr, total_char_leng);
196 ok = list_ptr.p -> expand( extra_char_leng );
201 set_mode(UPDATE, true);
207 io_status oid_list::asciiOut(ostream& out)
218 oid_t x = (*this)(ind);
220 if ( x.eq(ground) == false ) {
231 oid_t oid_list::operator()(int ind)
234 MESSAGE(cerr, "oid_list::operator()");
235 debug(cerr, my_oid());
239 debug(cerr, int(this));
240 debug(cerr, int(list_ptr.p));
243 if ( !INRANGE(ind, 1, (int) v_sz) ) {
244 MESSAGE(cerr, "oid_list::opeartor(): out of range");
245 throw(boundaryException(1, v_sz, ind));
249 int offset = (ind - 1) * OID_T_SZ;
251 if ( get_mode(PERSISTENT) == true )
254 if ( list_ptr.loc == 0 )
255 throw(stringException("zero loc value"));
257 if ( f_internal_index == true && chk_index == 0 ) {
258 build_internal_index();
262 str_index_record_t* anchor =
263 chk_index -> chunk_location(offset);
266 readString(anchor -> loc, z, OID_T_SZ,
267 offset - anchor -> str_offset);
271 readString(list_ptr.loc, z, OID_T_SZ, offset);
275 if ( list_ptr.p == 0 )
276 throw(stringException("zero list_ptr.p value"));
278 memcpy(z, list_ptr.p -> get() + offset, OID_T_SZ);
281 //MESSAGE(cerr, "oid_list::operator() done");
284 return oid_t(z, false, swap_order());
286 return oid_t(z, false, false);
292 oid_list::insert_component(const oid_t& new_comp_oid)
295 MESSAGE(cerr, "oid_list::insert_component");
297 debug(cerr, (void*)this);
298 debug(cerr, int(list_ptr.p));
299 new_comp_oid.asciiOut(cerr); cerr << "\n";
303 new_comp_oid.to_char_string(z, swap_order());
305 if ( get_mode(PERSISTENT) == true ) {
307 if ( list_ptr.loc == 0 ) {
310 insertString(list_ptr.loc, z, OID_T_SZ);
314 appendString(list_ptr.loc, z, OID_T_SZ);
318 list_ptr.p -> append(z, OID_T_SZ);
323 set_mode(UPDATE, true);
329 oid_list::update_component(int index, const oid_t& new_oid)
331 //MESSAGE(cerr, "oid_list::update_component()");
332 //debug(cerr, my_oid());
333 if ( !INRANGE(index, 1, (int) v_sz) ) {
334 MESSAGE(cerr, "oid_list update(): out of range");
335 throw(boundaryException(1, v_sz, index));
342 if ( get_mode(PERSISTENT) == true && swap_order() == true )
347 new_oid.to_char_string(z, swap);
349 if ( get_mode(PERSISTENT) == true ) {
351 if ( list_ptr.loc == 0 )
352 throw(stringException("zero list_ptr.p value"));
355 updateString(list_ptr.loc, z,
356 OID_T_SZ, (index-1) * OID_T_SZ
361 //MESSAGE(cerr, "oid_list::update_component(): vm update");
363 if ( list_ptr.p == 0 )
364 throw(stringException("zero list_ptr.p value"));
366 list_ptr.p -> update(z, OID_T_SZ, (index-1)*OID_T_SZ);
369 //MESSAGE(cerr, "oid_list::update_component() done");
373 io_status oid_list::asciiIn(istream& in)
375 //MESSAGE(cerr, "oid_list::asciiIn()");
376 if ( in.get() != LIST_MARK_CHAR )
377 throw(formatException("should be a LIST_MARK_CHAR"));
379 if ( in.get() != '\n' )
380 throw(formatException("should be a \n"));
383 dlist_void_ptr_cell* y = 0;
386 while ( (c = in.get()) != LIST_MARK_CHAR ) {
390 oid_t *x = new oid_t(ground);
392 y = new dlist_void_ptr_cell(x);
394 temp_list.insert_as_tail(y);
399 if ( in.get() != '\n' ) {
400 throw(formatException("bad oid_list input stream"));
403 int oid_array_sz = v_sz * OID_T_SZ;
404 char *oid_array = new char[oid_array_sz];
406 long ind = temp_list.first();
413 y = (dlist_void_ptr_cell*)(ind);
415 ((oid_t*)(y -> void_ptr())) ->
416 to_char_string(z, swap_order());
418 delete ((oid_t*)(y -> void_ptr()));
420 memcpy(oid_array + i * OID_T_SZ, z, OID_T_SZ);
427 if ( get_mode(PERSISTENT) == true ) {
429 if ( list_ptr.loc == 0 )
430 storage_ptr -> insertString(list_ptr.loc, oid_array, oid_array_sz);
432 storage_ptr -> updateString(list_ptr.loc, oid_array, oid_array_sz);
434 set_mode(UPDATE, true);
438 list_ptr.p = new ostring(0);
439 list_ptr.p -> set(oid_array, v_sz);
447 Boolean oid_list::remove_component(const oid_t& x)
452 if ( (*this)(ind).eq(x) == true ) {
454 update_component(ind, ground);
456 set_mode(UPDATE, true);
468 int oid_list::cdr_sizeof()
470 return composite::cdr_sizeof() + sizeof(list_ptr.loc);
473 io_status oid_list::cdrOut(buffer& buf)
476 MESSAGE(cerr, "oid_list::cdrOut()");
477 debug(cerr, (void*)this);
478 debug(cerr, (void*)list_ptr.loc);
479 debug(cerr, my_oid());
481 composite::cdrOut(buf);
482 buf.put(list_ptr.loc);
486 io_status oid_list::cdrIn(buffer& buf)
488 //MESSAGE(cerr, "oid_list::cdrIn()");
489 //debug(cerr, (void*)this);
490 composite::cdrIn(buf);
491 buf.get(list_ptr.loc);
492 //debug(cerr, (void*)list_ptr.loc);
493 //debug(cerr, my_oid());
497 MMDB_BODIES(oid_list)
499 oid_list_handler::oid_list_handler(int num_oids, storagePtr store):
500 handler(OID_LIST_CODE, store)
502 ((oid_list*)obj_ptr) -> init_data_member(num_oids);
505 oid_list_handler::oid_list_handler(const oid_t& v_oid, storagePtr store):
506 handler(v_oid, store)
510 oid_list_handler::~oid_list_handler()
514 oid_list* oid_list_handler::operator ->()
516 return (oid_list*)handler::operator->();