Use const_cast to change the constness

This commit is contained in:
Artur Wieczorek
2019-06-16 17:09:23 +02:00
parent 2ebdfb7a40
commit b064608c2a
9 changed files with 20 additions and 20 deletions

View File

@@ -460,7 +460,7 @@ public:
wxWindow* GetButton( unsigned int i ) { return m_buttons[i]; } wxWindow* GetButton( unsigned int i ) { return m_buttons[i]; }
const wxWindow* GetButton( unsigned int i ) const const wxWindow* GetButton( unsigned int i ) const
{ return (const wxWindow*) m_buttons[i]; } { return const_cast<const wxWindow*>(m_buttons[i]); }
// Utility function to be used in event handlers. // Utility function to be used in event handlers.
int GetButtonId( unsigned int i ) const { return GetButton(i)->GetId(); } int GetButtonId( unsigned int i ) const { return GetButton(i)->GetId(); }

View File

@@ -270,7 +270,7 @@ public:
const wxPropertyGrid* GetGrid() const const wxPropertyGrid* GetGrid() const
{ {
wxASSERT(m_pPropGrid); wxASSERT(m_pPropGrid);
return (const wxPropertyGrid*)m_pPropGrid; return const_cast<const wxPropertyGrid*>(m_pPropGrid);
} }
// Returns iterator class instance. // Returns iterator class instance.

View File

@@ -1162,7 +1162,7 @@ public:
const wxPGCommonValue* GetCommonValue( unsigned int i ) const const wxPGCommonValue* GetCommonValue( unsigned int i ) const
{ {
return (wxPGCommonValue*) m_commonValues[i]; return const_cast<const wxPGCommonValue*>(m_commonValues[i]);
} }
// Returns number of common values. // Returns number of common values.

View File

@@ -75,7 +75,7 @@ public:
wxPGProperty* GetPtr( wxPropertyGridInterface* iface ) const; wxPGProperty* GetPtr( wxPropertyGridInterface* iface ) const;
wxPGProperty* GetPtr( const wxPropertyGridInterface* iface ) const wxPGProperty* GetPtr( const wxPropertyGridInterface* iface ) const
{ {
return GetPtr((wxPropertyGridInterface*)iface); return GetPtr(const_cast<wxPropertyGridInterface*>(iface));
} }
wxPGProperty* GetPtr0() const { return m_ptr.property; } wxPGProperty* GetPtr0() const { return m_ptr.property; }
bool HasName() const { return (m_flags != IsProperty); } bool HasName() const { return (m_flags != IsProperty); }
@@ -305,7 +305,7 @@ public:
const wxPGProperty* GetFirst( int flags = wxPG_ITERATE_ALL ) const const wxPGProperty* GetFirst( int flags = wxPG_ITERATE_ALL ) const
{ {
return ((wxPropertyGridInterface*)this)->GetFirst(flags); return const_cast<const wxPGProperty*>(GetFirst(flags));
} }
// Returns pointer to a property with given name (case-sensitive). // Returns pointer to a property with given name (case-sensitive).

View File

@@ -217,12 +217,12 @@ public:
PROPERTY* property = NULL, int dir = 1) PROPERTY* property = NULL, int dir = 1)
: wxPropertyGridIteratorBase() : wxPropertyGridIteratorBase()
{ {
Init((wxPropertyGridPageState*)state, flags, (wxPGProperty*)property, dir); Init(const_cast<wxPropertyGridPageState*>(state), flags, const_cast<wxPGProperty*>(property), dir);
} }
wxPGIterator(STATE* state, int flags, int startPos, int dir = 0) wxPGIterator(STATE* state, int flags, int startPos, int dir = 0)
: wxPropertyGridIteratorBase() : wxPropertyGridIteratorBase()
{ {
Init((wxPropertyGridPageState*)state, flags, startPos, dir); Init(const_cast<wxPropertyGridPageState*>(state), flags, startPos, dir);
} }
wxPGIterator() wxPGIterator()
: wxPropertyGridIteratorBase() : wxPropertyGridIteratorBase()
@@ -248,7 +248,7 @@ public:
wxPGIterator operator++(int) { wxPGIterator it = *this; Next(); return it; } wxPGIterator operator++(int) { wxPGIterator it = *this; Next(); return it; }
wxPGIterator& operator--() { Prev(); return *this; } wxPGIterator& operator--() { Prev(); return *this; }
wxPGIterator operator--(int) { wxPGIterator it = *this; Prev(); return it; } wxPGIterator operator--(int) { wxPGIterator it = *this; Prev(); return it; }
PROPERTY* operator *() const { return (PROPERTY*)m_property; } PROPERTY* operator *() const { return const_cast<PROPERTY*>(m_property); }
static PROPERTY* OneStep(STATE* state, int flags = wxPG_ITERATE_DEFAULT, static PROPERTY* OneStep(STATE* state, int flags = wxPG_ITERATE_DEFAULT,
PROPERTY* property = NULL, int dir = 1) PROPERTY* property = NULL, int dir = 1)
{ {
@@ -412,7 +412,7 @@ public:
const wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT ) const const wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT ) const
{ {
return ((wxPropertyGridPageState*)this)->GetLastItem(flags); return const_cast<const wxPGProperty*>(GetLastItem(flags));
} }
// Returns currently selected property. // Returns currently selected property.

View File

@@ -771,7 +771,7 @@ bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
wxWindow* primary, wxEvent& event ) \ wxWindow* primary, wxEvent& event ) \
{ \ { \
if ( event.GetEventType() == wxEVT_BUTTON ) \ if ( event.GetEventType() == wxEVT_BUTTON ) \
return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \ return OnButtonClick(propgrid,primary, const_cast<const wxChar*>(CUSTBUTTXT)); \
return false; \ return false; \
} }

View File

@@ -1448,7 +1448,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
// GetPropertyByNameWH(). This optimizes for full list parsing. // GetPropertyByNameWH(). This optimizes for full list parsing.
for ( node = list.begin(); node != list.end(); ++node ) for ( node = list.begin(); node != list.end(); ++node )
{ {
wxVariant& childValue = *((wxVariant*)*node); wxVariant& childValue = *const_cast<wxVariant*>(*node);
wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i); wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i);
if ( child ) if ( child )
{ {
@@ -2248,8 +2248,8 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
wxPGProperty* wxPGProperty::GetMainParent() const wxPGProperty* wxPGProperty::GetMainParent() const
{ {
const wxPGProperty* curChild = this; wxPGProperty* curChild = const_cast<wxPGProperty*>(this);
const wxPGProperty* curParent = m_parent; wxPGProperty* curParent = m_parent;
while ( !curParent->IsRoot() && !curParent->IsCategory() ) while ( !curParent->IsRoot() && !curParent->IsCategory() )
{ {
@@ -2257,7 +2257,7 @@ wxPGProperty* wxPGProperty::GetMainParent() const
curParent = curParent->m_parent; curParent = curParent->m_parent;
} }
return (wxPGProperty*) curChild; return curChild;
} }
@@ -2729,7 +2729,7 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
for ( ; node != pList->end(); ++node ) for ( ; node != pList->end(); ++node )
{ {
const wxVariant& item = *((const wxVariant*)*node); const wxVariant& item = *const_cast<const wxVariant*>(*node);
if ( item.GetName() == childName ) if ( item.GetName() == childName )
{ {
listValue = &item; listValue = &item;
@@ -2753,7 +2753,7 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
if ( listValue && listValue->IsType(wxPG_VARIANT_TYPE_LIST) ) if ( listValue && listValue->IsType(wxPG_VARIANT_TYPE_LIST) )
childList = listValue; childList = listValue;
if ( !child->AreAllChildrenSpecified((wxVariant*)childList) ) if ( !child->AreAllChildrenSpecified(const_cast<wxVariant*>(childList)) )
return false; return false;
} }
} }

View File

@@ -2128,7 +2128,7 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
if ( !p->HasFlag(wxPG_PROP_HIDDEN) ) if ( !p->HasFlag(wxPG_PROP_HIDDEN) )
{ {
visPropArray.push_back((wxPGProperty*)p); visPropArray.push_back(const_cast<wxPGProperty*>(p));
if ( y > endScanBottomY ) if ( y > endScanBottomY )
break; break;

View File

@@ -1442,7 +1442,7 @@ void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wx
// Second pass for special entries // Second pass for special entries
for ( node = list.begin(); node != list.end(); ++node ) for ( node = list.begin(); node != list.end(); ++node )
{ {
wxVariant *current = (wxVariant*)*node; wxVariant *current = const_cast<wxVariant*>(*node);
// Make sure it is wxVariant. // Make sure it is wxVariant.
wxASSERT( current ); wxASSERT( current );
@@ -1505,7 +1505,7 @@ void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wx
{ {
for ( node = list.begin(); node != list.end(); ++node ) for ( node = list.begin(); node != list.end(); ++node )
{ {
wxVariant *current = (wxVariant*)*node; wxVariant *current = const_cast<wxVariant*>(*node);
const wxString& name = current->GetName(); const wxString& name = current->GetName();
if ( !name.empty() ) if ( !name.empty() )
@@ -1536,7 +1536,7 @@ void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wx
for ( node2 = list2.begin(); node2 != list2.end(); ++node2 ) for ( node2 = list2.begin(); node2 != list2.end(); ++node2 )
{ {
wxVariant *attr = (wxVariant*)*node2; wxVariant *attr = const_cast<wxVariant*>(*node2);
foundProp->SetAttribute( attr->GetName(), *attr ); foundProp->SetAttribute( attr->GetName(), *attr );
} }
} }