summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-06-06 19:01:46 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-06-06 19:01:46 -0400
commit2a6263ff4bcb195d7e9c398f5644511b43801730 (patch)
tree736b340ef4b60aee52ddf49d2fcbba276dcdeffc
parent9f7bc5b568e03b4094ea6b8ffe3be4edf3273a70 (diff)
downloadorcus-2a6263ff4bcb195d7e9c398f5644511b43801730.tar.gz
Introduce xf_category_t and combine some of the interfaces
The xf, style-xf, and dxf all share common attributes, so let's combine their interfaces. This is just the beginning of that work.
-rw-r--r--include/orcus/spreadsheet/factory.hpp5
-rw-r--r--include/orcus/spreadsheet/import_interface_styles.hpp4
-rw-r--r--include/orcus/spreadsheet/types.hpp15
-rw-r--r--src/include/mock_spreadsheet.hpp5
-rw-r--r--src/liborcus/xlsx_context.cpp6
-rw-r--r--src/spreadsheet/factory_styles.cpp27
6 files changed, 37 insertions, 25 deletions
diff --git a/include/orcus/spreadsheet/factory.hpp b/include/orcus/spreadsheet/factory.hpp
index 6bd4db6e..8078fa6b 100644
--- a/include/orcus/spreadsheet/factory.hpp
+++ b/include/orcus/spreadsheet/factory.hpp
@@ -84,10 +84,7 @@ public:
virtual void set_fill_count(size_t n) override;
virtual void set_border_count(size_t n) override;
virtual void set_number_format_count(size_t n) override;
-
- virtual void set_cell_xf_count(size_t n) override;
- virtual void set_cell_style_xf_count(size_t n) override;
- virtual void set_dxf_count(size_t n) override;
+ virtual void set_xf_count(xf_category_t cat, size_t n) override;
virtual void set_xf_font(size_t index) override;
virtual void set_xf_fill(size_t index) override;
diff --git a/include/orcus/spreadsheet/import_interface_styles.hpp b/include/orcus/spreadsheet/import_interface_styles.hpp
index d8147f15..0ae60323 100644
--- a/include/orcus/spreadsheet/import_interface_styles.hpp
+++ b/include/orcus/spreadsheet/import_interface_styles.hpp
@@ -135,9 +135,7 @@ public:
// directly by the index, and the entry in the cell format record references
// a cell style format in the cell style format record by the index.
- virtual void set_cell_xf_count(size_t n) = 0;
- virtual void set_cell_style_xf_count(size_t n) = 0;
- virtual void set_dxf_count(size_t n) = 0;
+ virtual void set_xf_count(xf_category_t cat, size_t n) = 0;
virtual void set_xf_font(size_t index) = 0;
virtual void set_xf_fill(size_t index) = 0;
diff --git a/include/orcus/spreadsheet/types.hpp b/include/orcus/spreadsheet/types.hpp
index 257e25ee..93c38c6f 100644
--- a/include/orcus/spreadsheet/types.hpp
+++ b/include/orcus/spreadsheet/types.hpp
@@ -274,6 +274,21 @@ enum class ver_alignment_t
};
/**
+ * Cell format type. The abbrevaition "xf" refers to "cell format" where the
+ * "x" stands for cell.
+ */
+enum class xf_category_t
+{
+ unknown,
+ /** direct cell format, also abbreviated as xf */
+ cell,
+ /** cell style format */
+ cell_style,
+ /** incremental cell format, also abbreviated as dxf */
+ differential,
+};
+
+/**
* Type of data table. A data table can be either of a single-variable
* column, a single-variable row, or a double-variable type that uses both
* column and row input cells.
diff --git a/src/include/mock_spreadsheet.hpp b/src/include/mock_spreadsheet.hpp
index 48a1b6e5..03277b3c 100644
--- a/src/include/mock_spreadsheet.hpp
+++ b/src/include/mock_spreadsheet.hpp
@@ -52,18 +52,17 @@ public:
virtual void set_border_count(size_t n) override;
virtual iface::import_border_style* get_border_style() override;
+ virtual void set_xf_count(xf_category_t cat, size_t n) = 0;
+
// cell style xf
- virtual void set_cell_style_xf_count(size_t n) override;
virtual size_t commit_cell_style_xf() override;
// cell xf
- virtual void set_cell_xf_count(size_t n) override;
virtual size_t commit_cell_xf() override;
// dxf
- virtual void set_dxf_count(size_t n) override;
virtual size_t commit_dxf() override;
// xf (cell format) - used both by cell xf and cell style xf.
diff --git a/src/liborcus/xlsx_context.cpp b/src/liborcus/xlsx_context.cpp
index ccf6d49b..bfbdb696 100644
--- a/src/liborcus/xlsx_context.cpp
+++ b/src/liborcus/xlsx_context.cpp
@@ -825,7 +825,7 @@ void xlsx_styles_context::start_element(xmlns_id_t ns, xml_token_t name, const x
if (!ps.empty())
{
size_t n = strtoul(ps.data(), nullptr, 10);
- mp_styles->set_cell_style_xf_count(n);
+ mp_styles->set_xf_count(ss::xf_category_t::cell_style, n);
}
m_cell_style_xf = true;
break;
@@ -839,7 +839,7 @@ void xlsx_styles_context::start_element(xmlns_id_t ns, xml_token_t name, const x
if (!ps.empty())
{
size_t n = strtoul(ps.data(), nullptr, 10);
- mp_styles->set_cell_xf_count(n);
+ mp_styles->set_xf_count(ss::xf_category_t::cell, n);
}
m_cell_style_xf = false;
break;
@@ -853,7 +853,7 @@ void xlsx_styles_context::start_element(xmlns_id_t ns, xml_token_t name, const x
if (!ps.empty())
{
size_t n = strtoul(ps.data(), nullptr, 10);
- mp_styles->set_dxf_count(n);
+ mp_styles->set_xf_count(ss::xf_category_t::differential, n);
}
break;
}
diff --git a/src/spreadsheet/factory_styles.cpp b/src/spreadsheet/factory_styles.cpp
index b06f24ba..773091e4 100644
--- a/src/spreadsheet/factory_styles.cpp
+++ b/src/spreadsheet/factory_styles.cpp
@@ -107,19 +107,22 @@ void import_styles::set_number_format_count(size_t n)
mp_impl->styles_model.reserve_number_format_store(n);
}
-void import_styles::set_cell_xf_count(size_t n)
+void import_styles::set_xf_count(xf_category_t cat, size_t n)
{
- mp_impl->styles_model.reserve_cell_format_store(n);
-}
-
-void import_styles::set_cell_style_xf_count(size_t n)
-{
- mp_impl->styles_model.reserve_cell_style_format_store(n);
-}
-
-void import_styles::set_dxf_count(size_t n)
-{
- mp_impl->styles_model.reserve_diff_cell_format_store(n);
+ switch (cat)
+ {
+ case xf_category_t::cell:
+ mp_impl->styles_model.reserve_cell_format_store(n);
+ break;
+ case xf_category_t::cell_style:
+ mp_impl->styles_model.reserve_cell_style_format_store(n);
+ break;
+ case xf_category_t::differential:
+ mp_impl->styles_model.reserve_diff_cell_format_store(n);
+ break;
+ case xf_category_t::unknown:
+ break;
+ }
}
void import_styles::set_xf_font(size_t index)