inv_lists.C 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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: inv_lists.cc /main/5 1996/07/18 14:37:46 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 "index/inv_lists.h"
  50. #include "utility/funcs.h"
  51. inv_lists::inv_lists(c_code_t c_cd) : oid_list(c_cd)
  52. {
  53. //set_mode(HEALTH, true);
  54. }
  55. inv_lists::~inv_lists()
  56. {
  57. }
  58. Boolean inv_lists::insert_list_pinned(int index, oid_list& lst)
  59. {
  60. if ( lst.count() == 0 ) {
  61. throw(boundaryException(0, lst.count(), index));
  62. }
  63. oid_list_handler list_hd(lst.count(), storage_ptr);
  64. for ( int i=1; i<=lst.count(); i++ )
  65. list_hd -> update_component(i, lst(i)) ;
  66. oid_list::update_component(index, list_hd.its_oid()) ;
  67. set_mode(UPDATE, true);
  68. return true;
  69. }
  70. Boolean inv_lists::append_list(oid_list& lst)
  71. {
  72. /*
  73. MESSAGE(cerr, "append a inv list");
  74. lst.asciiOut(cerr); cerr << "\n";
  75. */
  76. handler hd(OID_LIST_CODE, storage_ptr);
  77. oid_list_handler& lst_handler = *(oid_list_handler*)&hd;
  78. lst_handler -> expand_space(lst.count());
  79. for ( int i=1; i<=lst.count(); i++ )
  80. lst_handler -> update_component(i, lst(i)) ;
  81. oid_list::insert_component(hd.its_oid()) ;
  82. set_mode(UPDATE, true);
  83. return true;
  84. }
  85. Boolean inv_lists::remove_list(int index)
  86. {
  87. update_component(index, ground);
  88. return true;
  89. }
  90. oid_list_handler* inv_lists::get_list(int index)
  91. {
  92. oid_t x((*this)(index));
  93. if ( x.eq(ground) == true ) {
  94. return 0;
  95. } else {
  96. return new oid_list_handler(x, storage_ptr);
  97. }
  98. }
  99. /*
  100. oid_list_handler* inv_lists::get_list(mmdb_pos_t)
  101. {
  102. throw( stringException("get_list(): not implemented yet"));
  103. return 0;
  104. }
  105. */
  106. ostream& operator <<(ostream&s, inv_lists& o)
  107. {
  108. for (int i=0; i < o.count(); i++) {
  109. oid_list_handler* x = o.get_list(i);
  110. (*x) -> asciiOut(s);
  111. delete x;
  112. s << "\n";
  113. }
  114. return s;
  115. }
  116. void inv_lists::insert_to_list(int index, oid_t& id)
  117. {
  118. if ( !INRANGE(index, 1, (int) v_sz) ) {
  119. throw(boundaryException(1, v_sz, index));
  120. }
  121. oid_t list_id = (*this)(index);
  122. /*
  123. MESSAGE(cerr, "inv::insert");
  124. debug(cerr, index);
  125. */
  126. if ( INRANGE((short)list_id.ccode(), 0, 1) &&
  127. id.ccode() != OID_LIST_CODE
  128. ) {
  129. update_component(index, id);
  130. } else {
  131. if ( list_id.ccode() != OID_LIST_CODE ) {
  132. oid_list_handler y(OID_LIST_CODE, storage_ptr);
  133. y -> insert_component(list_id);
  134. update_component(index, y.its_oid());
  135. y -> insert_component(id);
  136. } else {
  137. oid_list_handler y( list_id, storage_ptr);
  138. y -> insert_component(id);
  139. }
  140. }
  141. }
  142. MMDB_BODIES(inv_lists)
  143. HANDLER_BODIES(inv_lists)