From 5fac8c030dc424faf77cb68aa86feeb119de4a68 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 30 Jul 2006 11:30:29 +0000 Subject: [PATCH] Add operator== and operator!= as well as getting all matching steps for a particular song. --- stepmania/src/SongUtil.h | 9 +++++++++ stepmania/src/StepsUtil.cpp | 18 +++++++++++------- stepmania/src/StepsUtil.h | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/stepmania/src/SongUtil.h b/stepmania/src/SongUtil.h index 37027a9d59..006330f1ef 100644 --- a/stepmania/src/SongUtil.h +++ b/stepmania/src/SongUtil.h @@ -35,6 +35,15 @@ public: } bool Matches( const Song *p ) const; + bool operator==( const SongCriteria &other ) const + { +#define X(x) (x == other.x) + return X(m_sGroupName) && X(m_bUseSongGenreAllowedList) && X(m_vsSongGenreAllowedList) && + X(m_Selectable) && X(m_bUseSongAllowedList) && X(m_vpSongAllowedList) && + X(m_iStagesForSong) && X(m_Tutorial) && X(m_Locked); +#undef X + } + bool operator!=( const SongCriteria &other ) const { return !operator==( other ); } }; namespace SongUtil diff --git a/stepmania/src/StepsUtil.cpp b/stepmania/src/StepsUtil.cpp index 6beeeaa609..f63add5287 100644 --- a/stepmania/src/StepsUtil.cpp +++ b/stepmania/src/StepsUtil.cpp @@ -45,16 +45,20 @@ void StepsUtil::GetAllMatching( const SongCriteria &soc, const StepsCriteria &st { if( !soc.Matches(*so) ) continue; - FOREACH_CONST( Steps*, (*so)->GetAllSteps(), st ) - { - if( !stc.Matches(*so,*st) ) - continue; - SongAndSteps sas = { *so, *st }; - out.push_back( sas ); - } + GetAllMatching( *so, stc, out ); } } +void StepsUtil::GetAllMatching( Song *pSong, const StepsCriteria &stc, vector &out ) +{ + const vector &vSteps = ( stc.m_st == STEPS_TYPE_INVALID ? pSong->GetAllSteps() : + pSong->GetStepsByStepsType(stc.m_st) ); + + FOREACH_CONST( Steps*, vSteps, st ) + if( stc.Matches(pSong, *st) ) + out.push_back( SongAndSteps(pSong, *st) ); +} + // // Sorting stuff diff --git a/stepmania/src/StepsUtil.h b/stepmania/src/StepsUtil.h index 3948bb32bd..6ed7212ac4 100644 --- a/stepmania/src/StepsUtil.h +++ b/stepmania/src/StepsUtil.h @@ -29,13 +29,22 @@ public: } bool Matches( const Song *pSong, const Steps *pSteps ) const; + bool operator==( const StepsCriteria &other ) const + { +#define X(x) (x == other.x) + return X(m_difficulty) && X(m_iLowMeter) && X(m_iHighMeter) && X(m_st) && X(m_Locked); +#undef X + } + bool operator!=( const StepsCriteria &other ) const { return !operator==( other ); } }; class SongAndSteps { public: - Song* pSong; - Steps* pSteps; + Song *pSong; + Steps *pSteps; + SongAndSteps() : pSong(NULL), pSteps(NULL) { } + SongAndSteps( Song *pSong_, Steps *pSteps_ ) : pSong(pSong_), pSteps(pSteps_) { } bool operator==( const SongAndSteps& other ) const { return pSong==other.pSong && pSteps==other.pSteps; } bool operator<( const SongAndSteps& other ) const { return pSong<=other.pSong && pSteps<=other.pSteps; } }; @@ -43,6 +52,7 @@ public: namespace StepsUtil { void GetAllMatching( const SongCriteria &soc, const StepsCriteria &stc, vector &out ); // look up in SONGMAN + void GetAllMatching( Song *pSong, const StepsCriteria &stc, vector &out ); bool CompareNotesPointersByRadarValues(const Steps* pSteps1, const Steps* pSteps2); bool CompareNotesPointersByMeter(const Steps *pSteps1, const Steps* pSteps2);