From f48a115976827701bb7b4bab7333f7512de08ab2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 22 Oct 2010 14:17:30 +0000 Subject: [PATCH] No real changes, just use const_cast<> instead of C casts. Replace many comments indicating that the C cast used was really a const_cast<> with the proper cast itself. There is no reason to not use it any longer, all the supported compilers understand it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65861 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/config.cpp | 2 +- src/common/ctrlcmn.cpp | 2 +- src/common/ffile.cpp | 2 +- src/common/file.cpp | 3 +-- src/common/intl.cpp | 2 +- src/common/mstream.cpp | 2 +- src/common/strconv.cpp | 2 +- src/generic/grid.cpp | 8 ++++---- src/msw/bitmap.cpp | 4 ++-- src/msw/notebook.cpp | 2 +- src/msw/thread.cpp | 12 ++++++------ src/osx/carbon/thread.cpp | 4 ++-- src/unix/fontutil.cpp | 9 +++------ 13 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 81ff589b68..6de614b83a 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -282,7 +282,7 @@ wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry) { m_bChanged = false; - m_pContainer = (wxConfigBase *)pContainer; + m_pContainer = const_cast(pContainer); // the path is everything which precedes the last slash wxString strPath = strEntry.BeforeLast(wxCONFIG_PATH_SEPARATOR); diff --git a/src/common/ctrlcmn.cpp b/src/common/ctrlcmn.cpp index 9d782d7f18..32f17b17a5 100644 --- a/src/common/ctrlcmn.cpp +++ b/src/common/ctrlcmn.cpp @@ -95,7 +95,7 @@ void wxControlBase::Command(wxCommandEvent& event) void wxControlBase::InitCommandEvent(wxCommandEvent& event) const { - event.SetEventObject((wxControlBase *)this); // const_cast + event.SetEventObject(const_cast(this)); // event.SetId(GetId()); -- this is usuall done in the event ctor diff --git a/src/common/ffile.cpp b/src/common/ffile.cpp index 7d669169a6..5957e34df2 100644 --- a/src/common/ffile.cpp +++ b/src/common/ffile.cpp @@ -244,7 +244,7 @@ wxFileOffset wxFFile::Length() const wxCHECK_MSG( IsOpened(), wxInvalidOffset, wxT("wxFFile::Length(): file is closed!") ); - wxFFile& self = *(wxFFile *)this; // const_cast + wxFFile& self = *const_cast(this); wxFileOffset posOld = Tell(); if ( posOld != wxInvalidOffset ) diff --git a/src/common/file.cpp b/src/common/file.cpp index 2b837569a2..bd4a4f0a0c 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -415,8 +415,7 @@ wxFileOffset wxFile::Length() const wxFileOffset iRc = Tell(); if ( iRc != wxInvalidOffset ) { - // have to use const_cast :-( - wxFileOffset iLen = ((wxFile *)this)->SeekEnd(); + wxFileOffset iLen = const_cast(this)->SeekEnd(); if ( iLen != wxInvalidOffset ) { // restore old position if ( ((wxFile *)this)->Seek(iRc) == wxInvalidOffset ) { diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 4e8542a1c4..7499eb5447 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -1024,7 +1024,7 @@ wxLocale::~wxLocale() wxSetLocale(m_pOldLocale); wxSetlocale(LC_ALL, m_pszOldLocale); - free((wxChar *)m_pszOldLocale); // const_cast + free(const_cast(m_pszOldLocale)); } diff --git a/src/common/mstream.cpp b/src/common/mstream.cpp index 5ecc10f704..66af403e2f 100644 --- a/src/common/mstream.cpp +++ b/src/common/mstream.cpp @@ -47,7 +47,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxMemoryInputStream, wxInputStream) wxMemoryInputStream::wxMemoryInputStream(const void *data, size_t len) { m_i_streambuf = new wxStreamBuffer(wxStreamBuffer::read); - m_i_streambuf->SetBufferIO((void *)data, len); // const_cast + m_i_streambuf->SetBufferIO(const_cast(data), len); m_i_streambuf->SetIntPosition(0); // seek to start pos m_i_streambuf->Fixed(true); diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 4615f5b24b..f46ccf4498 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -3227,7 +3227,7 @@ void wxCSConv::CreateConvIfNeeded() const { if ( m_deferred ) { - wxCSConv *self = (wxCSConv *)this; // const_cast + wxCSConv *self = const_cast(this); // if we don't have neither the name nor the encoding, use the default // encoding for this system diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index a05a2d519a..d60b2c579d 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -5892,8 +5892,8 @@ void wxGrid::EnableCellEditControl( bool enable ) bool wxGrid::IsCurrentCellReadOnly() const { - // const_cast - wxGridCellAttr* attr = ((wxGrid *)this)->GetCellAttr(m_currentCellCoords); + wxGridCellAttr* + attr = const_cast(this)->GetCellAttr(m_currentCellCoords); bool readonly = attr->IsReadOnly(); attr->DecRef(); @@ -7270,7 +7270,7 @@ void wxGrid::CacheAttr(int row, int col, wxGridCellAttr *attr) const { if ( attr != NULL ) { - wxGrid *self = (wxGrid *)this; // const_cast + wxGrid * const self = const_cast(this); self->ClearAttrCache(); self->m_attrCache.row = row; @@ -8164,7 +8164,7 @@ void wxGrid::AutoSizeColLabelSize( int col ) wxSize wxGrid::DoGetBestSize() const { - wxGrid *self = (wxGrid *)this; // const_cast + wxGrid * const self = const_cast(this); // we do the same as in AutoSize() here with the exception that we don't // change the column/row sizes, only calculate them diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index e903a33e8b..b0e759a7b9 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -414,7 +414,7 @@ bool wxBitmap::CopyFromDIB(const wxDIB& dib) if ( !hbitmap ) return false; #else // ALWAYS_USE_DIB - HBITMAP hbitmap = ((wxDIB &)dib).Detach(); // const_cast + HBITMAP hbitmap = const_cast(dib).Detach(); #endif // SOMETIMES_USE_DIB/ALWAYS_USE_DIB UnRef(); @@ -493,7 +493,7 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) else { // bits should already be in Windows standard format - data = (char *)bits; // const_cast is harmless + data = const_cast(bits); } HBITMAP hbmp = ::CreateBitmap(width, height, 1, depth, data); diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 90edb491b3..0e1f8926d0 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -785,7 +785,7 @@ bool wxNotebook::InsertPage(size_t nPage, if ( !strText.empty() ) { tcItem.mask |= TCIF_TEXT; - tcItem.pszText = (wxChar *)strText.wx_str(); // const_cast + tcItem.pszText = const_cast(strText.wx_str()); } // hide the page: unless it is selected, it shouldn't be shown (and if it diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 58715647ce..53c192cc50 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -1180,28 +1180,28 @@ void wxThread::SetPriority(unsigned int prio) unsigned int wxThread::GetPriority() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return m_internal->GetPriority(); } unsigned long wxThread::GetId() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return (unsigned long)m_internal->GetId(); } bool wxThread::IsRunning() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return m_internal->GetState() == STATE_RUNNING; } bool wxThread::IsAlive() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return (m_internal->GetState() == STATE_RUNNING) || (m_internal->GetState() == STATE_PAUSED); @@ -1209,14 +1209,14 @@ bool wxThread::IsAlive() const bool wxThread::IsPaused() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return m_internal->GetState() == STATE_PAUSED; } bool wxThread::TestDestroy() { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return m_internal->GetState() == STATE_CANCELED; } diff --git a/src/osx/carbon/thread.cpp b/src/osx/carbon/thread.cpp index e21d6136d7..3a55879a54 100644 --- a/src/osx/carbon/thread.cpp +++ b/src/osx/carbon/thread.cpp @@ -1128,14 +1128,14 @@ void wxThread::SetPriority(unsigned int prio) unsigned int wxThread::GetPriority() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return m_internal->GetPriority(); } unsigned long wxThread::GetId() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); // const_cast + wxCriticalSectionLocker lock(const_cast(m_critsect)); return (unsigned long)m_internal->GetId(); } diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index 39554c0fff..8a0fbb2193 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -581,8 +581,7 @@ wxString wxNativeFontInfo::GetXFontComponent(wxXLFDField field) const if ( !HasElements() ) { - // const_cast - if ( !((wxNativeFontInfo *)this)->FromXFontName(xFontName) ) + if ( !const_cast(this)->FromXFontName(xFontName) ) return wxEmptyString; } @@ -639,8 +638,7 @@ wxString wxNativeFontInfo::GetXFontName() const elt = wxT('*'); } - // const_cast - ((wxNativeFontInfo *)this)->xFontName << wxT('-') << elt; + const_cast(this)->xFontName << wxT('-') << elt; } } @@ -658,8 +656,7 @@ wxNativeFontInfo::SetXFontComponent(wxXLFDField field, const wxString& value) if ( !HasElements() ) { - // const_cast - if ( !((wxNativeFontInfo *)this)->FromXFontName(xFontName) ) + if ( !const_cast(this)->FromXFontName(xFontName) ) { wxFAIL_MSG( wxT("can't set font element for invalid XLFD") ); -- 2.47.2