cell_impl.hpp 3.2 KB

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