From cbab7a36cb62b580ec6f0ae3d3808230f3943cf5 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Tue, 20 Oct 2015 13:53:47 -0400 Subject: [PATCH] clean up styles --- include/xlnt/styles/alignment.hpp | 7 +- include/xlnt/styles/borders.hpp | 5 +- include/xlnt/styles/fill.hpp | 2 +- include/xlnt/styles/font.hpp | 10 +- include/xlnt/styles/number_format.hpp | 11 + include/xlnt/styles/protection.hpp | 2 +- include/xlnt/styles/style.hpp | 85 ++++--- include/xlnt/workbook/workbook.hpp | 2 +- source/cell.cpp | 14 +- source/detail/cell_impl.cpp | 3 +- source/detail/cell_impl.hpp | 2 + source/detail/workbook_impl.hpp | 56 ++--- source/reader.cpp | 4 + source/style.cpp | 41 ++-- source/style_writer.cpp | 8 +- source/workbook.cpp | 339 +++++++------------------- source/worksheet_writer.cpp | 25 +- 17 files changed, 217 insertions(+), 399 deletions(-) diff --git a/include/xlnt/styles/alignment.hpp b/include/xlnt/styles/alignment.hpp index 7dd5e64b..6c051959 100644 --- a/include/xlnt/styles/alignment.hpp +++ b/include/xlnt/styles/alignment.hpp @@ -56,12 +56,7 @@ public: bool operator==(const alignment &other) const { - return horizontal_ == other.horizontal_ - && vertical_ == other.vertical_ - && text_rotation_ == other.text_rotation_ - && wrap_text_ == other.wrap_text_ - && shrink_to_fit_ == other.shrink_to_fit_ - && indent_ == other.indent_; + return hash() == other.hash(); } std::size_t hash() const { return 0; } diff --git a/include/xlnt/styles/borders.hpp b/include/xlnt/styles/borders.hpp index a65f3055..e0acfe4f 100644 --- a/include/xlnt/styles/borders.hpp +++ b/include/xlnt/styles/borders.hpp @@ -100,10 +100,7 @@ public: bool operator==(const border &other) const { - return start.value == other.start.value - && outline == other.outline - && diagonal_up == other.diagonal_up - && diagonal_down == other.diagonal_down; + return hash() == other.hash(); } std::size_t hash() const { return 0; } diff --git a/include/xlnt/styles/fill.hpp b/include/xlnt/styles/fill.hpp index 12dc4234..e47b1940 100644 --- a/include/xlnt/styles/fill.hpp +++ b/include/xlnt/styles/fill.hpp @@ -62,7 +62,7 @@ public: virtual bool operator==(const fill &other) const { - return type_ == other.type_; + return hash() == other.hash(); } virtual std::size_t hash() const { return 0; } diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index 613d559e..54246fb6 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -47,15 +47,7 @@ public: bool operator==(const font &other) const { - return name_ == other.name_ - && size_ == other.size_ - && bold_ == other.bold_ - && italic_ == other.italic_ - && superscript_ == other.superscript_ - && subscript_ == other.subscript_ - && underline_ == other.underline_ - && strikethrough_ == other.strikethrough_ - && color_ == other.color_; + return hash() == other.hash(); } int get_size() const { return size_; } diff --git a/include/xlnt/styles/number_format.hpp b/include/xlnt/styles/number_format.hpp index 9f8658d0..b551f4d1 100644 --- a/include/xlnt/styles/number_format.hpp +++ b/include/xlnt/styles/number_format.hpp @@ -88,6 +88,12 @@ public: static bool is_builtin(const std::string &format); + static const number_format &default_number_format() + { + static number_format default_; + return default_; + } + number_format(); number_format(format code); number_format(const std::string &code); @@ -102,6 +108,11 @@ public: int get_format_index() const { return format_index_; } std::size_t hash() const; + + bool operator==(const number_format &other) const + { + return hash() == other.hash(); + } private: format format_code_; diff --git a/include/xlnt/styles/protection.hpp b/include/xlnt/styles/protection.hpp index e8f23bf7..71e8dc42 100644 --- a/include/xlnt/styles/protection.hpp +++ b/include/xlnt/styles/protection.hpp @@ -47,7 +47,7 @@ public: bool operator==(const protection &other) const { - return locked_ == other.locked_ && hidden_ == other.hidden_; + return hash() == other.hash(); } std::size_t hash() const { return 0; } diff --git a/include/xlnt/styles/style.hpp b/include/xlnt/styles/style.hpp index 1df36535..a218bd55 100644 --- a/include/xlnt/styles/style.hpp +++ b/include/xlnt/styles/style.hpp @@ -23,55 +23,68 @@ // @author: see AUTHORS file #pragma once -namespace xlnt { -namespace detail { - -struct cell_impl; - -} // namespace detail +#include "alignment.hpp" +#include "borders.hpp" +#include "fill.hpp" +#include "font.hpp" +#include "number_format.hpp" +#include "protection.hpp" -class alignment; -class border; -class font; -class fill; -class number_format; -class protection; - -class cell; +namespace xlnt { + +class workbook; class style { public: - const style default_style(); - style(); - style(const style &rhs); - style &operator=(const style &rhs); - - style copy() const; std::size_t hash() const; - const font &get_font() const; - const fill &get_fill() const; - const border &get_border() const; - const alignment &get_alignment() const; - const number_format &get_number_format() const; - const protection &get_protection() const; + const alignment get_alignment() const; + const border get_border() const; + const fill get_fill() const; + const font get_font() const; + const number_format get_number_format() const; + const protection get_protection() const; bool pivot_button() const; bool quote_prefix() const; + std::size_t get_fill_index() const { return fill_index_; } + std::size_t get_font_index() const { return font_index_; } + std::size_t get_border_index() const { return border_index_; } + std::size_t get_number_format_index() const { return number_format_index_; } + + bool operator==(const style &other) const + { + return hash() == other.hash(); + } + private: - cell get_parent(); - const cell get_parent() const; - detail::cell_impl *parent_; - std::size_t font_id_; - std::size_t fill_id_; - std::size_t border_id_; - std::size_t alignment_id_; - std::size_t number_format_id_; - std::size_t protection_id_; - std::size_t style_id_; + friend class workbook; + + std::size_t style_index_; + + std::size_t alignment_index_; + alignment alignment_; + + std::size_t border_index_; + border border_; + + std::size_t fill_index_; + fill fill_; + + std::size_t font_index_; + font font_; + + std::size_t number_format_index_; + number_format number_format_; + + std::size_t protection_index_; + protection protection_; + + bool pivot_button_; + bool quote_prefix_; }; } // namespace xlnt diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 0b3fd06c..c27709cd 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -208,7 +208,7 @@ public: void add_color(color c); void add_number_format(const std::string &format); - std::vector> get_styles() const; + std::vector