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 <cstddef>
26 #include <string>
27
28 #include <xlnt/cell/cell_type.hpp>
29 #include <xlnt/cell/comment.hpp>
30 #include <xlnt/cell/index_types.hpp>
31 #include <xlnt/cell/rich_text.hpp>
32 #include <xlnt/packaging/relationship.hpp>
33 #include <xlnt/utils/optional.hpp>
34 #include <detail/implementations/format_impl.hpp>
35 #include <detail/implementations/hyperlink_impl.hpp>
36 //#include "../numeric_utils.hpp"
37
38 namespace xlnt {
39 namespace detail {
40
41 struct worksheet_impl;
42
43 struct cell_impl
44 {
45 cell_impl();
46 cell_impl(const cell_impl &other) = default;
47 cell_impl(cell_impl &&other) = default;
48 cell_impl &operator=(const cell_impl &other) = default;
49 cell_impl &operator=(cell_impl &&other) = default;
50
51 cell_type type_;
52
53 worksheet_impl *parent_;
54
55 column_t column_;
56 row_t row_;
57
58 bool is_merged_;
59 bool phonetics_visible_;
60
61 rich_text value_text_;
62 double value_numeric_;
63
64 optional<std::string> formula_;
65 optional<hyperlink_impl> hyperlink_;
66 optional<format_impl *> format_;
67 optional<comment *> comment_;
68
is_garbage_collectiblexlnt::detail::cell_impl69 bool is_garbage_collectible() const
70 {
71 return !(type_ != cell_type::empty || is_merged_ || phonetics_visible_ || formula_.is_set() || format_.is_set() || hyperlink_.is_set());
72 }
73 };
74
operator ==(const cell_impl & lhs,const cell_impl & rhs)75 inline bool operator==(const cell_impl &lhs, const cell_impl &rhs)
76 {
77 // not comparing parent
78 return lhs.type_ == rhs.type_
79 && lhs.column_ == rhs.column_
80 && lhs.row_ == rhs.row_
81 && lhs.is_merged_ == rhs.is_merged_
82 && lhs.phonetics_visible_ == rhs.phonetics_visible_
83 && lhs.value_text_ == rhs.value_text_
84 && float_equals(lhs.value_numeric_, rhs.value_numeric_)
85 && lhs.formula_ == rhs.formula_
86 && lhs.hyperlink_ == rhs.hyperlink_
87 && (lhs.format_.is_set() == rhs.format_.is_set() && (!lhs.format_.is_set() || *lhs.format_.get() == *rhs.format_.get()))
88 && (lhs.comment_.is_set() == rhs.comment_.is_set() && (!lhs.comment_.is_set() || *lhs.comment_.get() == *rhs.comment_.get()));
89 }
90
91 } // namespace detail
92 } // namespace xlnt
93