More loops to tackle.

This commit is contained in:
Jason Felds
2013-04-30 20:19:03 -04:00
parent abe2b65514
commit 23d0180b20
+14 -21
View File
@@ -42,13 +42,13 @@ bool StepsCriteria::Matches( const Song *pSong, const Steps *pSteps ) const
void StepsUtil::GetAllMatching( const SongCriteria &soc, const StepsCriteria &stc, vector<SongAndSteps> &out )
{
const RString &sGroupName = soc.m_sGroupName.empty()? GROUP_ALL:soc.m_sGroupName;
const vector<Song*> &songs = SONGMAN->GetSongs( sGroupName );
const vector<Song*> &songs = SONGMAN->GetSongs( sGroupName );
FOREACH_CONST( Song*, songs, so )
for (Song *so : songs)
{
if( !soc.Matches(*so) )
if( !soc.Matches(so) )
continue;
GetAllMatching( *so, stc, out );
GetAllMatching( so, stc, out ); // TODO: Look into why this can't be const.
}
}
@@ -57,34 +57,27 @@ void StepsUtil::GetAllMatching( Song *pSong, const StepsCriteria &stc, vector<So
const vector<Steps*> &vSteps = ( stc.m_st == StepsType_Invalid ? pSong->GetAllSteps() :
pSong->GetStepsByStepsType(stc.m_st) );
FOREACH_CONST( Steps*, vSteps, st )
if( stc.Matches(pSong, *st) )
out.push_back( SongAndSteps(pSong, *st) );
for (Steps *st : vSteps)
if( stc.Matches(pSong, st) )
out.push_back( SongAndSteps(pSong, st) );
}
bool StepsUtil::HasMatching( const SongCriteria &soc, const StepsCriteria &stc )
{
const RString &sGroupName = soc.m_sGroupName.empty()? GROUP_ALL:soc.m_sGroupName;
const vector<Song*> &songs = SONGMAN->GetSongs( sGroupName );
const vector<Song*> &songs = SONGMAN->GetSongs( sGroupName );
FOREACH_CONST( Song*, songs, so )
{
if( soc.Matches(*so) && HasMatching(*so, stc) )
return true;
}
return false;
return std::any_of(songs.begin(), songs.end(), [&](Song const *so) {
return soc.Matches(so) && HasMatching(so, stc);
});
}
bool StepsUtil::HasMatching( const Song *pSong, const StepsCriteria &stc )
{
const vector<Steps*> &vSteps = stc.m_st == StepsType_Invalid? pSong->GetAllSteps():pSong->GetStepsByStepsType( stc.m_st );
FOREACH_CONST( Steps*, vSteps, st )
{
if( stc.Matches(pSong, *st) )
return true;
}
return false;
return std::any_of(vSteps.begin(), vSteps.end(), [&](Steps const *st) {
return stc.Matches(pSong, st);
});
}
// Sorting stuff