From 77d2c45c38a3029f64f9e1a1ae042bd86b5d6091 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Sep 2008 22:03:27 +0000 Subject: [PATCH] add const synonyms for wxGridTableBase::GetNumberRows/Cols(), using const_cast<> all the time is painful git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55750 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/grid.h | 13 +++++++++++++ interface/wx/grid.h | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index b9700ec2d3..789ffbfc52 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -903,8 +903,21 @@ public: // You must override these functions in a derived table class // + + // return the number of rows and columns in this table virtual int GetNumberRows() = 0; virtual int GetNumberCols() = 0; + + // the methods above are unfortunately non-const even though they should + // have been const -- but changing it now is not possible any longer as it + // would break the existing code overriding them, so instead we provide + // these const synonyms which can be used from const-correct code + int GetRowsCount() const + { return wx_const_cast(wxGridTableBase *, this)->GetNumberRows(); } + int GetColsCount() const + { return wx_const_cast(wxGridTableBase *, this)->GetNumberCols(); } + + virtual bool IsEmptyCell( int row, int col ) = 0; bool IsEmpty(const wxGridCellCoords& coord) diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 82b700b5e1..facc29034b 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -86,12 +86,42 @@ public: /// Destructor frees the attribute provider if it was created. virtual ~wxGridTableBase(); - /// Must be overridden to return the number of rows in the table. + /** + Must be overridden to return the number of rows in the table. + + For backwards compatibility reasons, this method is not const. + Use GetRowsCount() instead of it in const methods of derived table + classes. + */ virtual int GetNumberRows() = 0; - /// Must be overridden to return the number of columns in the table. + /** + Must be overridden to return the number of columns in the table. + + For backwards compatibility reasons, this method is not const. + Use GetColsCount() instead of it in const methods of derived table + classes, + */ virtual int GetNumberCols() = 0; + /** + Return the number of rows in the table. + + This method is not virtual and is only provided as a convenience for + the derived classes which can't call GetNumberRows() without a @c + const_cast from their const methods. + */ + int GetRowsCount() const; + + /** + Return the number of columns in the table. + + This method is not virtual and is only provided as a convenience for + the derived classes which can't call GetNumberCols() without a @c + const_cast from their const methods. + */ + int GetColsCount() const; + /** Accessing table cells. -- 2.45.2