cset.C 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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: cset.cc /main/5 1996/06/11 17:23:58 cde-hal $
  25. *
  26. * Copyright (c) 1992 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/cset.h"
  50. #include "utility/xtime.h"
  51. cset::cset(c_code_t c_cd): composite(c_cd)
  52. {
  53. num_indices = 0;
  54. indices = 0;
  55. set_mode(SWAP_ALLOWED, false);
  56. }
  57. void cset::init_data_member(c_index_handlerPtr* index_arrray,
  58. int iptrs
  59. )
  60. {
  61. indices = index_arrray;
  62. num_indices = iptrs;
  63. set_mode(HEALTH, true);
  64. #ifdef MEMORY_MAPPED
  65. set_mode(UPDATE, true);
  66. #endif
  67. }
  68. cset::~cset()
  69. {
  70. /*
  71. MESSAGE(cerr, "~cset() called.");
  72. debug(cerr, my_oid());
  73. debug(cerr, num_indices);
  74. debug(cerr, int(this));
  75. MESSAGE(cerr, "~cset() called.");
  76. debug(cerr, num_indices);
  77. */
  78. delete indices;
  79. }
  80. handler* cset::get_component(int index)
  81. {
  82. if ( indices[0] == 0 )
  83. return 0;
  84. oid_t id_ptr = (*indices[0]) -> first_of_invlist(index);
  85. handler* y = new handler(id_ptr, storage_ptr);
  86. return y;
  87. }
  88. oid_list_handler* cset::get_locs(handler& query, int index)
  89. {
  90. if ( !INRANGE(index, 0, (int) num_indices-1) ) {
  91. MESSAGE(cerr, "cset::get_locs(): invalid index");
  92. throw(boundaryException(0, num_indices-1, index));
  93. }
  94. if ( indices[index] == 0 ) {
  95. MESSAGE(cerr, "cset::get_locs(): invalid index");
  96. throw(stringException("NULL index ptr"));
  97. }
  98. return (*indices[index]) -> get_loc_list(query);
  99. }
  100. oid_t cset::get_first_oid(const handler& query, int index)
  101. {
  102. if ( !INRANGE(index, 0, (int) num_indices-1) ) {
  103. MESSAGE(cerr, "cset::get_first_oid(): invalid index");
  104. throw(boundaryException(0, num_indices-1, index));
  105. }
  106. if ( indices[index] == 0 ) {
  107. MESSAGE(cerr, "cset::get_first_oid(): invalid index");
  108. throw(stringException("NULL index ptr"));
  109. }
  110. return (*indices[index]) -> first_of_invlist(query);
  111. }
  112. c_index_handler* cset::get_index_ptr(int index)
  113. {
  114. if ( !INRANGE(index, 0, (int) num_indices-1) ) {
  115. MESSAGE(cerr, "cset::get_index_ptr(): invalid index");
  116. throw(boundaryException(0, num_indices-1, index));
  117. }
  118. return indices[index];
  119. }
  120. void cset::batch_index_begin()
  121. {
  122. for ( unsigned int i=0; i<num_indices; i++ ) {
  123. if ( indices[i] != 0 ) {
  124. (*indices[i]) -> batch_index_begin();
  125. }
  126. }
  127. }
  128. void cset::batch_index_end()
  129. {
  130. for ( unsigned int i=0; i<num_indices; i++ ) {
  131. if ( indices[i] != 0 ) {
  132. (*indices[i]) -> batch_index_end();
  133. }
  134. }
  135. }
  136. io_status cset::asciiIn(istream& in)
  137. {
  138. batch_index_begin();
  139. io_status ok = batch_asciiIn(in);
  140. batch_index_end();
  141. return ok;
  142. }
  143. io_status cset::batch_asciiIn(istream& in)
  144. {
  145. handler* root_hd_ptr = 0;
  146. /*
  147. #ifdef DEBUG
  148. xtime tmr;
  149. float f1;
  150. long f2;
  151. tmr.start();
  152. #endif
  153. */
  154. char ccode_buf[LBUFSIZ];
  155. int c;
  156. //fprintf(stderr, "batch_asciiIn() : start looping \n");
  157. while ( (c = in.get()) != EOF ) {
  158. in.putback(c);
  159. in.getline(ccode_buf, LBUFSIZ);
  160. //fprintf(stderr, "ccode_buf=%s\n", ccode_buf);
  161. char* x = strrchr(ccode_buf, 'L');
  162. if ( x ) *x = 0;
  163. int ccode;
  164. sscanf(ccode_buf, "%u", &ccode);
  165. //in >> ccode ;
  166. //fprintf(stderr, "ccode=%d\n", ccode);
  167. root_hd_ptr = new handler(ccode, storage_ptr);
  168. if ( filter::assigned() == false )
  169. (*root_hd_ptr) -> asciiIn(in);
  170. else
  171. (*root_hd_ptr) -> asciiIn(filter::filter_func()(in));
  172. root_hd_ptr->commit();
  173. insert_object(*root_hd_ptr);
  174. /*
  175. #ifdef DEBUG
  176. if ( v_sz % 1000 == 0 && v_sz != 0 ) {
  177. tmr.stop(f1, f2);
  178. debug(cerr, f1);
  179. debug(cerr, f2);
  180. debug(cerr, v_sz);
  181. tmr.start();
  182. }
  183. #endif
  184. */
  185. //(*root_hd_ptr)-> asciiOut(cerr);
  186. /*
  187. (root_hd_ptr -> its_oid()).asciiOut(cerr);
  188. storage_ptr -> asciiOut(cerr);
  189. MESSAGE(cerr, "\n========");
  190. */
  191. delete root_hd_ptr;
  192. }
  193. return done;
  194. }
  195. io_status cset::asciiOut(ostream&)
  196. {
  197. return done;
  198. }
  199. Boolean
  200. cset::insert_object(const handler& new_object)
  201. {
  202. /*
  203. MESSAGE(cerr, "in insert_object()");
  204. new_object.its_oid().asciiOut(cerr); cerr << "\n";
  205. */
  206. if ( indices[0] != 0 ) {
  207. #ifdef A16_BROWSER
  208. handler* zz = (handler*)&new_object;
  209. (*indices[0]) -> insert_key_loc(new_object, zz -> its_oid());
  210. #else
  211. (*indices[0]) -> insert_key_loc(new_object, new_object.its_oid());
  212. #endif
  213. }
  214. for ( unsigned int i = 1; i < num_indices; i++ ) {
  215. if ( indices[i] == 0 )
  216. continue;
  217. handler* y = (*(composite_handler*)&new_object)
  218. -> get_component(i);
  219. if ( y == 0 ) continue;
  220. #ifdef A16_BROWSER
  221. handler* ww = (handler*)&new_object;
  222. (*indices[i]) -> insert_key_loc(*y, ww -> its_oid());
  223. #else
  224. (*indices[i]) -> insert_key_loc(*y, new_object.its_oid());
  225. #endif
  226. if ( !(y -> its_oid() == new_object.its_oid()) )
  227. delete y;
  228. }
  229. v_sz++;
  230. set_mode(UPDATE, true);
  231. return true;
  232. }
  233. Boolean cset::remove_component(const oid_t& x_oid)
  234. {
  235. handler* x = new handler(x_oid, storage_ptr);
  236. for ( unsigned int i = 1; i < num_indices; i++ ) {
  237. if ( indices[i] == 0 )
  238. continue;
  239. handler* y = (*(composite_handler*)x) -> get_component(i);
  240. (*indices[i]) -> remove_loc(*y, x_oid);
  241. y -> destroy();
  242. delete y;
  243. }
  244. x -> destroy();
  245. delete x;
  246. v_sz--;
  247. set_mode(UPDATE, true);
  248. return true;
  249. }
  250. // update old component object 'old_comp_obj' to new
  251. // component object 'new_comp_obj'.
  252. // variable 'index' holds the index of the index object
  253. // effected. 'obj_pos' is the id of the
  254. // main object, of which old_comp_obj is a part.
  255. Boolean
  256. cset::update_index(handler* old_comp_obj, handler* new_comp_obj,
  257. int index,
  258. oid_t& main_obj_oid)
  259. {
  260. if ( !INRANGE(index, 1, (int) num_indices-1) ) {
  261. throw(boundaryException(1, num_indices-1, index));
  262. }
  263. if ( indices[index] ) {
  264. return (*indices[index]) -> update_streampos
  265. (
  266. *old_comp_obj,
  267. *new_comp_obj,
  268. main_obj_oid.icode()
  269. );
  270. } else
  271. return true;
  272. }
  273. int cset::cdr_sizeof()
  274. {
  275. return composite::cdr_sizeof() + sizeof(num_indices);
  276. }
  277. io_status cset::cdrOut(buffer& buf)
  278. {
  279. composite::cdrOut(buf);
  280. buf.put(num_indices);
  281. return done;
  282. }
  283. io_status cset::cdrIn(buffer& buf)
  284. {
  285. composite::cdrIn(buf);
  286. buf.get(num_indices);
  287. return done;
  288. }
  289. void cset::commit()
  290. {
  291. for ( unsigned int i = 1; i < num_indices; i++ ) {
  292. if ( indices[i] )
  293. indices[i] -> commit();
  294. }
  295. }
  296. MMDB_BODIES(cset)
  297. HANDLER_BODIES(cset)