Merge pull request #48 from xpol/add-missing-member-for-workbook

Add implement const version of workbook::get_sheet_by_name().
This commit is contained in:
Thomas Fussell 2016-06-04 08:53:34 -06:00
commit 30275476c1
2 changed files with 17 additions and 1 deletions

View File

@ -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;

View File

@ -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<const workbook*>(this)->get_sheet_by_name(name));
}
worksheet workbook::get_sheet_by_index(std::size_t index)
{
return worksheet(&d_->worksheets_[index]);