From a4b8094aac6d8b8ad498c02b4f762ee727c43144 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 20 Jun 2016 22:00:05 +0200 Subject: [PATCH] const correctness It is dangerous to hand out non-const pointers to members from a const method. --- src/insets/InsetTabular.cpp | 21 +++++++++++++-------- src/insets/InsetTabular.h | 8 ++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 7ad86633da..54b4158b41 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -525,7 +525,7 @@ string const featureAsString(Tabular::Feature action) } -DocIterator separatorPos(InsetTableCell * cell, docstring const & align_d) +DocIterator separatorPos(InsetTableCell const * cell, docstring const & align_d) { DocIterator dit = doc_iterator_begin(&(cell->buffer()), cell); for (; dit; dit.forwardChar()) @@ -2308,7 +2308,7 @@ void Tabular::TeXCellPreamble(otexstream & os, idx_type cell, // we center in multicol when no decimal point if (column_info[c].alignment == LYX_ALIGN_DECIMAL) { docstring const align_d = column_info[c].decimal_point; - DocIterator const dit = separatorPos(cellInset(cell).get(), align_d); + DocIterator const dit = separatorPos(cellInset(cell), align_d); ismulticol |= !dit; } @@ -2533,7 +2533,7 @@ void Tabular::TeXRow(otexstream & os, row_type row, OutputParams const & runparams) const { idx_type cell = cellIndex(row, 0); - shared_ptr inset = cellInset(cell); + InsetTableCell const * inset = cellInset(cell); Paragraph const & par = inset->paragraphs().front(); string const lang = par.getParLanguage(buffer().params())->lang(); @@ -2572,7 +2572,7 @@ void Tabular::TeXRow(otexstream & os, row_type row, } TeXCellPreamble(os, cell, ismulticol, ismultirow); - shared_ptr inset = cellInset(cell); + InsetTableCell const * inset = cellInset(cell); Paragraph const & par = inset->paragraphs().front(); @@ -3321,21 +3321,26 @@ void Tabular::plaintext(odocstringstream & os, } -shared_ptr Tabular::cellInset(idx_type cell) const +shared_ptr Tabular::cellInset(idx_type cell) { return cell_info[cellRow(cell)][cellColumn(cell)].inset; } -shared_ptr Tabular::cellInset(row_type row, - col_type column) const +shared_ptr Tabular::cellInset(row_type row, col_type column) { return cell_info[row][column].inset; } +InsetTableCell const * Tabular::cellInset(idx_type cell) const +{ + return cell_info[cellRow(cell)][cellColumn(cell)].inset.get(); +} + + void Tabular::setCellInset(row_type row, col_type column, - shared_ptr ins) const + shared_ptr ins) { CellData & cd = cell_info[row][column]; cd.inset = ins; diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index b23fc85b74..ee5cffcd5e 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -612,13 +612,13 @@ public: /// returns the VISIBLE cell at r,c, which may be the same as the /// cell at the previous row or column, if we're dealing with some /// multirow or multicell. - shared_ptr cellInset(idx_type cell) const; - shared_ptr cellInset(row_type row, - col_type column) const; + shared_ptr cellInset(idx_type cell); + shared_ptr cellInset(row_type row, col_type column); + InsetTableCell const * cellInset(idx_type cell) const; //@} /// void setCellInset(row_type row, col_type column, - shared_ptr) const; + shared_ptr); /// Search for \param inset in the tabular, with the /// void validate(LaTeXFeatures &) const;