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: cset.cc /main/5 1996/06/11 17:23:58 cde-hal $
26 * Copyright (c) 1992 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/cset.h"
52 #include "utility/xtime.h"
54 cset::cset(c_code_t c_cd): composite(c_cd)
59 set_mode(SWAP_ALLOWED, false);
62 void cset::init_data_member(c_index_handlerPtr* index_arrray,
66 indices = index_arrray;
68 set_mode(HEALTH, true);
71 set_mode(UPDATE, true);
78 MESSAGE(cerr, "~cset() called.");
79 debug(cerr, my_oid());
80 debug(cerr, num_indices);
81 debug(cerr, int(this));
82 MESSAGE(cerr, "~cset() called.");
83 debug(cerr, num_indices);
89 handler* cset::get_component(int index)
91 if ( indices[0] == 0 )
94 oid_t id_ptr = (*indices[0]) -> first_of_invlist(index);
96 handler* y = new handler(id_ptr, storage_ptr);
101 oid_list_handler* cset::get_locs(handler& query, int index)
103 if ( !INRANGE(index, 0, (int) num_indices-1) ) {
104 MESSAGE(cerr, "cset::get_locs(): invalid index");
105 throw(boundaryException(0, num_indices-1, index));
108 if ( indices[index] == 0 ) {
109 MESSAGE(cerr, "cset::get_locs(): invalid index");
110 throw(stringException("NULL index ptr"));
113 return (*indices[index]) -> get_loc_list(query);
116 oid_t cset::get_first_oid(const handler& query, int index)
118 if ( !INRANGE(index, 0, (int) num_indices-1) ) {
119 MESSAGE(cerr, "cset::get_first_oid(): invalid index");
120 throw(boundaryException(0, num_indices-1, index));
123 if ( indices[index] == 0 ) {
124 MESSAGE(cerr, "cset::get_first_oid(): invalid index");
125 throw(stringException("NULL index ptr"));
128 return (*indices[index]) -> first_of_invlist(query);
131 c_index_handler* cset::get_index_ptr(int index)
133 if ( !INRANGE(index, 0, (int) num_indices-1) ) {
134 MESSAGE(cerr, "cset::get_index_ptr(): invalid index");
135 throw(boundaryException(0, num_indices-1, index));
138 return indices[index];
141 void cset::batch_index_begin()
143 for ( unsigned int i=0; i<num_indices; i++ ) {
144 if ( indices[i] != 0 ) {
145 (*indices[i]) -> batch_index_begin();
150 void cset::batch_index_end()
152 for ( unsigned int i=0; i<num_indices; i++ ) {
153 if ( indices[i] != 0 ) {
154 (*indices[i]) -> batch_index_end();
159 io_status cset::asciiIn(istream& in)
162 io_status ok = batch_asciiIn(in);
168 io_status cset::batch_asciiIn(istream& in)
170 handler* root_hd_ptr = 0;
179 char ccode_buf[LBUFSIZ];
181 //fprintf(stderr, "batch_asciiIn() : start looping \n");
182 while ( (c = in.get()) != EOF ) {
185 in.getline(ccode_buf, LBUFSIZ);
186 //fprintf(stderr, "ccode_buf=%s\n", ccode_buf);
188 char* x = strrchr(ccode_buf, 'L');
192 sscanf(ccode_buf, "%u", &ccode);
195 //fprintf(stderr, "ccode=%d\n", ccode);
197 root_hd_ptr = new handler(ccode, storage_ptr);
200 if ( filter::assigned() == false )
201 (*root_hd_ptr) -> asciiIn(in);
203 (*root_hd_ptr) -> asciiIn(filter::filter_func()(in));
205 root_hd_ptr->commit();
207 insert_object(*root_hd_ptr);
212 if ( v_sz % 1000 == 0 && v_sz != 0 ) {
222 //(*root_hd_ptr)-> asciiOut(cerr);
225 (root_hd_ptr -> its_oid()).asciiOut(cerr);
226 storage_ptr -> asciiOut(cerr);
227 MESSAGE(cerr, "\n========");
236 io_status cset::asciiOut(ostream&)
242 cset::insert_object(const handler& new_object)
245 MESSAGE(cerr, "in insert_object()");
246 new_object.its_oid().asciiOut(cerr); cerr << "\n";
248 if ( indices[0] != 0 ) {
251 handler* zz = (handler*)&new_object;
252 (*indices[0]) -> insert_key_loc(new_object, zz -> its_oid());
254 (*indices[0]) -> insert_key_loc(new_object, new_object.its_oid());
258 for ( unsigned int i = 1; i < num_indices; i++ ) {
260 if ( indices[i] == 0 )
263 handler* y = (*(composite_handler*)&new_object)
266 if ( y == 0 ) continue;
269 handler* ww = (handler*)&new_object;
270 (*indices[i]) -> insert_key_loc(*y, ww -> its_oid());
272 (*indices[i]) -> insert_key_loc(*y, new_object.its_oid());
275 if ( !(y -> its_oid() == new_object.its_oid()) )
280 set_mode(UPDATE, true);
286 Boolean cset::remove_component(const oid_t& x_oid)
288 handler* x = new handler(x_oid, storage_ptr);
290 for ( unsigned int i = 1; i < num_indices; i++ ) {
292 if ( indices[i] == 0 )
295 handler* y = (*(composite_handler*)x) -> get_component(i);
297 (*indices[i]) -> remove_loc(*y, x_oid);
310 set_mode(UPDATE, true);
315 // update old component object 'old_comp_obj' to new
316 // component object 'new_comp_obj'.
317 // variable 'index' holds the index of the index object
318 // effected. 'obj_pos' is the id of the
319 // main object, of which old_comp_obj is a part.
322 cset::update_index(handler* old_comp_obj, handler* new_comp_obj,
327 if ( !INRANGE(index, 1, (int) num_indices-1) ) {
328 throw(boundaryException(1, num_indices-1, index));
331 if ( indices[index] ) {
334 return (*indices[index]) -> update_streampos
346 int cset::cdr_sizeof()
348 return composite::cdr_sizeof() + sizeof(num_indices);
351 io_status cset::cdrOut(buffer& buf)
353 composite::cdrOut(buf);
354 buf.put(num_indices);
358 io_status cset::cdrIn(buffer& buf)
360 composite::cdrIn(buf);
361 buf.get(num_indices);
367 for ( unsigned int i = 1; i < num_indices; i++ ) {
370 indices[i] -> commit();