OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / dlp_hd.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: dlp_hd.cc /main/4 1996/06/11 17:28:37 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 "oliasdb/dlp_hd.h"
52
53 handler* dlp::get_component(int index) 
54 {
55    if ( index !=  1 )
56       throw(boundaryException(1, 1, index));
57
58    return new handler(/*c,*/ f_oid, storage_ptr);
59 }
60
61 io_status dlp::asciiOut(ostream& out)
62 {
63 //////////////////////////////////////////////
64 // qfc: cause dlp trouble to find end nodes.
65 //////////////////////////////////////////////
66 /*
67    if ( BIT_TEST(pos_status, BEG) )
68       out << '+';
69 */
70
71    io_status ok = node_oid.asciiOut(out);
72
73 /*
74    if ( BIT_TEST(pos_status, TERM) )
75       out << '-';
76 */
77
78    return ok;
79 }
80
81 // format for a book section:
82 //  1004 \n
83 //  +x.x \n
84 //  ...
85 //  1004 \n
86 //  x.x \n
87 //  - \n
88 // 
89 // a dlp stream is (book_section)+
90
91 io_status dlp::asciiIn(istream& in)
92 {
93    set_mode(UPDATE, true);
94
95    pos_status = NOT_BEG_TERM;
96
97    int plus = in.get();
98
99    if ( plus == '+' ) {
100       pos_status |= BEG;
101    } else
102       in.putback(char(plus));
103
104    io_status ok = node_oid.asciiIn(in);
105
106    int minus = in.get();
107
108    if ( minus == '-' ) {
109       pos_status |= TERM;
110       if ( in.get() != '\n' )
111       throw(stringException("should be a newline"));
112    } else
113       in.putback(char(minus));
114
115 //debug(cerr, int(BEG));
116 //debug(cerr, int(TERM));
117 //debug(cerr, int(pos_status));
118 //debug(cerr, node_oid);
119
120    return ok;
121 }
122
123 int dlp::cdr_sizeof()
124 {
125    return dl_list_cell::cdr_sizeof() + node_oid.cdr_sizeof() + sizeof(pos_status);
126 }
127
128 io_status dlp::cdrOut(buffer& buf)
129 {
130    dl_list_cell::cdrOut(buf);
131    node_oid.cdrOut(buf);
132    buf.put(pos_status);
133    return done;
134 }
135
136 io_status dlp::cdrIn(buffer& buf)
137 {
138    dl_list_cell::cdrIn(buf);
139    node_oid.cdrIn(buf, OLIAS_NODE_CODE);
140    buf.get(pos_status);
141    return done;
142 }
143
144
145 MMDB_BODIES(dlp)
146
147 ///////////////////////////////////
148 //
149 ///////////////////////////////////
150
151 dlp_smart_ptr::
152 dlp_smart_ptr(info_lib* lib_ptr, 
153               const char* info_base_name, const oid_t& id): 
154 smart_ptr(lib_ptr, info_base_name, DLP_LIST_POS, 
155           managers::query_mgr -> form_oid_handler(
156                     oid_t(OLIAS_NODE_CODE, id.icode())
157                                                  ),
158 ////////////////////////////////////////////////////////////
159 // to keep backward compatibility
160 // up to 2.2: position is specified by BASE_COMPONENT_INDEX
161 // 2.3 and higher: position is specified by THIS
162 ////////////////////////////////////////////////////////////
163 (lib_ptr->get_info_base(info_base_name)->
164 get_list(DLP_LIST_POS)->its_store()->
165 get_db_version() < mm_version(2,3)) ? BASE_COMPONENT_INDEX : THIS, 
166 smart_ptr::LIST
167          )
168 {
169 }
170
171 dlp_smart_ptr::
172 dlp_smart_ptr(info_base* bs_ptr, const oid_t& id) : 
173 smart_ptr(bs_ptr, DLP_LIST_POS, 
174           managers::query_mgr -> form_oid_handler(
175                     oid_t(OLIAS_NODE_CODE, id.icode())
176                                                  ),
177 ////////////////////////////////////////////////////////////
178 // to keep backward compatibility
179 // up to 2.2: position is specified by BASE_COMPONENT_INDEX
180 // 2.3 and higher: position is specified by THIS
181 ////////////////////////////////////////////////////////////
182 (bs_ptr-> get_list(DLP_LIST_POS)->its_store()->
183 get_db_version() < mm_version(2,3)) ? BASE_COMPONENT_INDEX : THIS, 
184            smart_ptr::LIST
185          )
186 {
187 }
188
189 dlp_smart_ptr::
190 dlp_smart_ptr(dlp_smart_ptr& dsp, const oid_t& dlp_id) 
191 {
192    smart_ptr::_init(dlp_id, dsp.its_store());
193 }
194
195 ///////////////////////////////////
196 //
197 ///////////////////////////////////
198 const oid_t dlp_smart_ptr::node_id()
199 {
200    dlp* x = (dlp*)(handler::operator->());
201    return oid_t( x -> node_oid );
202 }
203
204 dlp_smart_ptr* dlp_smart_ptr::prev()
205 {
206    oid_t back_cell_oid(prev_dlp_oid());
207
208    if ( back_cell_oid.icode() == 0 )
209       return 0;
210    else {
211
212       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
213
214       dlp_smart_ptr* back_cell_hd = (dlp_smart_ptr*)
215           new smart_ptr(cell_hd->its_store(), back_cell_oid); 
216
217       if ( back_cell_hd -> node_id().icode() == 0 ) {
218          delete back_cell_hd;
219          return 0;
220       } else
221          return back_cell_hd;
222    }
223 }
224
225 dlp_smart_ptr* dlp_smart_ptr::next()
226 {
227    oid_t next_cell_oid(next_dlp_oid());
228
229    if ( next_cell_oid.icode() == 0 )
230       return 0;
231    else {
232
233       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
234
235       dlp_smart_ptr* next_cell_hd = (dlp_smart_ptr*)
236           new smart_ptr(cell_hd->its_store(), next_cell_oid);
237
238       if ( next_cell_hd -> node_id().icode() == 0 ) {
239          delete next_cell_hd;
240          return 0;
241       } else
242          return next_cell_hd;
243    }
244 }
245         
246 oid_t dlp_smart_ptr::next_node_oid()
247 {
248    dlp_smart_ptr* x = next();
249
250    if ( x ) {
251       //return oid_t(x -> node_id());
252       oid_t z(x -> node_id());
253       delete x;
254       return z;
255    } else {
256       return ground;
257    }
258 }
259         
260 oid_t dlp_smart_ptr::prev_node_oid()
261 {
262    dlp_smart_ptr* x = prev();
263
264    if (x) {
265       oid_t z(x -> node_id());
266       delete x;
267       return z;
268    } else {
269       return ground;
270    }
271 }
272
273 oid_t dlp_smart_ptr::prev_dlp_oid()
274 {
275    if ( BIT_TEST(((dlp*)(handler::operator->())) -> pos_status, dlp::BEG) ) {
276       return ground;
277    } else {
278       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
279       return oid_t((*cell_hd) -> get_backward_ptr());
280    }
281 }
282
283 oid_t dlp_smart_ptr::next_dlp_oid()
284 {
285 //debug(cerr, *((dlp*)(handler::operator->())));
286    if ( BIT_TEST(((dlp*)(handler::operator->())) -> pos_status, dlp::TERM) )
287       return ground;
288    else {
289       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
290       return oid_t((*cell_hd) -> get_forward_ptr());
291    }
292 }