Branch data TLA Line data Source code
1 : : // Copyright (c) 2014-2022 Thomas Fussell
2 : : // Copyright (c) 2024-2025 xlnt-community
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 : : #pragma once
25 : :
26 : : #include <list>
27 : : #include <string>
28 : : #include <unordered_map>
29 : : #include <vector>
30 : :
31 : : #include <detail/implementations/stylesheet.hpp>
32 : : #include <detail/implementations/worksheet_impl.hpp>
33 : : #include <xlnt/packaging/ext_list.hpp>
34 : : #include <xlnt/packaging/manifest.hpp>
35 : : #include <xlnt/utils/datetime.hpp>
36 : : #include <xlnt/utils/variant.hpp>
37 : : #include <xlnt/workbook/calculation_properties.hpp>
38 : : #include <xlnt/workbook/theme.hpp>
39 : : #include <xlnt/workbook/workbook_view.hpp>
40 : : #include <xlnt/worksheet/range.hpp>
41 : : #include <xlnt/worksheet/range_reference.hpp>
42 : : #include <xlnt/worksheet/sheet_view.hpp>
43 : :
44 : : namespace xlnt {
45 : : namespace detail {
46 : :
47 : : struct worksheet_impl;
48 : :
49 : : struct workbook_impl
50 : : {
51 :CBC 453 : workbook_impl() : base_date_(calendar::windows_1900)
52 : : {
53 : 453 : }
54 : :
55 : : workbook_impl(const workbook_impl &other)
56 : : : active_sheet_index_(other.active_sheet_index_),
57 : : worksheets_(other.worksheets_),
58 : : shared_strings_ids_(other.shared_strings_ids_),
59 : : shared_strings_values_(other.shared_strings_values_),
60 : : stylesheet_(other.stylesheet_),
61 : : manifest_(other.manifest_),
62 : : theme_(other.theme_),
63 : : core_properties_(other.core_properties_),
64 : : extended_properties_(other.extended_properties_),
65 : : custom_properties_(other.custom_properties_),
66 : : view_(other.view_),
67 : : code_name_(other.code_name_),
68 : : file_version_(other.file_version_)
69 : : {
70 : : }
71 : :
72 : 198 : workbook_impl &operator=(const workbook_impl &other)
73 : : {
74 : 198 : active_sheet_index_ = other.active_sheet_index_;
75 : 198 : worksheets_.clear();
76 : 198 : std::copy(other.worksheets_.begin(), other.worksheets_.end(), back_inserter(worksheets_));
77 : 198 : shared_strings_ids_ = other.shared_strings_ids_;
78 : 198 : shared_strings_values_ = other.shared_strings_values_;
79 : 198 : theme_ = other.theme_;
80 : 198 : manifest_ = other.manifest_;
81 : :
82 : 198 : sheet_title_rel_id_map_ = other.sheet_title_rel_id_map_;
83 : 198 : sheet_hidden_ = other.sheet_hidden_;
84 : 198 : view_ = other.view_;
85 : 198 : code_name_ = other.code_name_;
86 : 198 : file_version_ = other.file_version_;
87 : :
88 : 198 : core_properties_ = other.core_properties_;
89 : 198 : extended_properties_ = other.extended_properties_;
90 : 198 : custom_properties_ = other.custom_properties_;
91 : :
92 : 198 : return *this;
93 : : }
94 : :
95 : 14 : bool operator==(const workbook_impl &other) const
96 : : {
97 : : // not comparing abs_path_
98 : 14 : return active_sheet_index_ == other.active_sheet_index_
99 [ + - ]: 14 : && worksheets_ == other.worksheets_
100 [ + - ]: 14 : && shared_strings_ids_ == other.shared_strings_ids_
101 [ + - ]: 14 : && stylesheet_ == other.stylesheet_
102 [ + - ]: 14 : && base_date_ == other.base_date_
103 [ + - ]: 14 : && title_ == other.title_
104 [ + - ]: 14 : && manifest_ == other.manifest_
105 [ + - ]: 14 : && theme_ == other.theme_
106 [ + - ]: 14 : && images_ == other.images_
107 [ + - ]: 14 : && binaries_ == other.binaries_
108 [ + - ]: 14 : && core_properties_ == other.core_properties_
109 [ + - ]: 14 : && extended_properties_ == other.extended_properties_
110 [ + - ]: 14 : && custom_properties_ == other.custom_properties_
111 [ + - ]: 14 : && sheet_title_rel_id_map_ == other.sheet_title_rel_id_map_
112 [ + - ]: 14 : && sheet_hidden_ == other.sheet_hidden_
113 [ + - ]: 14 : && view_ == other.view_
114 [ + - ]: 14 : && code_name_ == other.code_name_
115 [ + - ]: 14 : && file_version_ == other.file_version_
116 [ + - ]: 14 : && calculation_properties_ == other.calculation_properties_
117 [ + - ]: 14 : && arch_id_flags_ == other.arch_id_flags_
118 [ + - + - ]: 28 : && extensions_ == other.extensions_;
119 : : }
120 : :
121 : : bool operator!=(const workbook_impl &other) const
122 : : {
123 : : return !(*this == other);
124 : : }
125 : :
126 : : optional<std::size_t> active_sheet_index_;
127 : :
128 : : std::list<worksheet_impl> worksheets_;
129 : : std::unordered_map<rich_text, std::size_t, rich_text_hash> shared_strings_ids_;
130 : : std::vector<rich_text> shared_strings_values_;
131 : :
132 : : optional<stylesheet> stylesheet_;
133 : :
134 : : calendar base_date_;
135 : : optional<std::string> title_;
136 : :
137 : : manifest manifest_;
138 : : optional<theme> theme_;
139 : : std::unordered_map<std::string, std::vector<std::uint8_t>> images_;
140 : : std::unordered_map<std::string, std::vector<std::uint8_t>> binaries_;
141 : :
142 : : std::vector<std::pair<xlnt::core_property, variant>> core_properties_;
143 : : std::vector<std::pair<xlnt::extended_property, variant>> extended_properties_;
144 : : std::vector<std::pair<std::string, variant>> custom_properties_;
145 : :
146 : : std::unordered_map<std::string, std::string> sheet_title_rel_id_map_;
147 : : std::vector<bool> sheet_hidden_;
148 : :
149 : : optional<workbook_view> view_;
150 : : optional<std::string> code_name_;
151 : :
152 : : struct file_version_t
153 : : {
154 : : std::string app_name;
155 : : std::size_t last_edited;
156 : : std::size_t lowest_edited;
157 : : std::size_t rup_build;
158 : :
159 : 334 : file_version_t(): last_edited(0), lowest_edited(0), rup_build(0) {
160 : :
161 : 334 : }
162 : :
163 : 8 : bool operator==(const file_version_t& rhs) const
164 : : {
165 : 8 : return app_name == rhs.app_name
166 [ + - ]: 8 : && last_edited == rhs.last_edited
167 [ + - ]: 8 : && lowest_edited == rhs.lowest_edited
168 [ + - + - ]: 16 : && rup_build == rhs.rup_build;
169 : : }
170 : :
171 : : bool operator!=(const file_version_t& rhs) const
172 : : {
173 : : return !(*this == rhs);
174 : : }
175 : : };
176 : :
177 : : optional<file_version_t> file_version_;
178 : : optional<calculation_properties> calculation_properties_;
179 : : optional<std::string> abs_path_;
180 : : optional<std::size_t> arch_id_flags_;
181 : : optional<ext_list> extensions_;
182 : : };
183 : :
184 : : } // namespace detail
185 : : } // namespace xlnt
|