Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / object / oid_t.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: oid_t.cc /main/4 1996/07/18 14:44:11 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 "object/oid_t.h"
52
53 #ifdef C_API
54 oid_t* ground_ptr = 0;
55 #else
56 oid_t ground(c_code_t(0), i_code_t(0));
57 #endif
58
59
60 /* inline
61 oid_t::oid_t()
62 {
63 }
64 */
65
66 /* inline
67 oid_t::oid_t(c_code_t c, i_code_t i) :
68 v_c_code(c), v_i_code(i), v_e_code(0)
69 {
70 }
71 */
72
73 /* inline
74 oid_t::oid_t(const oid_t& x)
75 {
76    v_e_code = x.v_e_code;
77    v_c_code = x.v_c_code;
78    v_i_code = x.v_i_code;
79 }
80 */
81
82 oid_t::oid_t(const char* source, Boolean ascii_format, Boolean swap_order)
83 {
84    if ( source == 0 )
85        throw(stringException("NULL string pointer"));
86
87    if ( ascii_format == false ) {
88
89 // 4/28/93.  do not save c_code in an oid_t.
90       v_c_code = 1;
91       memcpy((char*)&v_i_code, source, sizeof(v_i_code));
92
93       if ( swap_order == true )
94 #ifdef __osf__
95          ORDER_SWAP_INT(v_i_code);
96 #else
97          ORDER_SWAP_LONG(v_i_code);
98 #endif
99
100    } else {
101       istringstream in((char*)source);
102
103       in >> v_c_code;
104
105       if ( in.get() == '\n') {
106          v_i_code = 0;
107       } else {
108          in >> v_i_code;
109       }
110    }
111
112 /*
113 MESSAGE(cerr, "constr oid_t using a string");
114 debug(cerr, v_c_code);
115 debug(cerr, v_i_code);
116 */
117 }
118
119 /* inline
120 oid_t::~oid_t()
121 {
122 }
123 */
124
125 /* inline
126 void oid_t::become(const oid_t& x)
127 {
128    v_e_code = x.v_e_code;
129    v_c_code = x.v_c_code;
130    v_i_code = x.v_i_code;
131 }
132 */
133
134 Boolean oid_t::eq(const oid_t& x) const
135 {
136    if ( v_i_code == x.v_i_code ) {
137       if ( v_c_code == 1 || x.v_c_code == 1 )
138          return true;
139       else {
140         if ( v_c_code == x.v_c_code )
141           return true;
142         else
143           return false;
144       }
145    } else
146       return false;
147 }
148
149 Boolean oid_t::ls(const oid_t & x) const
150 {
151    if ( v_c_code != 1 && x.v_c_code != 1 && v_c_code >= x.v_c_code )
152       return false;
153    else
154    if ( v_i_code >= x.v_i_code )
155       return false;
156    else
157       return true;
158 }
159
160 // Static function to compute a hash code for an oid_t
161 unsigned oid_t::hash(const oid_t& id)
162 {
163     return unsigned(id.icode()) + unsigned(id.ccode());
164 }
165
166 io_status oid_t::asciiOut(ostream& out) const
167 {
168    out << v_c_code << "." ; 
169
170 // for compacted disk store. need to revisit. not working.
171 //   out << 0 << "." ;
172
173    out << v_i_code;
174    return done;
175 }
176
177 io_status oid_t::asciiIn(istream& in) 
178 {
179    _asciiIn(in);
180
181    if ( in.get() != '\n' ) {
182        throw(stringException("'\\n' expected"));
183    }
184
185    return done;
186 }
187
188 io_status oid_t::_asciiIn(istream& in) 
189 {
190    if ( ! cc_is_digit(in) )
191       throw (stringException("a digit is expected"));
192
193    if ( v_c_code == 0 )
194       in >> v_c_code;
195    else {
196       c_code_t y;
197       in >> y;
198       if ( v_c_code != y )
199          return fail;
200    }
201
202    int mid = in.get();
203
204    if ( mid == '\n') {
205       v_i_code = 0;
206       in.putback(char(mid));
207    } else {
208
209       if ( mid != '.' ) {
210           debug(cerr, v_c_code);
211           debug(cerr, mid);
212           throw(stringException("'.' expected"));
213       }
214     
215       if ( ! cc_is_digit(in) )
216          throw (stringException("a digit expected"));
217
218       in >> v_i_code;
219
220    }
221
222    return done;
223 }
224
225 ostream& operator<<(ostream& out, const oid_t& id) 
226 {
227    id.asciiOut(out);
228    return out;
229 }
230
231 void oid_t::to_char_string(char* sink, Boolean swap_order) const
232 {
233    if ( sink == 0 )
234        throw(stringException("NULL string pointer"));
235
236 ////////////////////////////////////////////
237 // 4/28/93.  Do not save c_code in an oid_t.
238 ////////////////////////////////////////////
239 /*
240    //bcopy((char*)&c_code, sink, sizeof(c_code));
241    memcpy(sink, (char*)&c_code, sizeof(c_code));
242
243    //bcopy((char*)&i_code, 
244    //      sink+sizeof(c_code), sizeof(i_code));
245    memcpy(
246          sink+sizeof(c_code), 
247          (char*)&i_code, 
248          sizeof(i_code));
249 */
250
251    if ( swap_order == true ) {
252       i_code_t x = v_i_code;
253 #ifdef __osf__
254       ORDER_SWAP_INT(x);
255 #else
256       ORDER_SWAP_LONG(x);
257 #endif
258       memcpy(sink, (char*)&x, sizeof(x));
259    } else 
260       memcpy(sink, (char*)&v_i_code, sizeof(v_i_code));
261 }
262
263
264 int oid_t::cdr_sizeof()
265 {
266    //return sizeof(c_code) + sizeof(i_code);
267 // 4/30/93. save no c_code
268    return sizeof(v_i_code);
269 }
270
271 io_status oid_t::cdrOut(buffer& buf)
272 {
273 // 4/30/93. save no c_code
274 //   buf.put(c_code);
275    buf.put(v_i_code);
276    return done;
277 }
278    
279 io_status oid_t::cdrIn(buffer& buf, c_code_t c_code_to_use)
280 {
281 // 4/30/93. save no c_code
282 //   buf.get(v_c_code);
283    buf.get(v_i_code);
284    v_c_code = c_code_to_use;
285    return done;
286 }
287
288