tuple.C 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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: tuple.cc /main/4 1996/06/11 17:26:06 cde-hal $
  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/tuple.h"
  50. #define MAX_COMPS 50
  51. mmdb_tuple::mmdb_tuple(c_code_t c_cd) : oid_list(c_cd)
  52. {
  53. }
  54. mmdb_tuple::mmdb_tuple(int comps, c_code_t c_cd) : oid_list(comps, c_cd)
  55. {
  56. }
  57. mmdb_tuple::mmdb_tuple(mmdb_tuple& x) : oid_list(x)
  58. {
  59. }
  60. mmdb_tuple::~mmdb_tuple()
  61. {
  62. }
  63. handler* mmdb_tuple::get_component(int index)
  64. {
  65. //MESSAGE(cerr, "in mmdb_tuple():: get_component()");
  66. //debug(cerr, index);
  67. //debug(cerr, my_oid());
  68. //debug(cerr, int(storage_ptr));
  69. if (!INRANGE(index, 1, (int) v_sz)) {
  70. MESSAGE(cerr, "out of range in mmdb_tuple::get_component()");
  71. throw( boundaryException(1, v_sz, index) );
  72. }
  73. oid_t x = oid_list::operator()(index);
  74. //debug(cerr, x);
  75. //debug(cerr, x.ccode());
  76. //debug(cerr, x.icode());
  77. handler* y = 0;
  78. if ( x.icode() != 0 )
  79. y = new handler(x, storage_ptr);
  80. return y;
  81. }
  82. Boolean mmdb_tuple::pinned_insert(int index, const oid_t& val)
  83. {
  84. //MESSAGE(cerr, "in mmdb_tuple():: pinned_component()");
  85. //debug(cerr, index);
  86. //debug(cerr, val);
  87. return oid_list::update_component(index, val);
  88. }
  89. io_status mmdb_tuple::asciiOut(ostream& out)
  90. {
  91. out << "OID_T:\n";
  92. my_oid().asciiOut(out);
  93. out << "\n";
  94. // debug(cerr, v_sz);
  95. for ( unsigned int i=1; i<=v_sz; i++ ) {
  96. handler* hd_ptr = get_component(i);
  97. if ( hd_ptr == 0 )
  98. continue;
  99. (*hd_ptr) -> asciiOut(out);
  100. out << "\n";
  101. delete hd_ptr;
  102. }
  103. return done;
  104. }
  105. io_status mmdb_tuple::asciiIn(istream& in)
  106. {
  107. /*
  108. MESSAGE(cerr, "in mmdb_tuple asciiIn()");
  109. my_oid().asciiOut(cerr);
  110. MESSAGE(cerr, "\n");
  111. */
  112. int comps; in >> comps;
  113. if ( comps > MAX_COMPS ) {
  114. debug(cerr, comps);
  115. throw(stringException("exceed MAX_COMPS"));
  116. }
  117. //debug(cerr, comps);
  118. int ret = in.get();
  119. if ( ret != '\n' ) {
  120. debug(cerr, ret);
  121. throw(stringException("'\\n' expected"));
  122. }
  123. if ( comps > (int) v_sz ) {
  124. MESSAGE(cerr, "mmdb_tuple asciiIn(): to expand space");
  125. debug(cerr, comps);
  126. debug(cerr, v_sz);
  127. oid_list::expand_space(comps - v_sz);
  128. v_sz = comps;
  129. }
  130. handler *hd_ptr = 0;
  131. for ( int i=1; i<=comps; i++ ) {
  132. c_code_t ccode;
  133. in >> ccode;
  134. if ( in.get() != '\n' ) {
  135. throw(stringException("'\\n' expected"));
  136. }
  137. hd_ptr = new handler(ccode, storage_ptr);
  138. (*hd_ptr) -> asciiIn(in);
  139. pinned_insert(i, hd_ptr -> its_oid());
  140. delete hd_ptr;
  141. }
  142. set_mode(UPDATE, true);
  143. return done;
  144. }
  145. MMDB_BODIES(mmdb_tuple)
  146. HANDLER_BODIES(mmdb_tuple)