Code reduction by using of Range-based for loop

This commit is contained in:
Markus Gans 2018-12-15 22:10:31 +01:00
parent cef13611d1
commit fd924233c3
7 changed files with 61 additions and 115 deletions

View File

@ -1,5 +1,6 @@
2018-12-15 Markus Gans <guru.mail@muenster.de> 2018-12-15 Markus Gans <guru.mail@muenster.de>
* Use of the C++11 auto specifier in the program code * Use of the C++11 auto specifier in the program code
* Code reduction by using of Range-based for loop
2018-12-09 Markus Gans <guru.mail@muenster.de> 2018-12-09 Markus Gans <guru.mail@muenster.de>
* Better handling of the scrollbar maximum * Better handling of the scrollbar maximum

View File

@ -334,18 +334,14 @@ void FDialog::setSize (std::size_t w, std::size_t h, bool adjust)
if ( window_list && ! window_list->empty() ) if ( window_list && ! window_list->empty() )
{ {
bool overlaid = false; bool overlaid = false;
auto iter = window_list->begin();
auto last = window_list->end();
while ( iter != last ) for (auto&& win : *window_list)
{ {
if ( overlaid ) if ( overlaid )
putArea ((*iter)->getTermPos(), (*iter)->getVWin()); putArea (win->getTermPos(), win->getVWin());
if ( vwin == (*iter)->getVWin() ) if ( vwin == win->getVWin() )
overlaid = true; overlaid = true;
++iter;
} }
} }
@ -729,14 +725,8 @@ void FDialog::onWindowRaised (FEvent*)
// Handle always-on-top windows // Handle always-on-top windows
if ( always_on_top_list && ! always_on_top_list->empty() ) if ( always_on_top_list && ! always_on_top_list->empty() )
{ {
auto iter = always_on_top_list->begin(); for (auto&& win : *always_on_top_list)
auto last = always_on_top_list->end(); putArea (win->getTermPos(), win->getVWin());
while ( iter != last )
{
putArea ((*iter)->getTermPos(), (*iter)->getVWin());
++iter;
}
} }
} }
@ -749,14 +739,8 @@ void FDialog::onWindowLowered (FEvent*)
if ( window_list->empty() ) if ( window_list->empty() )
return; return;
auto iter = window_list->begin(); for (auto&& win : *window_list)
auto last = window_list->end(); putArea (win->getTermPos(), win->getVWin());
while ( iter != last )
{
putArea ((*iter)->getTermPos(), (*iter)->getVWin());
++iter;
}
} }
@ -1198,18 +1182,14 @@ void FDialog::restoreOverlaidWindows()
return; return;
bool overlaid = false; bool overlaid = false;
auto iter = window_list->begin();
auto last = window_list->end();
while ( iter != last ) for (auto&& win : *window_list)
{ {
if ( overlaid ) if ( overlaid )
putArea ((*iter)->getTermPos(), (*iter)->getVWin()); putArea (win->getTermPos(), win->getVWin());
if ( vwin == (*iter)->getVWin() ) if ( vwin == win->getVWin() )
overlaid = true; overlaid = true;
++iter;
} }
} }

View File

@ -471,14 +471,8 @@ void FFileDialog::clear()
return; return;
// delete all directory entries; // delete all directory entries;
auto iter = dir_entries.begin(); for (auto&& entry : dir_entries)
auto last = dir_entries.end(); std::free (entry.name);
while ( iter != last )
{
std::free (iter->name);
++iter;
}
dir_entries.clear(); dir_entries.clear();
} }
@ -490,17 +484,11 @@ int FFileDialog::numOfDirs()
return 0; return 0;
int n = 0; int n = 0;
auto iter = dir_entries.begin();
auto last = dir_entries.end();
while ( iter != last ) for (auto&& entry : dir_entries)
{ if ( entry.directory && std::strcmp(entry.name, ".") != 0 )
if ( iter->directory && std::strcmp(iter->name, ".") != 0 )
n++; n++;
++iter;
}
return n; return n;
} }
@ -668,17 +656,33 @@ void FFileDialog::dirEntriesToList()
if ( dir_entries.empty() ) if ( dir_entries.empty() )
return; return;
auto iter = dir_entries.begin(); for (auto&& entry : dir_entries)
auto last = dir_entries.end();
while ( iter != last )
{ {
if ( iter->directory ) if ( entry.directory )
filebrowser.insert(FString(iter->name), fc::SquareBrackets); filebrowser.insert(FString(entry.name), fc::SquareBrackets);
else else
filebrowser.insert(FString(iter->name)); filebrowser.insert(FString(entry.name));
}
}
++iter; //----------------------------------------------------------------------
void FFileDialog::selectDirectoryEntry (const char* const name)
{
if ( dir_entries.empty() )
return;
std::size_t i = 1;
for (auto&& entry : dir_entries)
{
if ( std::strcmp(entry.name, name) == 0 )
{
filebrowser.setCurrentItem(i);
filename.setText(FString(name) + '/');
break;
}
i++;
} }
} }
@ -712,26 +716,10 @@ int FFileDialog::changeDir (const FString& dirname)
{ {
if ( lastdir == FString('/') ) if ( lastdir == FString('/') )
filename.setText('/'); filename.setText('/');
else if ( ! dir_entries.empty() ) else
{ {
std::size_t i = 1; auto baseName = basename(C_STR(lastdir.c_str()));
const char* const baseName = \ selectDirectoryEntry (baseName);
basename(C_STR(lastdir.c_str()));
auto iter = dir_entries.begin();
auto last = dir_entries.end();
while ( iter != last )
{
if ( std::strcmp(iter->name, baseName) == 0 )
{
filebrowser.setCurrentItem(i);
filename.setText(FString(baseName) + '/');
break;
}
i++;
++iter;
}
} }
} }
else else
@ -807,21 +795,17 @@ void FFileDialog::cb_processActivate (FWidget*, data_ptr)
if ( ! dir_entries.empty() ) if ( ! dir_entries.empty() )
{ {
const FString& input = filename.getText().trim(); const FString& input = filename.getText().trim();
auto iter = dir_entries.begin();
auto last = dir_entries.end();
while ( iter != last ) for (auto&& entry : dir_entries)
{ {
if ( iter->name && input && ! input.isNull() if ( entry.name && input && ! input.isNull()
&& std::strcmp(iter->name, input) == 0 && std::strcmp(entry.name, input) == 0
&& iter->directory ) && entry.directory )
{ {
found = true; found = true;
changeDir(input); changeDir(input);
break; break;
} }
++iter;
} }
} }

View File

@ -295,16 +295,12 @@ void FListBox::remove (std::size_t item)
element_count = getCount(); element_count = getCount();
max_line_width = 0; max_line_width = 0;
auto iter = itemlist.begin(); for (auto&& item : itemlist)
while ( iter != itemlist.end() )
{ {
std::size_t len = iter->getText().getLength(); std::size_t len = item.getText().getLength();
if ( len > max_line_width ) if ( len > max_line_width )
max_line_width = len; max_line_width = len;
++iter;
} }
int hmax = ( max_line_width > getWidth() - nf_offset - 4 ) int hmax = ( max_line_width > getWidth() - nf_offset - 4 )

View File

@ -161,16 +161,9 @@ bool FStatusBar::hasActivatedKey()
{ {
if ( ! key_list.empty() ) if ( ! key_list.empty() )
{ {
auto iter = key_list.begin(); for (auto&& k : key_list)
auto last = key_list.end(); if ( k->isActivated() )
while ( iter != last )
{
if ( (*iter)->isActivated() )
return true; return true;
++iter;
}
} }
return false; return false;

View File

@ -871,19 +871,15 @@ FVTerm::covered_state FVTerm::isCovered ( int x, int y
if ( ! area ) if ( ! area )
return non_covered; return non_covered;
auto is_covered = non_covered;
bool found = bool(area == vdesktop); bool found = bool(area == vdesktop);
auto is_covered = non_covered;
auto w = static_cast<FWidget*>(area->widget); auto w = static_cast<FWidget*>(area->widget);
if ( w->window_list && ! w->window_list->empty() ) if ( w->window_list && ! w->window_list->empty() )
{ {
auto iter = w->window_list->begin(); for (auto&& win_obj : *w->window_list)
auto end = w->window_list->end();
for (; iter != end; ++iter)
{ {
auto win = (*iter)->getVWin(); auto win = win_obj->getVWin();
if ( ! win ) if ( ! win )
continue; continue;
@ -1706,12 +1702,9 @@ FVTerm::charData FVTerm::generateCharacter (int x, int y)
if ( ! widget->window_list || widget->window_list->empty() ) if ( ! widget->window_list || widget->window_list->empty() )
return *sc; return *sc;
auto iter = widget->window_list->begin(); for (auto&& win_obj : *widget->window_list)
auto end = widget->window_list->end();
for (; iter != end; ++iter)
{ {
auto win = (*iter)->getVWin(); auto win = win_obj->getVWin();
if ( ! win || ! win->visible ) if ( ! win || ! win->visible )
continue; continue;
@ -1808,23 +1801,21 @@ FVTerm::charData FVTerm::getCharacter ( character_type char_type
// Get the window layer of this object // Get the window layer of this object
int layer = FWindow::getWindowLayer(w); int layer = FWindow::getWindowLayer(w);
auto iter = w->window_list->begin();
auto end = w->window_list->end();
for (; iter != end; ++iter) for (auto&& win_obj : *w->window_list)
{ {
bool significant_char; bool significant_char;
// char_type can be "overlapped_character" // char_type can be "overlapped_character"
// or "covered_character" // or "covered_character"
if ( char_type == covered_character ) if ( char_type == covered_character )
significant_char = bool(layer >= FWindow::getWindowLayer(*iter)); significant_char = bool(layer >= FWindow::getWindowLayer(win_obj));
else else
significant_char = bool(layer < FWindow::getWindowLayer(*iter)); significant_char = bool(layer < FWindow::getWindowLayer(win_obj));
if ( obj && *iter != obj && significant_char ) if ( obj && win_obj != obj && significant_char )
{ {
auto win = (*iter)->getVWin(); auto win = win_obj->getVWin();
if ( ! win || ! win->visible ) if ( ! win || ! win->visible )
continue; continue;

View File

@ -173,6 +173,7 @@ class FFileDialog : public FDialog
void getEntry (const char* const, struct dirent*); void getEntry (const char* const, struct dirent*);
void followSymLink (const char* const, dir_entry&); void followSymLink (const char* const, dir_entry&);
void dirEntriesToList(); void dirEntriesToList();
void selectDirectoryEntry (const char* const);
int changeDir (const FString&); int changeDir (const FString&);
void printPath (const FString&); void printPath (const FString&);
static const FString getHomeDir(); static const FString getHomeDir();