collectionIterator.C 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. // $XConsortium: collectionIterator.cc /main/4 1996/06/11 17:28:28 cde-hal $
  24. #include "oliasdb/collectionIterator.h"
  25. #include "oliasdb/olias_consts.h"
  26. #include "oliasdb/node_hd.h"
  27. #include "oliasdb/stylesheet_hd.h"
  28. #include "oliasdb/graphic_hd.h"
  29. #include "oliasdb/locator_hd.h"
  30. collectionIterator::collectionIterator(info_base* base, int position) :
  31. f_set_ptr(base -> get_set(position)), f_base(base), f_index(-1)
  32. {
  33. if ( f_set_ptr == 0 )
  34. throw(stringException("can't find set"));
  35. }
  36. collectionIterator::~collectionIterator()
  37. {
  38. }
  39. unsigned int collectionIterator::operator++()
  40. {
  41. if ( f_index == -1 ) {
  42. f_index = 0;
  43. return 1;
  44. }
  45. if ( f_index == -2 ) {
  46. MESSAGE(cerr, "can't advance iterator any more");
  47. return 0;
  48. }
  49. if ( (*f_set_ptr) -> count() - 1 == f_index ) {
  50. f_index = -2;
  51. return 0;
  52. } else {
  53. f_index++;
  54. return 1;
  55. }
  56. }
  57. oid_t collectionIterator::get_oid(int index)
  58. {
  59. c_index_handler* x = (*f_set_ptr) -> get_index_ptr(index);
  60. if ( x == 0 )
  61. throw(stringException("bad internal index"));
  62. return (*x) -> first_of_invlist(f_index);
  63. }
  64. nodeCollectionIterator::nodeCollectionIterator(info_base* base) :
  65. collectionIterator(base, NODE_SET_POS)
  66. {
  67. }
  68. nodeCollectionIterator::~nodeCollectionIterator()
  69. {
  70. }
  71. const char* nodeCollectionIterator::get_locator()
  72. {
  73. oid_t id = get_oid(1);
  74. node_smart_ptr node(f_base, id);
  75. return node.locator();
  76. }
  77. stylesheetCollectionIterator::stylesheetCollectionIterator(info_base* base) :
  78. collectionIterator(base, STYLESHEET_SET_POS)
  79. {
  80. }
  81. stylesheetCollectionIterator::~stylesheetCollectionIterator()
  82. {
  83. }
  84. const char* stylesheetCollectionIterator::get_locator()
  85. {
  86. oid_t id = get_oid(1);
  87. stylesheet_smart_ptr ss(f_base, id);
  88. return ss.name();
  89. }
  90. graphicCollectionIterator::graphicCollectionIterator(info_base* base) :
  91. collectionIterator(base, GRAPHIC_SET_POS)
  92. {
  93. }
  94. graphicCollectionIterator::~graphicCollectionIterator()
  95. {
  96. }
  97. const char* graphicCollectionIterator::get_locator()
  98. {
  99. oid_t id = get_oid(1);
  100. graphic_smart_ptr gr(f_base, id);
  101. return gr.locator();
  102. }
  103. locatorCollectionIterator::locatorCollectionIterator(info_base* base) :
  104. collectionIterator(base, LOCATOR_SET_POS)
  105. {
  106. }
  107. locatorCollectionIterator::~locatorCollectionIterator()
  108. {
  109. }
  110. const char* locatorCollectionIterator::get_locator()
  111. {
  112. oid_t id = get_oid(1);
  113. locator_smart_ptr lc(f_base, id);
  114. return lc.inside_node_locator_str();
  115. }