d20e7a77af3783e839d8b387ad14d75f2651b4f1
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / dlp_hd.C
1 /*
2  * $XConsortium: dlp_hd.cc /main/4 1996/06/11 17:28:37 cde-hal $
3  *
4  * Copyright (c) 1992 HAL Computer Systems International, Ltd.
5  * All rights reserved.  Unpublished -- rights reserved under
6  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
7  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
8  * OR DISCLOSURE.
9  * 
10  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
11  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
12  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
13  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
14  * INTERNATIONAL, LTD.
15  * 
16  *                         RESTRICTED RIGHTS LEGEND
17  * Use, duplication, or disclosure by the Government is subject
18  * to the restrictions as set forth in subparagraph (c)(l)(ii)
19  * of the Rights in Technical Data and Computer Software clause
20  * at DFARS 252.227-7013.
21  *
22  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
23  *                  1315 Dell Avenue
24  *                  Campbell, CA  95008
25  * 
26  */
27
28
29 #include "oliasdb/dlp_hd.h"
30
31 handler* dlp::get_component(int index) 
32 {
33    if ( index !=  1 )
34       throw(boundaryException(1, 1, index));
35
36    return new handler(/*c,*/ f_oid, storage_ptr);
37 }
38
39 io_status dlp::asciiOut(ostream& out)
40 {
41 //////////////////////////////////////////////
42 // qfc: cause dlp trouble to find end nodes.
43 //////////////////////////////////////////////
44 /*
45    if ( BIT_TEST(pos_status, BEG) )
46       out << '+';
47 */
48
49    io_status ok = node_oid.asciiOut(out);
50
51 /*
52    if ( BIT_TEST(pos_status, TERM) )
53       out << '-';
54 */
55
56    return ok;
57 }
58
59 // format for a book section:
60 //  1004 \n
61 //  +x.x \n
62 //  ...
63 //  1004 \n
64 //  x.x \n
65 //  - \n
66 // 
67 // a dlp stream is (book_section)+
68
69 io_status dlp::asciiIn(istream& in)
70 {
71    set_mode(UPDATE, true);
72
73    pos_status = NOT_BEG_TERM;
74
75    int plus = in.get();
76
77    if ( plus == '+' ) {
78       pos_status |= BEG;
79    } else
80       in.putback(char(plus));
81
82    io_status ok = node_oid.asciiIn(in);
83
84    int minus = in.get();
85
86    if ( minus == '-' ) {
87       pos_status |= TERM;
88       if ( in.get() != '\n' )
89       throw(stringException("should be a newline"));
90    } else
91       in.putback(char(minus));
92
93 //debug(cerr, int(BEG));
94 //debug(cerr, int(TERM));
95 //debug(cerr, int(pos_status));
96 //debug(cerr, node_oid);
97
98    return ok;
99 }
100
101 int dlp::cdr_sizeof()
102 {
103    return dl_list_cell::cdr_sizeof() + node_oid.cdr_sizeof() + sizeof(pos_status);
104 }
105
106 io_status dlp::cdrOut(buffer& buf)
107 {
108    dl_list_cell::cdrOut(buf);
109    node_oid.cdrOut(buf);
110    buf.put(pos_status);
111    return done;
112 }
113
114 io_status dlp::cdrIn(buffer& buf)
115 {
116    dl_list_cell::cdrIn(buf);
117    node_oid.cdrIn(buf, OLIAS_NODE_CODE);
118    buf.get(pos_status);
119    return done;
120 }
121
122
123 MMDB_BODIES(dlp)
124
125 ///////////////////////////////////
126 //
127 ///////////////////////////////////
128
129 dlp_smart_ptr::
130 dlp_smart_ptr(info_lib* lib_ptr, 
131               const char* info_base_name, const oid_t& id): 
132 smart_ptr(lib_ptr, info_base_name, DLP_LIST_POS, 
133           managers::query_mgr -> form_oid_handler(
134                     oid_t(OLIAS_NODE_CODE, id.icode())
135                                                  ),
136 ////////////////////////////////////////////////////////////
137 // to keep backward compatibility
138 // up to 2.2: position is specified by BASE_COMPONENT_INDEX
139 // 2.3 and higher: position is specified by THIS
140 ////////////////////////////////////////////////////////////
141 (lib_ptr->get_info_base(info_base_name)->
142 get_list(DLP_LIST_POS)->its_store()->
143 get_db_version() < mm_version(2,3)) ? BASE_COMPONENT_INDEX : THIS, 
144 smart_ptr::LIST
145          )
146 {
147 }
148
149 dlp_smart_ptr::
150 dlp_smart_ptr(info_base* bs_ptr, const oid_t& id) : 
151 smart_ptr(bs_ptr, DLP_LIST_POS, 
152           managers::query_mgr -> form_oid_handler(
153                     oid_t(OLIAS_NODE_CODE, id.icode())
154                                                  ),
155 ////////////////////////////////////////////////////////////
156 // to keep backward compatibility
157 // up to 2.2: position is specified by BASE_COMPONENT_INDEX
158 // 2.3 and higher: position is specified by THIS
159 ////////////////////////////////////////////////////////////
160 (bs_ptr-> get_list(DLP_LIST_POS)->its_store()->
161 get_db_version() < mm_version(2,3)) ? BASE_COMPONENT_INDEX : THIS, 
162            smart_ptr::LIST
163          )
164 {
165 }
166
167 dlp_smart_ptr::
168 dlp_smart_ptr(dlp_smart_ptr& dsp, const oid_t& dlp_id) 
169 {
170    smart_ptr::_init(dlp_id, dsp.its_store());
171 }
172
173 ///////////////////////////////////
174 //
175 ///////////////////////////////////
176 const oid_t dlp_smart_ptr::node_id()
177 {
178    dlp* x = (dlp*)(handler::operator->());
179    return oid_t( x -> node_oid );
180 }
181
182 dlp_smart_ptr* dlp_smart_ptr::prev()
183 {
184    oid_t back_cell_oid(prev_dlp_oid());
185
186    if ( back_cell_oid.icode() == 0 )
187       return 0;
188    else {
189
190       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
191
192       dlp_smart_ptr* back_cell_hd = (dlp_smart_ptr*)
193           new smart_ptr(cell_hd->its_store(), back_cell_oid); 
194
195       if ( back_cell_hd -> node_id().icode() == 0 ) {
196          delete back_cell_hd;
197          return 0;
198       } else
199          return back_cell_hd;
200    }
201 }
202
203 dlp_smart_ptr* dlp_smart_ptr::next()
204 {
205    oid_t next_cell_oid(next_dlp_oid());
206
207    if ( next_cell_oid.icode() == 0 )
208       return 0;
209    else {
210
211       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
212
213       dlp_smart_ptr* next_cell_hd = (dlp_smart_ptr*)
214           new smart_ptr(cell_hd->its_store(), next_cell_oid);
215
216       if ( next_cell_hd -> node_id().icode() == 0 ) {
217          delete next_cell_hd;
218          return 0;
219       } else
220          return next_cell_hd;
221    }
222 }
223         
224 oid_t dlp_smart_ptr::next_node_oid()
225 {
226    dlp_smart_ptr* x = next();
227
228    if ( x ) {
229       //return oid_t(x -> node_id());
230       oid_t z(x -> node_id());
231       delete x;
232       return z;
233    } else {
234       return ground;
235    }
236 }
237         
238 oid_t dlp_smart_ptr::prev_node_oid()
239 {
240    dlp_smart_ptr* x = prev();
241
242    if (x) {
243       oid_t z(x -> node_id());
244       delete x;
245       return z;
246    } else {
247       return ground;
248    }
249 }
250
251 oid_t dlp_smart_ptr::prev_dlp_oid()
252 {
253    if ( BIT_TEST(((dlp*)(handler::operator->())) -> pos_status, dlp::BEG) ) {
254       return ground;
255    } else {
256       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
257       return oid_t((*cell_hd) -> get_backward_ptr());
258    }
259 }
260
261 oid_t dlp_smart_ptr::next_dlp_oid()
262 {
263 //debug(cerr, *((dlp*)(handler::operator->())));
264    if ( BIT_TEST(((dlp*)(handler::operator->())) -> pos_status, dlp::TERM) )
265       return ground;
266    else {
267       dl_list_cell_handler* cell_hd = (dl_list_cell_handler*)this;
268       return oid_t((*cell_hd) -> get_forward_ptr());
269    }
270 }