Avoid using dynamic_cast in source code

This commit is contained in:
Markus Gans 2018-10-13 00:32:14 +02:00
parent dbaebf0efc
commit 3fd5abfa1a
3 changed files with 33 additions and 5 deletions

View File

@ -1,3 +1,8 @@
2018-10-13 Markus Gans <guru.mail@muenster.de>
* Avoid using dynamic_cast so that you can compile Final Cut
without Run-Time Type Information (RTTI).
Thanks to user1095108 for reporting that.
2018-10-11 Markus Gans <guru.mail@muenster.de> 2018-10-11 Markus Gans <guru.mail@muenster.de>
* FKeyboard now uses references for keyboard buffer passing * FKeyboard now uses references for keyboard buffer passing

View File

@ -101,7 +101,7 @@ FMenuItem::~FMenuItem() // destructor
{ {
if ( super_menu && (isMenu(super_menu) || isMenuBar(super_menu)) ) if ( super_menu && (isMenu(super_menu) || isMenuBar(super_menu)) )
{ {
FMenuList* menu_list = dynamic_cast<FMenuList*>(super_menu); FMenuList* menu_list = getFMenuList(*super_menu);
if ( menu_list ) if ( menu_list )
menu_list->remove(this); menu_list->remove(this);
@ -150,7 +150,7 @@ bool FMenuItem::setFocus (bool on)
{ {
if ( ! selected ) if ( ! selected )
{ {
FMenuList* menu_list = dynamic_cast<FMenuList*>(getSuperMenu()); FMenuList* menu_list = getFMenuList(*getSuperMenu());
setSelected(); setSelected();
if ( menu_list ) if ( menu_list )
@ -559,6 +559,27 @@ bool FMenuItem::isMenu (FWidget* w) const
// private methods of FMenuItem // private methods of FMenuItem
//----------------------------------------------------------------------
FMenuList* FMenuItem::getFMenuList (FWidget& widget)
{
FMenuList* menu_list;
if ( isMenu(&widget) )
{
FMenu* menu = static_cast<FMenu*>(&widget);
menu_list = static_cast<FMenuList*>(menu);
}
else if ( isMenuBar(&widget) )
{
FMenuBar* menubar = static_cast<FMenuBar*>(&widget);
menu_list = static_cast<FMenuList*>(menubar);
}
else
menu_list = 0;
return menu_list;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::init (FWidget* parent) void FMenuItem::init (FWidget* parent)
{ {
@ -573,13 +594,12 @@ void FMenuItem::init (FWidget* parent)
if ( ! parent ) if ( ! parent )
return; return;
FMenuList* menu_list;
setSuperMenu (parent); setSuperMenu (parent);
if ( accel_key ) if ( accel_key )
addAccelerator (accel_key); addAccelerator (accel_key);
menu_list = dynamic_cast<FMenuList*>(parent); FMenuList* menu_list = getFMenuList(*parent);
if ( menu_list ) if ( menu_list )
menu_list->insert(this); menu_list->insert(this);
@ -616,7 +636,7 @@ uChar FMenuItem::hotKey()
length = text.getLength(); length = text.getLength();
for (uInt i = 0; i < length; i++) for (std::size_t i = 0; i < length; i++)
{ {
try try
{ {

View File

@ -166,6 +166,9 @@ class FMenuItem : public FWidget
// Disable assignment operator (=) // Disable assignment operator (=)
FMenuItem& operator = (const FMenuItem&); FMenuItem& operator = (const FMenuItem&);
// Accessor
FMenuList* getFMenuList (FWidget&);
// Methods // Methods
void init (FWidget*); void init (FWidget*);
uChar hotKey(); uChar hotKey();