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