From c884ad7f8245c154ed9ff4987d3ac23d5bc2eca7 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Thu, 29 Oct 2015 13:46:56 -0400 Subject: [PATCH] start refactoring serialization code --- include/xlnt/cell/cell.hpp | 61 +- include/xlnt/reader/comment_reader.hpp | 33 - include/xlnt/reader/style_reader.hpp | 88 -- .../comment_serializer.hpp} | 47 +- .../excel_serializer.hpp} | 42 +- include/xlnt/s11n/manifest_serializer.hpp | 24 + include/xlnt/s11n/relationship_serializer.hpp | 17 + .../shared_strings_serializer.hpp} | 10 +- include/xlnt/s11n/style_serializer.hpp | 255 +++++ .../theme_serializer.hpp} | 8 +- .../workbook_serializer.hpp} | 35 +- .../worksheet_serializer.hpp} | 20 +- include/xlnt/s11n/xml_document.hpp | 25 + include/xlnt/s11n/xml_node.hpp | 42 + include/xlnt/s11n/xml_serializer.hpp | 16 + include/xlnt/styles/color.hpp | 31 +- include/xlnt/styles/side.hpp | 22 +- include/xlnt/styles/style.hpp | 3 +- include/xlnt/workbook/manifest.hpp | 60 ++ include/xlnt/workbook/theme.hpp | 10 + include/xlnt/workbook/workbook.hpp | 6 +- include/xlnt/worksheet/worksheet.hpp | 4 +- include/xlnt/writer/comment_writer.hpp | 33 - include/xlnt/writer/excel_writer.hpp | 56 -- include/xlnt/writer/manifest_writer.hpp | 11 - include/xlnt/writer/relationship_writer.hpp | 12 - include/xlnt/writer/shared_strings_writer.hpp | 33 - include/xlnt/writer/style_writer.hpp | 61 -- include/xlnt/writer/workbook_writer.hpp | 43 - include/xlnt/writer/worksheet_writer.hpp | 13 - source/cell/cell.cpp | 28 +- source/detail/cell_impl.cpp | 1 - source/detail/cell_impl.hpp | 4 +- source/detail/workbook_impl.hpp | 5 +- source/reader/shared_strings_reader.cpp | 38 - source/reader/style_reader.cpp | 484 ---------- source/reader/workbook_reader.cpp | 240 ----- source/s11n/comment_serializer.cpp | 5 + .../excel_serializer.cpp} | 124 ++- source/s11n/manifest_serializer.cpp | 33 + source/s11n/relationship_serializer.cpp | 47 + source/s11n/shared_strings_serializer.cpp | 29 + source/s11n/style_serializer.cpp | 900 ++++++++++++++++++ .../workbook_serializer.cpp} | 219 ++++- source/s11n/worksheet_serializer.cpp | 368 +++++++ source/s11n/xml_document.cpp | 25 + source/s11n/xml_node.cpp | 107 +++ source/s11n/xml_serializer.cpp | 85 ++ source/workbook/manifest.cpp | 43 + source/workbook/workbook.cpp | 10 + source/worksheet/worksheet.cpp | 4 +- source/writer/excel_writer.cpp | 152 --- source/writer/manifest_writer.cpp | 40 - source/writer/relationship_writer.cpp | 45 - source/writer/style_writer.cpp | 409 -------- source/writer/worksheet_writer.cpp | 369 ------- tests/test_cell.hpp | 9 + 57 files changed, 2639 insertions(+), 2305 deletions(-) delete mode 100644 include/xlnt/reader/comment_reader.hpp delete mode 100644 include/xlnt/reader/style_reader.hpp rename include/xlnt/{writer/chart_writer.hpp => s11n/comment_serializer.hpp} (76%) rename include/xlnt/{reader/excel_reader.hpp => s11n/excel_serializer.hpp} (51%) create mode 100644 include/xlnt/s11n/manifest_serializer.hpp create mode 100644 include/xlnt/s11n/relationship_serializer.hpp rename include/xlnt/{reader/shared_strings_reader.hpp => s11n/shared_strings_serializer.hpp} (85%) create mode 100644 include/xlnt/s11n/style_serializer.hpp rename include/xlnt/{writer/theme_writer.hpp => s11n/theme_serializer.hpp} (90%) rename include/xlnt/{reader/workbook_reader.hpp => s11n/workbook_serializer.hpp} (62%) rename include/xlnt/{reader/worksheet_reader.hpp => s11n/worksheet_serializer.hpp} (72%) create mode 100644 include/xlnt/s11n/xml_document.hpp create mode 100644 include/xlnt/s11n/xml_node.hpp create mode 100644 include/xlnt/s11n/xml_serializer.hpp create mode 100644 include/xlnt/workbook/manifest.hpp create mode 100644 include/xlnt/workbook/theme.hpp delete mode 100644 include/xlnt/writer/comment_writer.hpp delete mode 100644 include/xlnt/writer/excel_writer.hpp delete mode 100644 include/xlnt/writer/manifest_writer.hpp delete mode 100644 include/xlnt/writer/relationship_writer.hpp delete mode 100644 include/xlnt/writer/shared_strings_writer.hpp delete mode 100644 include/xlnt/writer/style_writer.hpp delete mode 100644 include/xlnt/writer/workbook_writer.hpp delete mode 100644 include/xlnt/writer/worksheet_writer.hpp delete mode 100644 source/reader/shared_strings_reader.cpp delete mode 100644 source/reader/style_reader.cpp delete mode 100644 source/reader/workbook_reader.cpp create mode 100644 source/s11n/comment_serializer.cpp rename source/{reader/excel_reader.cpp => s11n/excel_serializer.cpp} (58%) create mode 100644 source/s11n/manifest_serializer.cpp create mode 100644 source/s11n/relationship_serializer.cpp create mode 100644 source/s11n/shared_strings_serializer.cpp create mode 100644 source/s11n/style_serializer.cpp rename source/{writer/workbook_writer.cpp => s11n/workbook_serializer.cpp} (79%) create mode 100644 source/s11n/worksheet_serializer.cpp create mode 100644 source/s11n/xml_document.cpp create mode 100644 source/s11n/xml_node.cpp create mode 100644 source/s11n/xml_serializer.cpp create mode 100644 source/workbook/manifest.cpp delete mode 100644 source/writer/excel_writer.cpp delete mode 100644 source/writer/manifest_writer.cpp delete mode 100644 source/writer/relationship_writer.cpp delete mode 100644 source/writer/style_writer.cpp delete mode 100644 source/writer/worksheet_writer.cpp diff --git a/include/xlnt/cell/cell.hpp b/include/xlnt/cell/cell.hpp index 630753d2..0f678161 100644 --- a/include/xlnt/cell/cell.hpp +++ b/include/xlnt/cell/cell.hpp @@ -27,15 +27,20 @@ #include #include -#include "../styles/style.hpp" -#include "../common/types.hpp" +#include namespace xlnt { enum class calendar; - + +class alignment; +class border; class cell_reference; class comment; +class fill; +class font; +class number_format; +class protection; class relationship; class worksheet; @@ -62,6 +67,9 @@ struct cell_impl; class cell { public: + /// + /// Enumerates the possible types a cell can be determined by it's current value. + /// enum class type { null, @@ -72,14 +80,38 @@ public: boolean }; - static const std::unordered_map ErrorCodes; + /// + /// Return a map of error strings such as #DIV/0! and their associated indices. + /// + static const std::unordered_map error_codes(); + //TODO: Should it be possible to construct and use a cell without a parent worksheet? + //(cont'd) If so, it would need to be responsible for allocating and deleting its PIMPL. + + /// + /// Construct a null cell without a parent. + /// Most methods will throw an exception if this cell is not further initialized. + /// cell(); - cell(worksheet worksheet, const cell_reference &reference); + + /// + /// Construct a cell in worksheet, sheet, at the given reference location (e.g. A1). + /// + cell(worksheet sheet, const cell_reference &reference); + + /// + /// This constructor, provided for convenience, is equivalent to calling: + /// cell c(sheet, reference); + /// c.set_value(initial_value); + /// template - cell(worksheet worksheet, const cell_reference &reference, const T &initial_value); + cell(worksheet sheet, const cell_reference &reference, const T &initial_value); // value + + /// + /// Return true if value has been set and has not been cleared using cell::clear_value(). + /// bool has_value() const; template @@ -93,10 +125,18 @@ public: type get_data_type() const; void set_data_type(type t); - // characteristics + // properties + + /// + /// There's no reason to keep a cell which has no value and is not a placeholder. + /// Return true if this cell has no value, style, isn't merged, etc. + /// bool garbage_collectible() const; + + /// + /// Return true iff this cell's number format matches a date format. + /// bool is_date() const; - std::size_t get_xf_index() const; // position cell_reference get_reference() const; @@ -176,6 +216,7 @@ public: bool operator==(const cell &comparand) const; bool operator==(std::nullptr_t) const; + // friend operators, so we can put cell on either side of comparisons with other types friend bool operator==(std::nullptr_t, const cell &cell); friend bool operator<(cell left, cell right); @@ -188,6 +229,10 @@ private: detail::cell_impl *d_; }; +/// +/// Convenience function for writing cell to an ostream. +/// Uses cell::to_string() internally. +/// inline std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell) { return stream << cell.to_string(); diff --git a/include/xlnt/reader/comment_reader.hpp b/include/xlnt/reader/comment_reader.hpp deleted file mode 100644 index 91a0bf1b..00000000 --- a/include/xlnt/reader/comment_reader.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2015 Thomas Fussell -// Copyright (c) 2010-2015 openpyxl -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE -// -// @license: http://www.opensource.org/licenses/mit-license.php -// @author: see AUTHORS file -#pragma once - -namespace xlnt { - -class comment_reader -{ - -}; - -} // namespace xlnt diff --git a/include/xlnt/reader/style_reader.hpp b/include/xlnt/reader/style_reader.hpp deleted file mode 100644 index 329c2e03..00000000 --- a/include/xlnt/reader/style_reader.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2015 Thomas Fussell -// Copyright (c) 2010-2015 openpyxl -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE -// -// @license: http://www.opensource.org/licenses/mit-license.php -// @author: see AUTHORS file -#pragma once - -#include -#include -#include - -#include "xlnt/workbook/workbook.hpp" - -namespace pugi { -class xml_node; -} // namespace pugi - -namespace xlnt { - -class border; -class fill; -class font; -class named_style; -class number_format; -class style; -class zip_file; - -class style_reader -{ -public: - style_reader(workbook &wb); - - void read_styles(zip_file &archive); - - const std::vector