oid_t.C 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 libraries 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. #include "object/oid_t.h"
  50. #ifdef C_API
  51. oid_t* ground_ptr = 0;
  52. #else
  53. oid_t ground(c_code_t(0), i_code_t(0));
  54. #endif
  55. /* inline
  56. oid_t::oid_t()
  57. {
  58. }
  59. */
  60. /* inline
  61. oid_t::oid_t(c_code_t c, i_code_t i) :
  62. v_c_code(c), v_i_code(i), v_e_code(0)
  63. {
  64. }
  65. */
  66. /* inline
  67. oid_t::oid_t(const oid_t& x)
  68. {
  69. v_e_code = x.v_e_code;
  70. v_c_code = x.v_c_code;
  71. v_i_code = x.v_i_code;
  72. }
  73. */
  74. oid_t::oid_t(const char* source, Boolean ascii_format, Boolean swap_order)
  75. {
  76. if ( source == 0 )
  77. throw(stringException("NULL string pointer"));
  78. if ( ascii_format == false ) {
  79. // 4/28/93. do not save c_code in an oid_t.
  80. v_c_code = 1;
  81. memcpy((char*)&v_i_code, source, sizeof(v_i_code));
  82. if ( swap_order == true )
  83. ORDER_SWAP_LONG(v_i_code);
  84. } else {
  85. istringstream in((char*)source);
  86. in >> v_c_code;
  87. if ( in.get() == '\n') {
  88. v_i_code = 0;
  89. } else {
  90. in >> v_i_code;
  91. }
  92. }
  93. v_e_code = 0;
  94. /*
  95. MESSAGE(cerr, "constr oid_t using a string");
  96. debug(cerr, v_c_code);
  97. debug(cerr, v_i_code);
  98. */
  99. }
  100. /* inline
  101. oid_t::~oid_t()
  102. {
  103. }
  104. */
  105. /* inline
  106. void oid_t::become(const oid_t& x)
  107. {
  108. v_e_code = x.v_e_code;
  109. v_c_code = x.v_c_code;
  110. v_i_code = x.v_i_code;
  111. }
  112. */
  113. Boolean oid_t::eq(const oid_t& x) const
  114. {
  115. if ( v_i_code == x.v_i_code ) {
  116. if ( v_c_code == 1 || x.v_c_code == 1 )
  117. return true;
  118. else {
  119. if ( v_c_code == x.v_c_code )
  120. return true;
  121. else
  122. return false;
  123. }
  124. } else
  125. return false;
  126. }
  127. Boolean oid_t::ls(const oid_t & x) const
  128. {
  129. if ( v_c_code != 1 && x.v_c_code != 1 && v_c_code >= x.v_c_code )
  130. return false;
  131. else
  132. if ( v_i_code >= x.v_i_code )
  133. return false;
  134. else
  135. return true;
  136. }
  137. // Static function to compute a hash code for an oid_t
  138. unsigned oid_t::hash(const oid_t& id)
  139. {
  140. return unsigned(id.icode()) + unsigned(id.ccode());
  141. }
  142. io_status oid_t::asciiOut(ostream& out) const
  143. {
  144. out << v_c_code << "." ;
  145. // for compacted disk store. need to revisit. not working.
  146. // out << 0 << "." ;
  147. out << v_i_code;
  148. return done;
  149. }
  150. io_status oid_t::asciiIn(istream& in)
  151. {
  152. _asciiIn(in);
  153. if ( in.get() != '\n' ) {
  154. throw(stringException("'\\n' expected"));
  155. }
  156. return done;
  157. }
  158. io_status oid_t::_asciiIn(istream& in)
  159. {
  160. if ( ! cc_is_digit(in) )
  161. throw (stringException("a digit is expected"));
  162. if ( v_c_code == 0 )
  163. in >> v_c_code;
  164. else {
  165. c_code_t y;
  166. in >> y;
  167. if ( v_c_code != y )
  168. return fail;
  169. }
  170. int mid = in.get();
  171. if ( mid == '\n') {
  172. v_i_code = 0;
  173. in.putback(char(mid));
  174. } else {
  175. if ( mid != '.' ) {
  176. debug(cerr, v_c_code);
  177. debug(cerr, mid);
  178. throw(stringException("'.' expected"));
  179. }
  180. if ( ! cc_is_digit(in) )
  181. throw (stringException("a digit expected"));
  182. in >> v_i_code;
  183. }
  184. return done;
  185. }
  186. ostream& operator<<(ostream& out, const oid_t& id)
  187. {
  188. id.asciiOut(out);
  189. return out;
  190. }
  191. void oid_t::to_char_string(char* sink, Boolean swap_order) const
  192. {
  193. if ( sink == 0 )
  194. throw(stringException("NULL string pointer"));
  195. ////////////////////////////////////////////
  196. // 4/28/93. Do not save c_code in an oid_t.
  197. ////////////////////////////////////////////
  198. /*
  199. //bcopy((char*)&c_code, sink, sizeof(c_code));
  200. memcpy(sink, (char*)&c_code, sizeof(c_code));
  201. //bcopy((char*)&i_code,
  202. // sink+sizeof(c_code), sizeof(i_code));
  203. memcpy(
  204. sink+sizeof(c_code),
  205. (char*)&i_code,
  206. sizeof(i_code));
  207. */
  208. if ( swap_order == true ) {
  209. i_code_t x = v_i_code;
  210. ORDER_SWAP_LONG(x);
  211. memcpy(sink, (char*)&x, sizeof(x));
  212. } else
  213. memcpy(sink, (char*)&v_i_code, sizeof(v_i_code));
  214. }
  215. int oid_t::cdr_sizeof()
  216. {
  217. //return sizeof(c_code) + sizeof(i_code);
  218. // 4/30/93. save no c_code
  219. return sizeof(v_i_code);
  220. }
  221. io_status oid_t::cdrOut(buffer& buf)
  222. {
  223. // 4/30/93. save no c_code
  224. // buf.put(c_code);
  225. buf.put(v_i_code);
  226. return done;
  227. }
  228. io_status oid_t::cdrIn(buffer& buf, c_code_t c_code_to_use)
  229. {
  230. // 4/30/93. save no c_code
  231. // buf.get(v_c_code);
  232. buf.get(v_i_code);
  233. v_c_code = c_code_to_use;
  234. return done;
  235. }