I'm working with Irrlicht's GUI event handler and I found myself trapped in making nested switch-case statements. For example, the code show here is the outer nest and each helper function (e.g. onMenuItemSelected(), onButtonClicked(), onListBoxSelectedAgain(), etc.) may also contain nested switch-case statements. I have been using a helper function to define the body of each case. What alternatives are there to nested switch-case statements?
/// Does stuff when a Menu Bar item is selected.
bool EditorGui::onMenuItemSelected( irr::gui::IGUIContextMenu* pMenuItem )
{
irr::s32 menuItemId = pMenuItem->getItemCommandId( pMenuItem->getSelectedItem() ); // Get id of calling menu item
switch( menuItemId )
{
case GUID_FILE_NEWPROJECT :
{
return onFileNewProject();
}
case GUID_FILE_OPENPROJECT :
{
return onFileOpenProject();
}
case GUID_FILE_SAVEPROJECT :
{
return onFileSaveProject();
}
case GUID_FILE_EXIT :
{
onFileExit();
}
default :
returnfalse;
}
}