2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * $XConsortium: oid_t.cc /main/4 1996/07/18 14:44:11 drk $
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
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
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.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "object/oid_t.h"
54 oid_t* ground_ptr = 0;
56 oid_t ground(c_code_t(0), i_code_t(0));
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)
74 oid_t::oid_t(const oid_t& x)
76 v_e_code = x.v_e_code;
77 v_c_code = x.v_c_code;
78 v_i_code = x.v_i_code;
82 oid_t::oid_t(const char* source, Boolean ascii_format, Boolean swap_order)
85 throw(stringException("NULL string pointer"));
87 if ( ascii_format == false ) {
89 // 4/28/93. do not save c_code in an oid_t.
91 memcpy((char*)&v_i_code, source, sizeof(v_i_code));
93 if ( swap_order == true )
95 ORDER_SWAP_INT(v_i_code);
97 ORDER_SWAP_LONG(v_i_code);
101 istringstream in((char*)source);
105 if ( in.get() == '\n') {
113 MESSAGE(cerr, "constr oid_t using a string");
114 debug(cerr, v_c_code);
115 debug(cerr, v_i_code);
126 void oid_t::become(const oid_t& x)
128 v_e_code = x.v_e_code;
129 v_c_code = x.v_c_code;
130 v_i_code = x.v_i_code;
134 Boolean oid_t::eq(const oid_t& x) const
136 if ( v_i_code == x.v_i_code ) {
137 if ( v_c_code == 1 || x.v_c_code == 1 )
140 if ( v_c_code == x.v_c_code )
149 Boolean oid_t::ls(const oid_t & x) const
151 if ( v_c_code != 1 && x.v_c_code != 1 && v_c_code >= x.v_c_code )
154 if ( v_i_code >= x.v_i_code )
160 // Static function to compute a hash code for an oid_t
161 unsigned oid_t::hash(const oid_t& id)
163 return unsigned(id.icode()) + unsigned(id.ccode());
166 io_status oid_t::asciiOut(ostream& out) const
168 out << v_c_code << "." ;
170 // for compacted disk store. need to revisit. not working.
177 io_status oid_t::asciiIn(istream& in)
181 if ( in.get() != '\n' ) {
182 throw(stringException("'\\n' expected"));
188 io_status oid_t::_asciiIn(istream& in)
190 if ( ! cc_is_digit(in) )
191 throw (stringException("a digit is expected"));
206 in.putback(char(mid));
210 debug(cerr, v_c_code);
212 throw(stringException("'.' expected"));
215 if ( ! cc_is_digit(in) )
216 throw (stringException("a digit expected"));
225 ostream& operator<<(ostream& out, const oid_t& id)
231 void oid_t::to_char_string(char* sink, Boolean swap_order) const
234 throw(stringException("NULL string pointer"));
236 ////////////////////////////////////////////
237 // 4/28/93. Do not save c_code in an oid_t.
238 ////////////////////////////////////////////
240 //bcopy((char*)&c_code, sink, sizeof(c_code));
241 memcpy(sink, (char*)&c_code, sizeof(c_code));
243 //bcopy((char*)&i_code,
244 // sink+sizeof(c_code), sizeof(i_code));
251 if ( swap_order == true ) {
252 i_code_t x = v_i_code;
258 memcpy(sink, (char*)&x, sizeof(x));
260 memcpy(sink, (char*)&v_i_code, sizeof(v_i_code));
264 int oid_t::cdr_sizeof()
266 //return sizeof(c_code) + sizeof(i_code);
267 // 4/30/93. save no c_code
268 return sizeof(v_i_code);
271 io_status oid_t::cdrOut(buffer& buf)
273 // 4/30/93. save no c_code
279 io_status oid_t::cdrIn(buffer& buf, c_code_t c_code_to_use)
281 // 4/30/93. save no c_code
282 // buf.get(v_c_code);
284 v_c_code = c_code_to_use;