worksheet_impl.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Copyright (c) 2014-2021 Thomas Fussell
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE
  20. //
  21. // @license: http://www.opensource.org/licenses/mit-license.php
  22. // @author: see AUTHORS file
  23. #pragma once
  24. #include <string>
  25. #include <unordered_map>
  26. #include <vector>
  27. #include <xlnt/drawing/spreadsheet_drawing.hpp>
  28. #include <xlnt/packaging/ext_list.hpp>
  29. #include <xlnt/workbook/named_range.hpp>
  30. #include <xlnt/worksheet/column_properties.hpp>
  31. #include <xlnt/worksheet/header_footer.hpp>
  32. #include <xlnt/worksheet/phonetic_pr.hpp>
  33. #include <xlnt/worksheet/range.hpp>
  34. #include <xlnt/worksheet/range_reference.hpp>
  35. #include <xlnt/worksheet/row_properties.hpp>
  36. #include <xlnt/worksheet/sheet_format_properties.hpp>
  37. #include <xlnt/worksheet/sheet_view.hpp>
  38. #include <xlnt/worksheet/print_options.hpp>
  39. #include <xlnt/worksheet/sheet_pr.hpp>
  40. #include <detail/implementations/cell_impl.hpp>
  41. namespace xlnt {
  42. class workbook;
  43. namespace detail {
  44. struct worksheet_impl
  45. {
  46. worksheet_impl(workbook *parent_workbook, std::size_t id, const std::string &title)
  47. : parent_(parent_workbook),
  48. id_(id),
  49. title_(title)
  50. {
  51. }
  52. worksheet_impl(const worksheet_impl &other)
  53. {
  54. *this = other;
  55. }
  56. void operator=(const worksheet_impl &other)
  57. {
  58. parent_ = other.parent_;
  59. id_ = other.id_;
  60. title_ = other.title_;
  61. format_properties_ = other.format_properties_;
  62. column_properties_ = other.column_properties_;
  63. row_properties_ = other.row_properties_;
  64. cell_map_ = other.cell_map_;
  65. page_setup_ = other.page_setup_;
  66. auto_filter_ = other.auto_filter_;
  67. page_margins_ = other.page_margins_;
  68. merged_cells_ = other.merged_cells_;
  69. named_ranges_ = other.named_ranges_;
  70. phonetic_properties_ = other.phonetic_properties_;
  71. header_footer_ = other.header_footer_;
  72. print_title_cols_ = other.print_title_cols_;
  73. print_title_rows_ = other.print_title_rows_;
  74. print_area_ = other.print_area_;
  75. views_ = other.views_;
  76. column_breaks_ = other.column_breaks_;
  77. row_breaks_ = other.row_breaks_;
  78. extension_list_ = other.extension_list_;
  79. sheet_properties_ = other.sheet_properties_;
  80. print_options_ = other.print_options_;
  81. for (auto &cell : cell_map_)
  82. {
  83. cell.second.parent_ = this;
  84. }
  85. }
  86. workbook *parent_;
  87. bool operator==(const worksheet_impl& rhs) const
  88. {
  89. return id_ == rhs.id_
  90. && title_ == rhs.title_
  91. && format_properties_ == rhs.format_properties_
  92. && column_properties_ == rhs.column_properties_
  93. && row_properties_ == rhs.row_properties_
  94. && cell_map_ == rhs.cell_map_
  95. && page_setup_ == rhs.page_setup_
  96. && auto_filter_ == rhs.auto_filter_
  97. && page_margins_ == rhs.page_margins_
  98. && merged_cells_ == rhs.merged_cells_
  99. && named_ranges_ == rhs.named_ranges_
  100. && phonetic_properties_ == rhs.phonetic_properties_
  101. && header_footer_ == rhs.header_footer_
  102. && print_title_cols_ == rhs.print_title_cols_
  103. && print_title_rows_ == rhs.print_title_rows_
  104. && print_area_ == rhs.print_area_
  105. && views_ == rhs.views_
  106. && column_breaks_ == rhs.column_breaks_
  107. && row_breaks_ == rhs.row_breaks_
  108. && comments_ == rhs.comments_
  109. && print_options_ == rhs.print_options_
  110. && sheet_properties_ == rhs.sheet_properties_
  111. && extension_list_ == rhs.extension_list_;
  112. }
  113. std::size_t id_;
  114. std::string title_;
  115. sheet_format_properties format_properties_;
  116. std::unordered_map<column_t, column_properties> column_properties_;
  117. std::unordered_map<row_t, row_properties> row_properties_;
  118. std::unordered_map<cell_reference, cell_impl> cell_map_;
  119. optional<page_setup> page_setup_;
  120. optional<range_reference> auto_filter_;
  121. optional<page_margins> page_margins_;
  122. std::vector<range_reference> merged_cells_;
  123. std::unordered_map<std::string, named_range> named_ranges_;
  124. optional<phonetic_pr> phonetic_properties_;
  125. optional<header_footer> header_footer_;
  126. optional<std::pair<column_t, column_t>> print_title_cols_;
  127. optional<std::pair<row_t, row_t>> print_title_rows_;
  128. optional<range_reference> print_area_;
  129. std::vector<sheet_view> views_;
  130. std::vector<column_t> column_breaks_;
  131. std::vector<row_t> row_breaks_;
  132. std::unordered_map<std::string, comment> comments_;
  133. optional<print_options> print_options_;
  134. optional<sheet_pr> sheet_properties_;
  135. optional<ext_list> extension_list_;
  136. std::string drawing_rel_id_;
  137. optional<drawing::spreadsheet_drawing> drawing_;
  138. };
  139. } // namespace detail
  140. } // namespace xlnt