Remove COMPARE and COMPARE_FLOAT macros for equivalent if statements.

This is both for clarity, and to conform with the google c++ style
guide.

https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros
This commit is contained in:
Brandon W
2025-04-29 21:37:45 -07:00
committed by teejusb
parent 607b407007
commit 8dcb01f3ee
12 changed files with 171 additions and 172 deletions
+14 -16
View File
@@ -1455,22 +1455,20 @@ void Actor::TweenState::Init()
aux = 0; aux = 0;
} }
bool Actor::TweenState::operator==( const TweenState &other ) const bool Actor::TweenState::operator==(const TweenState& other) const {
{ if (pos != other.pos) return false;
#define COMPARE( x ) if( x != other.x ) return false; if (rotation != other.rotation) return false;
COMPARE( pos ); if (quat != other.quat) return false;
COMPARE( rotation ); if (scale != other.scale) return false;
COMPARE( quat ); if (fSkewX != other.fSkewX) return false;
COMPARE( scale ); if (fSkewY != other.fSkewY) return false;
COMPARE( fSkewX ); if (crop != other.crop) return false;
COMPARE( fSkewY ); if (fade != other.fade) return false;
COMPARE( crop ); for (unsigned i = 0; i < ARRAYLEN(diffuse); i++) {
COMPARE( fade ); if (diffuse[i] != other.diffuse[i]) return false;
for( unsigned i=0; i<ARRAYLEN(diffuse); i++ ) }
COMPARE( diffuse[i] ); if (glow != other.glow) return false;
COMPARE( glow ); if (aux != other.aux) return false;
COMPARE( aux );
#undef COMPARE
return true; return true;
} }
+11 -9
View File
@@ -13,15 +13,17 @@
#include <vector> #include <vector>
bool BackgroundDef::operator<( const BackgroundDef &other ) const bool BackgroundDef::operator<(const BackgroundDef& other) const {
{ if (m_sEffect != other.m_sEffect)
#define COMPARE(x) if( x < other.x ) return true; else if( x > other.x ) return false; return m_sEffect < other.m_sEffect;
COMPARE( m_sEffect ); if (m_sFile1 != other.m_sFile1)
COMPARE( m_sFile1 ); return m_sFile1 < other.m_sFile1;
COMPARE( m_sFile2 ); if (m_sFile2 != other.m_sFile2)
COMPARE( m_sColor1 ); return m_sFile2 < other.m_sFile2;
COMPARE( m_sColor2 ); if (m_sColor1 != other.m_sColor1)
#undef COMPARE return m_sColor1 < other.m_sColor1;
if (m_sColor2 != other.m_sColor2)
return m_sColor2 < other.m_sColor2;
return false; return false;
} }
+35 -32
View File
@@ -15,47 +15,50 @@ void DateTime::Init()
ZERO( *this ); ZERO( *this );
} }
bool DateTime::operator<( const DateTime& other ) const bool DateTime::operator<(const DateTime& other) const {
{ if (tm_year != other.tm_year) return tm_year < other.tm_year;
#define COMPARE( v ) if(v!=other.v) return v<other.v; if (tm_mon != other.tm_mon) return tm_mon < other.tm_mon;
COMPARE( tm_year ); if (tm_mday != other.tm_mday) return tm_mday < other.tm_mday;
COMPARE( tm_mon ); if (tm_hour != other.tm_hour) return tm_hour < other.tm_hour;
COMPARE( tm_mday ); if (tm_min != other.tm_min) return tm_min < other.tm_min;
COMPARE( tm_hour ); if (tm_sec != other.tm_sec) return tm_sec < other.tm_sec;
COMPARE( tm_min );
COMPARE( tm_sec );
#undef COMPARE
// they're equal
return false; return false;
} }
bool DateTime::operator==( const DateTime& other ) const bool DateTime::operator==(const DateTime& other) const {
{ if (tm_year != other.tm_year) return false;
#define COMPARE(x) if( x!=other.x ) return false; if (tm_mon != other.tm_mon) return false;
COMPARE( tm_year ); if (tm_mday != other.tm_mday) return false;
COMPARE( tm_mon ); if (tm_hour != other.tm_hour) return false;
COMPARE( tm_mday ); if (tm_min != other.tm_min) return false;
COMPARE( tm_hour ); if (tm_sec != other.tm_sec) return false;
COMPARE( tm_min );
COMPARE( tm_sec );
#undef COMPARE
return true; return true;
} }
bool DateTime::operator>( const DateTime& other ) const
{ bool DateTime::operator!=(const DateTime& other) const {
#define COMPARE( v ) if(v!=other.v) return v>other.v; return !(*this == other);
COMPARE( tm_year ); }
COMPARE( tm_mon );
COMPARE( tm_mday ); bool DateTime::operator>(const DateTime& other) const {
COMPARE( tm_hour ); if (tm_year != other.tm_year) return tm_year > other.tm_year;
COMPARE( tm_min ); if (tm_mon != other.tm_mon) return tm_mon > other.tm_mon;
COMPARE( tm_sec ); if (tm_mday != other.tm_mday) return tm_mday > other.tm_mday;
#undef COMPARE if (tm_hour != other.tm_hour) return tm_hour > other.tm_hour;
// they're equal if (tm_min != other.tm_min) return tm_min > other.tm_min;
if (tm_sec != other.tm_sec) return tm_sec > other.tm_sec;
return false; return false;
} }
bool DateTime::operator<=(const DateTime& other) const {
return !(*this > other); // Reuse the > operator
}
bool DateTime::operator>=(const DateTime& other) const {
return !(*this < other); // Reuse the < operator
}
DateTime DateTime::GetNowDateTime() DateTime DateTime::GetNowDateTime()
{ {
time_t now = time(nullptr); time_t now = time(nullptr);
+3 -3
View File
@@ -109,18 +109,18 @@ struct DateTime
* @brief Determine if this DateTime is not equal to some other time. * @brief Determine if this DateTime is not equal to some other time.
* @param other the other DateTime to check. * @param other the other DateTime to check.
* @return true if this is not equal to the other time, or false otherwise. */ * @return true if this is not equal to the other time, or false otherwise. */
bool operator!=( const DateTime& other ) const { return !operator==(other); } bool operator!=(const DateTime& other) const;
/** /**
* @brief Determine if this DateTime is less than or equal to some other time. * @brief Determine if this DateTime is less than or equal to some other time.
* @param other the other DateTime to check. * @param other the other DateTime to check.
* @return true if this is less than or equal to the other time, or false otherwise. */ * @return true if this is less than or equal to the other time, or false otherwise. */
bool operator<=( const DateTime& other ) const { return !operator>(other); } bool operator<=(const DateTime& other) const;
/** /**
* @brief Determine if this DateTime is greater than or equal to some other time. * @brief Determine if this DateTime is greater than or equal to some other time.
* @param other the other DateTime to check. * @param other the other DateTime to check.
* @return true if this is greater than or equal to the other time, or false otherwise. */ * @return true if this is greater than or equal to the other time, or false otherwise. */
bool operator>=( const DateTime& other ) const { return !operator<(other); } bool operator>=(const DateTime& other) const;
/** /**
* @brief Retrieve the current date and time. * @brief Retrieve the current date and time.
+5 -8
View File
@@ -17,16 +17,13 @@ public:
* @brief Determine if one DisplayResolution is less than the other. * @brief Determine if one DisplayResolution is less than the other.
* @param other the other DisplayResolution to check. * @param other the other DisplayResolution to check.
* @return true if this DisplayResolution is less than the other, or false otherwise. */ * @return true if this DisplayResolution is less than the other, or false otherwise. */
bool operator<( const DisplayResolution &other ) const bool operator<(const DisplayResolution& other) const {
{ if (iWidth != other.iWidth) return iWidth < other.iWidth;
/** @brief A quick way to compare the two DisplayResolutions. */ if (iHeight != other.iHeight) return iHeight < other.iHeight;
#define COMPARE(x) if( x != other.x ) return x < other.x; if (bStretched != other.bStretched) return bStretched < other.bStretched;
COMPARE( iWidth );
COMPARE( iHeight );
COMPARE( bStretched );
#undef COMPARE
return false; return false;
} }
}; };
/** @brief The collection of DisplayResolutions available within the program. */ /** @brief The collection of DisplayResolutions available within the program. */
typedef std::set<DisplayResolution> DisplayResolutions; typedef std::set<DisplayResolution> DisplayResolutions;
+5 -8
View File
@@ -22,17 +22,14 @@ struct DisplayMode {
* configuration * configuration
*/ */
bool operator<( const DisplayMode &other ) const bool operator<(const DisplayMode& other) const {
{ if (width != other.width) return width < other.width;
/** @brief A quick way to compare the two DisplayResolutions. */ if (height != other.height) return height < other.height;
#define COMPARE(x) if( x != other.x ) return x < other.x; if (refreshRate != other.refreshRate) return refreshRate < other.refreshRate;
COMPARE( width );
COMPARE( height );
COMPARE( refreshRate );
#undef COMPARE
return false; return false;
} }
// Lua // Lua
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
}; };
+24 -25
View File
@@ -44,34 +44,33 @@ struct HighScoreImpl
bool operator!=( const HighScoreImpl& other ) const { return !(*this == other); } bool operator!=( const HighScoreImpl& other ) const { return !(*this == other); }
}; };
bool HighScoreImpl::operator==( const HighScoreImpl& other ) const bool HighScoreImpl::operator==(const HighScoreImpl& other) const {
{ if (sName != other.sName) return false;
#define COMPARE(x) if( x!=other.x ) return false; if (grade != other.grade) return false;
COMPARE( sName ); if (iScore != other.iScore) return false;
COMPARE( grade ); if (iMaxCombo != other.iMaxCombo) return false;
COMPARE( iScore ); if (stageAward != other.stageAward) return false;
COMPARE( iMaxCombo ); if (peakComboAward != other.peakComboAward) return false;
COMPARE( stageAward ); if (fPercentDP != other.fPercentDP) return false;
COMPARE( peakComboAward ); if (fSurviveSeconds != other.fSurviveSeconds) return false;
COMPARE( fPercentDP ); if (sModifiers != other.sModifiers) return false;
COMPARE( fSurviveSeconds ); if (dateTime != other.dateTime) return false;
COMPARE( sModifiers ); if (sPlayerGuid != other.sPlayerGuid) return false;
COMPARE( dateTime ); if (sMachineGuid != other.sMachineGuid) return false;
COMPARE( sPlayerGuid ); if (iProductID != other.iProductID) return false;
COMPARE( sMachineGuid ); FOREACH_ENUM(TapNoteScore, tns) {
COMPARE( iProductID ); if (iTapNoteScores[tns] != other.iTapNoteScores[tns]) return false;
FOREACH_ENUM( TapNoteScore, tns ) }
COMPARE( iTapNoteScores[tns] ); FOREACH_ENUM(HoldNoteScore, hns) {
FOREACH_ENUM( HoldNoteScore, hns ) if (iHoldNoteScores[hns] != other.iHoldNoteScores[hns]) return false;
COMPARE( iHoldNoteScores[hns] ); }
COMPARE( radarValues ); if (radarValues != other.radarValues) return false;
COMPARE( fLifeRemainingSeconds ); if (fLifeRemainingSeconds != other.fLifeRemainingSeconds) return false;
COMPARE( bDisqualified ); if (bDisqualified != other.bDisqualified) return false;
#undef COMPARE
return true; return true;
} }
HighScoreImpl::HighScoreImpl() HighScoreImpl::HighScoreImpl()
{ {
sName = ""; sName = "";
+9 -12
View File
@@ -209,18 +209,15 @@ struct TapNote
* @brief Determine if the two TapNotes are equal to each other. * @brief Determine if the two TapNotes are equal to each other.
* @param other the other TapNote we're checking. * @param other the other TapNote we're checking.
* @return true if the two TapNotes are equal, or false otherwise. */ * @return true if the two TapNotes are equal, or false otherwise. */
bool operator==( const TapNote &other ) const bool operator==(const TapNote& other) const {
{ if (type != other.type) return false;
#define COMPARE(x) if(x!=other.x) return false if (subType != other.subType) return false;
COMPARE(type); if (source != other.source) return false;
COMPARE(subType); if (sAttackModifiers != other.sAttackModifiers) return false;
COMPARE(source); if (fAttackDurationSeconds != other.fAttackDurationSeconds) return false;
COMPARE(sAttackModifiers); if (iKeysoundIndex != other.iKeysoundIndex) return false;
COMPARE(fAttackDurationSeconds); if (iDuration != other.iDuration) return false;
COMPARE(iKeysoundIndex); if (pn != other.pn) return false;
COMPARE(iDuration);
COMPARE(pn);
#undef COMPARE
return true; return true;
} }
/** /**
+6 -8
View File
@@ -315,16 +315,14 @@ public:
T GetCenterX() const { return (left+right)/2; }; T GetCenterX() const { return (left+right)/2; };
T GetCenterY() const { return (top+bottom)/2; }; T GetCenterY() const { return (top+bottom)/2; };
bool operator==( const Rect &other ) const bool operator==(const Rect& other) const {
{ if (left != other.left) return false;
#define COMPARE( x ) if( x != other.x ) return false if (top != other.top) return false;
COMPARE( left ); if (right != other.right) return false;
COMPARE( top ); if (bottom != other.bottom) return false;
COMPARE( right );
COMPARE( bottom );
#undef COMPARE
return true; return true;
} }
bool operator!=( const Rect &other ) const { return !operator==(other); } bool operator!=( const Rect &other ) const { return !operator==(other); }
T left, top, right, bottom; T left, top, right, bottom;
+11 -14
View File
@@ -183,20 +183,17 @@ bool SongOptions::FromOneModString( const RString &sOneMod, RString &sErrorOut )
return true; return true;
} }
bool SongOptions::operator==( const SongOptions &other ) const bool SongOptions::operator==(const SongOptions& other) const {
{ if (m_fMusicRate != other.m_fMusicRate) return false;
#define COMPARE(x) { if( x != other.x ) return false; } if (m_fHaste != other.m_fHaste) return false;
COMPARE( m_fMusicRate ); if (m_bAssistClap != other.m_bAssistClap) return false;
COMPARE( m_fHaste ); if (m_bAssistMetronome != other.m_bAssistMetronome) return false;
COMPARE( m_bAssistClap ); if (m_AutosyncType != other.m_AutosyncType) return false;
COMPARE( m_bAssistMetronome ); if (m_SoundEffectType != other.m_SoundEffectType) return false;
COMPARE( m_AutosyncType ); if (m_bStaticBackground != other.m_bStaticBackground) return false;
COMPARE( m_SoundEffectType ); if (m_bRandomBGOnly != other.m_bRandomBGOnly) return false;
COMPARE( m_bStaticBackground ); if (m_bSaveScore != other.m_bSaveScore) return false;
COMPARE( m_bRandomBGOnly ); if (m_bSaveReplay != other.m_bSaveReplay) return false;
COMPARE( m_bSaveScore );
COMPARE( m_bSaveReplay );
#undef COMPARE
return true; return true;
} }
+42 -25
View File
@@ -40,9 +40,6 @@ const RString& TimingSegmentTypeToString( TimingSegmentType tst );
const int ROW_INVALID = -1; const int ROW_INVALID = -1;
#define COMPARE(x) if( this->x!=other.x ) return false
#define COMPARE_FLOAT(x) if( std::abs(this->x - other.x) > EPSILON ) return false
/** /**
* @brief The base timing segment for make glorious benefit wolfman * @brief The base timing segment for make glorious benefit wolfman
* XXX: this should be an abstract class. * XXX: this should be an abstract class.
@@ -66,6 +63,11 @@ struct TimingSegment
// for our purposes, two floats within this level of error are equal // for our purposes, two floats within this level of error are equal
static constexpr double EPSILON = 1e-6; static constexpr double EPSILON = 1e-6;
// A helper for testing equality of two floats within a level of error epsilon.
bool AreEqual(float f1, float f2) const {
return std::abs(f1 - f2) < EPSILON;
}
virtual ~TimingSegment() { } virtual ~TimingSegment() { }
/** /**
@@ -161,7 +163,9 @@ struct FakeSegment : public TimingSegment
bool operator==( const FakeSegment &other ) const bool operator==( const FakeSegment &other ) const
{ {
COMPARE( m_iLengthRows ); if (m_iLengthRows != other.m_iLengthRows) {
return false;
}
return true; return true;
} }
@@ -219,7 +223,9 @@ struct WarpSegment : public TimingSegment
bool operator==( const WarpSegment &other ) const bool operator==( const WarpSegment &other ) const
{ {
COMPARE( m_iLengthRows ); if (m_iLengthRows != other.m_iLengthRows) {
return false;
}
return true; return true;
} }
@@ -274,7 +280,9 @@ struct TickcountSegment : public TimingSegment
bool operator==( const TickcountSegment &other ) const bool operator==( const TickcountSegment &other ) const
{ {
COMPARE( m_iTicksPerBeat ); if (m_iTicksPerBeat != other.m_iTicksPerBeat) {
return false;
}
return true; return true;
} }
@@ -326,8 +334,12 @@ struct ComboSegment : public TimingSegment
bool operator==( const ComboSegment &other ) const bool operator==( const ComboSegment &other ) const
{ {
COMPARE( m_iCombo ); if (m_iCombo != other.m_iCombo) {
COMPARE( m_iMissCombo ); return false;
}
if (m_iMissCombo != other.m_iMissCombo) {
return false;
}
return true; return true;
} }
@@ -379,7 +391,9 @@ struct LabelSegment : public TimingSegment
bool operator==( const LabelSegment &other ) const bool operator==( const LabelSegment &other ) const
{ {
COMPARE( m_sLabel ); if (m_sLabel != other.m_sLabel) {
return false;
}
return true; return true;
} }
@@ -427,8 +441,7 @@ struct BPMSegment : public TimingSegment
bool operator==( const BPMSegment &other ) const bool operator==( const BPMSegment &other ) const
{ {
COMPARE_FLOAT( m_fBPS ); return AreEqual(m_fBPS, other.m_fBPS);
return true;
} }
bool operator==( const TimingSegment &other ) const bool operator==( const TimingSegment &other ) const
@@ -499,8 +512,12 @@ struct TimeSignatureSegment : public TimingSegment
bool operator==( const TimeSignatureSegment &other ) const bool operator==( const TimeSignatureSegment &other ) const
{ {
COMPARE( m_iNumerator ); if (m_iNumerator != other.m_iNumerator) {
COMPARE( m_iDenominator ); return false;
}
if (m_iDenominator != other.m_iDenominator) {
return false;
}
return true; return true;
} }
@@ -566,9 +583,15 @@ struct SpeedSegment : public TimingSegment
bool operator==( const SpeedSegment &other ) const bool operator==( const SpeedSegment &other ) const
{ {
COMPARE_FLOAT( m_fRatio ); if (!AreEqual(m_fRatio, other.m_fRatio)) {
COMPARE_FLOAT( m_fDelay ); return false;
COMPARE( m_Unit ); }
if (!AreEqual(m_fDelay, other.m_fDelay)) {
return false;
}
if (m_Unit != other.m_Unit) {
return false;
}
return true; return true;
} }
@@ -626,8 +649,7 @@ struct ScrollSegment : public TimingSegment
bool operator==( const ScrollSegment &other ) const bool operator==( const ScrollSegment &other ) const
{ {
COMPARE_FLOAT( m_fRatio ); return AreEqual(m_fRatio, other.m_fRatio);
return true;
} }
bool operator==( const TimingSegment &other ) const bool operator==( const TimingSegment &other ) const
@@ -671,8 +693,7 @@ struct StopSegment : public TimingSegment
bool operator==( const StopSegment &other ) const bool operator==( const StopSegment &other ) const
{ {
COMPARE_FLOAT( m_fSeconds ); return AreEqual(m_fSeconds, other.m_fSeconds);
return true;
} }
bool operator==( const TimingSegment &other ) const bool operator==( const TimingSegment &other ) const
@@ -715,8 +736,7 @@ struct DelaySegment : public TimingSegment
bool operator==( const DelaySegment &other ) const bool operator==( const DelaySegment &other ) const
{ {
COMPARE_FLOAT( m_fSeconds ); return AreEqual(m_fSeconds, other.m_fSeconds);
return true;
} }
bool operator==( const TimingSegment &other ) const bool operator==( const TimingSegment &other ) const
@@ -731,9 +751,6 @@ private:
float m_fSeconds; float m_fSeconds;
}; };
#undef COMPARE
#undef COMPARE_FLOAT
#endif #endif
/** /**
+5 -11
View File
@@ -26,18 +26,12 @@ LuaXType(MemoryCardDriverType);
Preference<MemoryCardDriverType> g_MemoryCardDriver("MemoryCardDriver", MemoryCardDriverType_Usb, nullptr, PreferenceType::Immutable); Preference<MemoryCardDriverType> g_MemoryCardDriver("MemoryCardDriver", MemoryCardDriverType_Usb, nullptr, PreferenceType::Immutable);
bool UsbStorageDevice::operator==(const UsbStorageDevice& other) const bool UsbStorageDevice::operator==(const UsbStorageDevice& other) const {
{ if (iBus != other.iBus) return false;
// LOG->Trace( "Comparing %d %d %d %s %s to %d %d %d %s %s", if (iPort != other.iPort) return false;
// iBus, iPort, iLevel, sName.c_str(), sOsMountDir.c_str(), if (iLevel != other.iLevel) return false;
// other.iBus, other.iPort, other.iLevel, other.sName.c_str(), other.sOsMountDir.c_str() ); if (sOsMountDir != other.sOsMountDir) return false;
#define COMPARE(x) if( x != other.x ) return false
COMPARE( iBus );
COMPARE( iPort );
COMPARE( iLevel );
COMPARE( sOsMountDir );
return true; return true;
#undef COMPARE
} }
void UsbStorageDevice::SetOsMountDir( const RString &s ) void UsbStorageDevice::SetOsMountDir( const RString &s )