worksheet_iterator.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (c) 2014-2021 Thomas Fussell
  2. // Copyright (c) 2010-2015 openpyxl
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE
  21. //
  22. // @license: http://www.opensource.org/licenses/mit-license.php
  23. // @author: see AUTHORS file
  24. #include <xlnt/workbook/workbook.hpp>
  25. #include <xlnt/workbook/worksheet_iterator.hpp>
  26. #include <xlnt/worksheet/worksheet.hpp>
  27. namespace xlnt {
  28. worksheet_iterator::worksheet_iterator(workbook &wb, std::size_t index)
  29. : wb_(&wb), index_(index)
  30. {
  31. }
  32. worksheet_iterator::reference worksheet_iterator::operator*()
  33. {
  34. return (*wb_)[index_];
  35. }
  36. const worksheet_iterator::reference worksheet_iterator::operator*() const
  37. {
  38. return (*wb_)[index_];
  39. }
  40. worksheet_iterator &worksheet_iterator::operator++()
  41. {
  42. index_++;
  43. return *this;
  44. }
  45. worksheet_iterator worksheet_iterator::operator++(int)
  46. {
  47. worksheet_iterator old(*wb_, index_);
  48. ++*this;
  49. return old;
  50. }
  51. worksheet_iterator &worksheet_iterator::operator--()
  52. {
  53. --index_;
  54. return *this;
  55. }
  56. worksheet_iterator worksheet_iterator::operator--(int)
  57. {
  58. worksheet_iterator old(*wb_, index_);
  59. --(*this);
  60. return old;
  61. }
  62. bool worksheet_iterator::operator==(const worksheet_iterator &comparand) const
  63. {
  64. return index_ == comparand.index_ && wb_ == comparand.wb_;
  65. }
  66. bool worksheet_iterator::operator!=(const worksheet_iterator &comparand) const
  67. {
  68. return !(*this == comparand);
  69. }
  70. const_worksheet_iterator::const_worksheet_iterator(const workbook &wb, std::size_t index)
  71. : wb_(&wb), index_(index)
  72. {
  73. }
  74. const const_worksheet_iterator::reference const_worksheet_iterator::operator*() const
  75. {
  76. return wb_->sheet_by_index(index_);
  77. }
  78. const_worksheet_iterator &const_worksheet_iterator::operator++()
  79. {
  80. index_++;
  81. return *this;
  82. }
  83. const_worksheet_iterator const_worksheet_iterator::operator++(int)
  84. {
  85. const_worksheet_iterator old(*wb_, index_);
  86. ++*this;
  87. return old;
  88. }
  89. const_worksheet_iterator &const_worksheet_iterator::operator--()
  90. {
  91. --index_;
  92. return *this;
  93. }
  94. const_worksheet_iterator const_worksheet_iterator::operator--(int)
  95. {
  96. const_worksheet_iterator old(*wb_, index_);
  97. --(*this);
  98. return old;
  99. }
  100. bool const_worksheet_iterator::operator==(const const_worksheet_iterator &comparand) const
  101. {
  102. return index_ == comparand.index_ && wb_ == comparand.wb_;
  103. }
  104. bool const_worksheet_iterator::operator!=(const const_worksheet_iterator &comparand) const
  105. {
  106. return !(*this == comparand);
  107. }
  108. } // namespace xlnt