Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / schema / container_desc.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: container_desc.cc /main/5 1996/07/18 14:49:46 drk $
25  *
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
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 "schema/container_desc.h"
52
53 container_desc::container_desc(int code, const char* comment) : 
54         index_nms(10), stored_object_desc(code, comment)
55 {
56 }
57
58 container_desc::~container_desc()
59 {
60    int ind = index_nms.first();
61    char* idx_nm = 0;
62
63    while ( ind != -1 ) {
64
65       idx_nm = (char*)index_nms[ind];
66
67       delete idx_nm;
68
69       index_nms.next(ind);
70    }
71 }
72
73 void container_desc::set_index_nm(const char* str)
74 {
75    if ( index_nms.count() <= index_nms.no_elmts() ) {
76       index_nms.expandWith(2*index_nms.count());
77    }
78
79    int i = index_nms.no_elmts() + 1;
80
81    int l = strlen(str);
82    char *x = new char[l+1];
83    memcpy(x, str, l);
84    x[l] = 0;
85
86 //cerr << "container_desc::set_index_nm(): this = " << this << ", str=(long)" << (long)str << " i=" << i << endl;
87    index_nms.insert(x, i);
88
89    index_nms.reset_elmts(i);
90 }
91
92 ostream& container_desc::asciiOut(ostream& out, Boolean last)
93 {
94    if ( index_nms.no_elmts() == 0 ) {
95       stored_object_desc::asciiOut(out, last);
96       return out;
97    } 
98
99    stored_object_desc::asciiOut(out, false);
100
101    int ind = index_nms.first();
102    char* index_nm = 0;
103    int num_printed = 1;
104
105    for ( int i=0; i<index_nms.count(); i++ ) {
106 //cerr << "ind=" << ind << endl;
107      index_nm = (char*)index_nms[ind];
108      index_nms.next(ind);
109
110      if ( index_nm ) {
111 //cerr << "this=" << this << "; index_nm=(long)" << (long)index_nm << " ind=" << ind << endl;
112        if ( num_printed < index_nms.no_elmts() )
113          desc_print(out, index_nm);
114        else {
115          if ( last == true ) {
116            desc_print_end(out, index_nm);
117            break;
118          } else
119            desc_print(out, index_nm);
120        }
121        num_printed++;
122      }
123    }
124
125    return out;
126
127 /*
128    char* index_nm = 0;
129    int ind = index_nms.first();
130    int last_ind = 0;
131
132 cerr << "this=" << this << "; index_nms.no_elmts()=" << index_nms.no_elmts();
133 cerr << "first()=" << ind << endl;
134
135    do {
136       last_ind = ind;
137
138       index_nms.next(ind);
139
140       if ( index_nms[ind] == 0 )
141          break;
142
143    } while ( ind != -1 );
144
145 ////////////////////////////
146    stored_object_desc::asciiOut(out, false);
147
148 cerr << "last_ind=" << last_ind << endl;
149 cerr << "ind=" << ind << endl;
150
151    while ( ind != last_ind ) {
152
153      index_nm = (char*)index_nms[ind];
154      index_nms.next(ind);
155
156      if ( index_nm ) {
157 cerr << "this=" << this << "; index_nm=(long)" << (long)index_nm << " ind=" << ind << endl;
158        desc_print(out, index_nm);
159      }
160    }
161
162    index_nm = (char*)index_nms[last_ind];
163  
164    if ( last == true)
165      desc_print_end(out, index_nm);
166    else
167      desc_print(out, index_nm);
168
169
170    return out;
171 */
172 }
173
174 void 
175 container_desc::init_index_array(object_dict& dict, 
176                                  c_index_handlerPtr*& index_array, 
177                                  int& idx_array_sz)
178 {
179    c_index_handlerPtr* tmp_index_array = 
180         new c_index_handlerPtr[index_nms.no_elmts()];
181
182    idx_array_sz = 0;
183
184    int i = 0;
185    int ind = index_nms.first();
186    char* idx_nm = 0;
187
188    while ( ind != -1 ) {
189
190       idx_nm = (char*)index_nms[ind];
191
192       if ( idx_nm ) {
193
194          c_index_handler* idx_handler = 
195             (c_index_handler*)dict.get_handler(idx_nm);
196
197          idx_array_sz = MAX(idx_array_sz, (*idx_handler) -> bound_to());
198
199          tmp_index_array[i++] = idx_handler;
200       }
201
202       index_nms.next(ind);
203 //cerr << "ind=" << ind << endl;
204    }
205
206    idx_array_sz++;
207
208    index_array = new c_index_handlerPtr[idx_array_sz];
209
210    for ( ind=0; ind<idx_array_sz; ind++ ) 
211       index_array[ind] = 0;
212
213    for ( ind=0; ind<i; ind++ ) {
214       int pos = (*tmp_index_array[ind]) -> bound_to();
215       index_array[pos] = tmp_index_array[ind];
216    }
217
218    delete tmp_index_array;
219 }
220
221 //////////////////////////////////////////////////////////////////////
222 //
223 //////////////////////////////////////////////////////////////////////
224
225 set_desc::set_desc() : container_desc(SET_CODE, "container      set")
226 {
227 }
228
229 handler* set_desc::init_handler(object_dict& dict) 
230 {
231    page_storage* store = (page_storage*)dict.get_store(get_store_nm());
232
233    if ( v_oid.icode() == 0 ) {
234       v_handler_ptr = new handler(SET_CODE, store);
235       desc::set_oid(v_handler_ptr -> its_oid());
236    } else
237       v_handler_ptr = new cset_handler(v_oid, store);
238
239 /////////////////////////////
240 // init index array 
241 /////////////////////////////
242    c_index_handlerPtr* idx_array = 0; int sz = 0;
243
244    init_index_array(dict, idx_array, sz) ;
245
246 //debug(cerr, v_handler_ptr -> its_oid());
247 //debug(cerr, int(v_handler_ptr -> operator ->()));
248
249    (*(cset_handler*)v_handler_ptr) -> init_data_member(idx_array, sz);
250
251    return v_handler_ptr;
252 }
253
254 //////////////////////////////////////////////////////////////////////
255 //
256 //////////////////////////////////////////////////////////////////////
257
258 list_desc::list_desc() : container_desc(DL_LIST_CODE, "container        list")
259 {
260 }
261
262 handler* list_desc::init_handler(object_dict& dict) 
263 {
264    page_storage* store = (page_storage*)dict.get_store(get_store_nm());
265
266    if ( v_oid.icode() == 0 ) {
267       v_handler_ptr = new handler(DL_LIST_CODE, store);
268       desc::set_oid(v_handler_ptr -> its_oid());
269    } else
270       v_handler_ptr = new dl_list_handler(v_oid, store);
271
272 /////////////////////////////
273 // init index array 
274 /////////////////////////////
275    c_index_handlerPtr* idx_array = 0; int sz = 0;
276
277    init_index_array(dict, idx_array, sz) ;
278
279 //debug(cerr, v_handler_ptr -> its_oid());
280    (*(dl_list_handler*)v_handler_ptr) -> init_data_member(idx_array, sz);
281
282    return v_handler_ptr;
283 }
284
285