From ba2d4743a6b2e44d294651a2b036f3d16b01eb2f Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Thu, 26 May 2016 10:05:30 +0800 Subject: [PATCH 1/2] Add implement const version of workbook::get_sheet_by_name(). and non const version are based on const version. --- source/workbook/workbook.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index d0429714..4319d706 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -93,7 +93,7 @@ workbook::workbook(encoding e) : workbook() d_->encoding_ = e; } -worksheet workbook::get_sheet_by_name(const std::string &name) +const worksheet workbook::get_sheet_by_name(const std::string &name) const { for (auto &impl : d_->worksheets_) { @@ -106,6 +106,11 @@ worksheet workbook::get_sheet_by_name(const std::string &name) return worksheet(); } +worksheet workbook::get_sheet_by_name(const std::string &name) +{ + return worksheet(static_cast(this)->get_sheet_by_name(name)); +} + worksheet workbook::get_sheet_by_index(std::size_t index) { return worksheet(&d_->worksheets_[index]); From aaabfe546ae63d575a5a71ca8c4e2492ef87b72d Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Thu, 26 May 2016 10:44:35 +0800 Subject: [PATCH 2/2] Add tests for const version of get_sheet_by_name(). --- source/workbook/tests/test_workbook.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 6d354b93..e7647d14 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -76,6 +76,17 @@ public: TS_ASSERT_EQUALS(new_sheet, found_sheet); } + void test_get_sheet_by_name_const() + { + xlnt::workbook wb; + auto new_sheet = wb.create_sheet(); + std::string title = "my sheet"; + new_sheet.set_title(title); + const xlnt::workbook& wbconst = wb; + auto found_sheet = wbconst.get_sheet_by_name(title); + TS_ASSERT_EQUALS(new_sheet, found_sheet); + } + void test_index_operator() // test_getitem { xlnt::workbook wb;