Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / object / cset.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*
24  * $XConsortium: cset.cc /main/5 1996/06/11 17:23:58 cde-hal $
25  *
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
30  * OR DISCLOSURE.
31  * 
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
36  * INTERNATIONAL, LTD.
37  * 
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.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #include "object/cset.h"
52 #include "utility/xtime.h"
53
54 cset::cset(c_code_t c_cd): composite(c_cd)
55 {
56    num_indices = 0;
57    indices = 0;
58   
59    set_mode(SWAP_ALLOWED, false);
60 }
61
62 void cset::init_data_member(c_index_handlerPtr* index_arrray, 
63                          int iptrs
64                         ) 
65 {
66    indices = index_arrray;
67    num_indices = iptrs;
68    set_mode(HEALTH, true);
69
70 #ifdef MEMORY_MAPPED
71    set_mode(UPDATE, true);
72 #endif
73 }
74
75 cset::~cset()
76 {
77 /*
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);
84 */
85
86    delete indices;
87 }
88
89 handler* cset::get_component(int index) 
90 {
91    if ( indices[0] == 0 )
92       return 0;
93
94    oid_t id_ptr = (*indices[0]) -> first_of_invlist(index);
95
96    handler* y = new handler(id_ptr, storage_ptr);
97
98    return y;
99 }
100
101 oid_list_handler* cset::get_locs(handler& query, int index)
102 {
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));
106    }
107
108    if ( indices[index] == 0 ) {
109       MESSAGE(cerr, "cset::get_locs(): invalid index");
110       throw(stringException("NULL index ptr"));
111    }
112
113    return (*indices[index]) -> get_loc_list(query);
114 }
115
116 oid_t cset::get_first_oid(const handler& query, int index)
117 {
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));
121    }
122
123    if ( indices[index] == 0 ) {
124       MESSAGE(cerr, "cset::get_first_oid(): invalid index");
125       throw(stringException("NULL index ptr"));
126    }
127
128    return (*indices[index]) -> first_of_invlist(query);
129 }
130
131 c_index_handler* cset::get_index_ptr(int index)
132 {
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));
136    }
137
138    return indices[index];
139 }
140
141 void cset::batch_index_begin() 
142 {
143    for ( unsigned int i=0; i<num_indices; i++ ) {
144       if ( indices[i] != 0 ) {
145          (*indices[i]) -> batch_index_begin();
146       }
147    }
148 }
149
150 void cset::batch_index_end() 
151 {
152    for ( unsigned int i=0; i<num_indices; i++ ) {
153       if ( indices[i] != 0 ) {
154          (*indices[i]) -> batch_index_end();
155       }
156    }
157 }
158
159 io_status cset::asciiIn(istream& in) 
160 {
161    batch_index_begin();
162    io_status ok = batch_asciiIn(in);
163    batch_index_end();
164
165    return ok;
166 }
167
168 io_status cset::batch_asciiIn(istream& in) 
169 {
170    handler* root_hd_ptr = 0;
171 /*
172 #ifdef DEBUG
173 xtime tmr;
174 float f1;
175 long f2;
176 tmr.start();
177 #endif
178 */
179    char ccode_buf[LBUFSIZ];
180    int c;
181 //fprintf(stderr, "batch_asciiIn() : start looping \n");
182    while ( (c = in.get()) != EOF ) {
183       in.putback(c);
184
185       in.getline(ccode_buf, LBUFSIZ);
186 //fprintf(stderr, "ccode_buf=%s\n", ccode_buf);
187
188       char* x = strrchr(ccode_buf, 'L');
189       if ( x ) *x = 0;
190
191       int ccode; 
192       sscanf(ccode_buf, "%u", &ccode);
193       //in >> ccode ;
194
195 //fprintf(stderr, "ccode=%d\n", ccode);
196
197       root_hd_ptr = new handler(ccode, storage_ptr);
198
199
200       if ( filter::assigned() == false )
201          (*root_hd_ptr) -> asciiIn(in);
202       else
203          (*root_hd_ptr) -> asciiIn(filter::filter_func()(in));
204
205       root_hd_ptr->commit();
206
207       insert_object(*root_hd_ptr);
208
209
210 /*
211 #ifdef DEBUG
212 if ( v_sz % 1000 == 0 && v_sz != 0 ) {
213 tmr.stop(f1, f2);
214 debug(cerr, f1);
215 debug(cerr, f2);
216 debug(cerr, v_sz);
217 tmr.start();
218 }
219 #endif
220 */
221
222 //(*root_hd_ptr)-> asciiOut(cerr);
223
224 /*
225 (root_hd_ptr -> its_oid()).asciiOut(cerr);
226 storage_ptr -> asciiOut(cerr);
227 MESSAGE(cerr, "\n========");
228 */
229       delete root_hd_ptr;
230
231    }
232
233    return done;
234 }
235
236 io_status cset::asciiOut(ostream&) 
237 {
238    return done;
239 }
240
241 Boolean 
242 cset::insert_object(const handler& new_object)
243 {
244 /*
245 MESSAGE(cerr, "in insert_object()");
246 new_object.its_oid().asciiOut(cerr); cerr << "\n";
247 */
248    if ( indices[0] != 0 ) {
249
250 #ifdef A16_BROWSER 
251       handler* zz = (handler*)&new_object;
252       (*indices[0]) -> insert_key_loc(new_object, zz -> its_oid()); 
253 #else
254       (*indices[0]) -> insert_key_loc(new_object, new_object.its_oid()); 
255 #endif
256    }
257
258    for ( unsigned int i = 1; i < num_indices; i++ ) {
259
260       if ( indices[i] == 0 )
261           continue;
262
263       handler* y = (*(composite_handler*)&new_object) 
264                     -> get_component(i);
265
266       if ( y == 0 ) continue;
267
268 #ifdef A16_BROWSER
269       handler* ww = (handler*)&new_object;
270       (*indices[i]) -> insert_key_loc(*y, ww -> its_oid());
271 #else
272       (*indices[i]) -> insert_key_loc(*y, new_object.its_oid());
273 #endif
274
275       if ( !(y -> its_oid() == new_object.its_oid()) )
276          delete y;
277    }
278
279    v_sz++;
280    set_mode(UPDATE, true);
281
282    return true;
283 }
284
285
286 Boolean cset::remove_component(const oid_t& x_oid)
287 {
288    handler* x = new handler(x_oid, storage_ptr);
289
290    for ( unsigned int i = 1; i < num_indices; i++ ) {
291
292       if ( indices[i] == 0 )
293          continue;
294
295       handler* y = (*(composite_handler*)x) -> get_component(i);
296
297       (*indices[i]) -> remove_loc(*y, x_oid);
298
299       y -> destroy();
300
301       delete y;
302
303    }
304
305    x -> destroy();
306
307    delete x;
308
309    v_sz--;
310    set_mode(UPDATE, true);
311
312    return true;
313 }
314
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.
320
321 Boolean 
322 cset::update_index(handler* old_comp_obj, handler* new_comp_obj, 
323                    int index,
324                    oid_t& main_obj_oid)
325 {
326
327    if ( !INRANGE(index, 1, (int) num_indices-1) ) {
328       throw(boundaryException(1, num_indices-1, index));
329    }
330
331    if ( indices[index] ) {
332
333
334       return (*indices[index]) -> update_streampos
335                           (
336                              *old_comp_obj, 
337                              *new_comp_obj, 
338                              main_obj_oid.icode()
339                           );
340
341    } else
342       return true;
343 }
344
345
346 int cset::cdr_sizeof()
347 {
348    return composite::cdr_sizeof() + sizeof(num_indices);
349 }
350
351 io_status cset::cdrOut(buffer& buf)
352 {
353    composite::cdrOut(buf);
354    buf.put(num_indices);
355    return done;
356 }
357
358 io_status cset::cdrIn(buffer& buf)
359 {
360    composite::cdrIn(buf);
361    buf.get(num_indices);
362    return done;
363 }
364
365 void cset::commit() 
366 {
367    for ( unsigned int i = 1; i < num_indices; i++ ) {
368
369       if ( indices[i] )
370          indices[i] -> commit();
371    }
372 }
373
374
375 MMDB_BODIES(cset)
376 HANDLER_BODIES(cset)
377
378