workbook_impl.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <list>
  25. #include <string>
  26. #include <unordered_map>
  27. #include <vector>
  28. #include <detail/implementations/stylesheet.hpp>
  29. #include <detail/implementations/worksheet_impl.hpp>
  30. #include <xlnt/packaging/ext_list.hpp>
  31. #include <xlnt/packaging/manifest.hpp>
  32. #include <xlnt/utils/datetime.hpp>
  33. #include <xlnt/utils/variant.hpp>
  34. #include <xlnt/workbook/calculation_properties.hpp>
  35. #include <xlnt/workbook/theme.hpp>
  36. #include <xlnt/workbook/workbook_view.hpp>
  37. #include <xlnt/worksheet/range.hpp>
  38. #include <xlnt/worksheet/range_reference.hpp>
  39. #include <xlnt/worksheet/sheet_view.hpp>
  40. namespace xlnt {
  41. namespace detail {
  42. struct worksheet_impl;
  43. struct workbook_impl
  44. {
  45. workbook_impl() : base_date_(calendar::windows_1900)
  46. {
  47. }
  48. workbook_impl(const workbook_impl &other)
  49. : active_sheet_index_(other.active_sheet_index_),
  50. worksheets_(other.worksheets_),
  51. shared_strings_ids_(other.shared_strings_ids_),
  52. shared_strings_values_(other.shared_strings_values_),
  53. stylesheet_(other.stylesheet_),
  54. manifest_(other.manifest_),
  55. theme_(other.theme_),
  56. core_properties_(other.core_properties_),
  57. extended_properties_(other.extended_properties_),
  58. custom_properties_(other.custom_properties_),
  59. view_(other.view_),
  60. code_name_(other.code_name_),
  61. file_version_(other.file_version_)
  62. {
  63. }
  64. workbook_impl &operator=(const workbook_impl &other)
  65. {
  66. active_sheet_index_ = other.active_sheet_index_;
  67. worksheets_.clear();
  68. std::copy(other.worksheets_.begin(), other.worksheets_.end(), back_inserter(worksheets_));
  69. shared_strings_ids_ = other.shared_strings_ids_;
  70. shared_strings_values_ = other.shared_strings_values_;
  71. theme_ = other.theme_;
  72. manifest_ = other.manifest_;
  73. sheet_title_rel_id_map_ = other.sheet_title_rel_id_map_;
  74. sheet_hidden_ = other.sheet_hidden_;
  75. view_ = other.view_;
  76. code_name_ = other.code_name_;
  77. file_version_ = other.file_version_;
  78. core_properties_ = other.core_properties_;
  79. extended_properties_ = other.extended_properties_;
  80. custom_properties_ = other.custom_properties_;
  81. return *this;
  82. }
  83. bool operator==(const workbook_impl &other)
  84. {
  85. return active_sheet_index_ == other.active_sheet_index_
  86. && worksheets_ == other.worksheets_
  87. && shared_strings_ids_ == other.shared_strings_ids_
  88. && stylesheet_ == other.stylesheet_
  89. && base_date_ == other.base_date_
  90. && title_ == other.title_
  91. && manifest_ == other.manifest_
  92. && theme_ == other.theme_
  93. && images_ == other.images_
  94. && binaries_ == other.binaries_
  95. && core_properties_ == other.core_properties_
  96. && extended_properties_ == other.extended_properties_
  97. && custom_properties_ == other.custom_properties_
  98. && sheet_title_rel_id_map_ == other.sheet_title_rel_id_map_
  99. && sheet_hidden_ == other.sheet_hidden_
  100. && view_ == other.view_
  101. && code_name_ == other.code_name_
  102. && file_version_ == other.file_version_
  103. && calculation_properties_ == other.calculation_properties_
  104. && abs_path_ == other.abs_path_
  105. && arch_id_flags_ == other.arch_id_flags_
  106. && extensions_ == other.extensions_;
  107. }
  108. optional<std::size_t> active_sheet_index_;
  109. std::list<worksheet_impl> worksheets_;
  110. std::unordered_map<rich_text, std::size_t, rich_text_hash> shared_strings_ids_;
  111. std::vector<rich_text> shared_strings_values_;
  112. optional<stylesheet> stylesheet_;
  113. calendar base_date_;
  114. optional<std::string> title_;
  115. manifest manifest_;
  116. optional<theme> theme_;
  117. std::unordered_map<std::string, std::vector<std::uint8_t>> images_;
  118. std::unordered_map<std::string, std::vector<std::uint8_t>> binaries_;
  119. std::vector<std::pair<xlnt::core_property, variant>> core_properties_;
  120. std::vector<std::pair<xlnt::extended_property, variant>> extended_properties_;
  121. std::vector<std::pair<std::string, variant>> custom_properties_;
  122. std::unordered_map<std::string, std::string> sheet_title_rel_id_map_;
  123. std::vector<bool> sheet_hidden_;
  124. optional<workbook_view> view_;
  125. optional<std::string> code_name_;
  126. struct file_version_t
  127. {
  128. std::string app_name;
  129. std::size_t last_edited;
  130. std::size_t lowest_edited;
  131. std::size_t rup_build;
  132. file_version_t(): last_edited(0), lowest_edited(0), rup_build(0) {
  133. }
  134. bool operator==(const file_version_t& rhs) const
  135. {
  136. return app_name == rhs.app_name
  137. && last_edited == rhs.last_edited
  138. && lowest_edited == rhs.lowest_edited
  139. && rup_build == rhs.rup_build;
  140. }
  141. };
  142. optional<file_version_t> file_version_;
  143. optional<calculation_properties> calculation_properties_;
  144. optional<std::string> abs_path_;
  145. optional<std::size_t> arch_id_flags_;
  146. optional<ext_list> extensions_;
  147. };
  148. } // namespace detail
  149. } // namespace xlnt