diff --git a/include/loot/metadata/file.h b/include/loot/metadata/file.h index 3ab92150..e7d1934d 100644 --- a/include/loot/metadata/file.h +++ b/include/loot/metadata/file.h @@ -63,19 +63,6 @@ public: const std::string& condition = "", const std::vector& detail = {}); - /** - * A less-than operator implemented with no semantics so that File objects can - * be stored in sets. - * @returns True if this File is less than the given File, false otherwise. - */ - LOOT_API bool operator<(const File& rhs) const; - - /** - * Check if two File objects are equal by comparing their fields. - * @returns True if the objects' fields are equal, false otherwise. - */ - LOOT_API bool operator==(const File& rhs) const; - /** * Get the filename of the file. * @return The file's filename. @@ -103,12 +90,26 @@ private: std::vector detail_; }; +/** + * Check if two File objects are equal by comparing their fields. + * @returns True if the objects' fields are equal, false otherwise. + */ +LOOT_API bool operator==(const File& lhs, const File& rhs); + /** * Check if two File objects are not equal. * @returns True if the File objects are not equal, false otherwise. */ LOOT_API bool operator!=(const File& lhs, const File& rhs); +/** + * A less-than operator implemented with no semantics so that File objects can + * be stored in sets. + * @returns True if the first File is less than the second File, false + * otherwise. + */ +LOOT_API bool operator<(const File& lhs, const File& rhs); + /** * Check if the first File object is greater than the second File object. * @returns True if the second File object is less than the first File object, diff --git a/src/api/metadata/file.cpp b/src/api/metadata/file.cpp index b57b633c..f6cb5039 100644 --- a/src/api/metadata/file.cpp +++ b/src/api/metadata/file.cpp @@ -37,49 +37,48 @@ File::File(const std::string& name, display_(display), detail_(detail) {} -bool File::operator<(const File& rhs) const { - if (display_ < rhs.display_) { - return true; - } - - if (rhs.display_ < display_) { - return false; - } - - if (this->GetCondition() < rhs.GetCondition()) { - return true; - } - - if (rhs.GetCondition() < this->GetCondition()) { - return false; - } - - if (name_ < rhs.name_) { - return true; - } - - if (rhs.name_ < name_) { - return false; - } - - return detail_ < rhs.detail_; -} - -bool File::operator==(const File& rhs) const { - return display_ == rhs.display_ && GetCondition() == rhs.GetCondition() && - name_ == rhs.name_ && detail_ == rhs.detail_; -} - Filename File::GetName() const { return name_; } -std::string File::GetDisplayName() const { - return display_; -} +std::string File::GetDisplayName() const { return display_; } std::vector File::GetDetail() const { return detail_; } +bool operator==(const File& lhs, const File& rhs) { + return lhs.GetDisplayName() == rhs.GetDisplayName() && + lhs.GetCondition() == rhs.GetCondition() && + lhs.GetName() == rhs.GetName() && lhs.GetDetail() == rhs.GetDetail(); +} + bool operator!=(const File& lhs, const File& rhs) { return !(lhs == rhs); } +bool operator<(const File& lhs, const File& rhs) { + if (lhs.GetDisplayName() < rhs.GetDisplayName()) { + return true; + } + + if (rhs.GetDisplayName() < lhs.GetDisplayName()) { + return false; + } + + if (lhs.GetCondition() < rhs.GetCondition()) { + return true; + } + + if (rhs.GetCondition() < lhs.GetCondition()) { + return false; + } + + if (lhs.GetName() < rhs.GetName()) { + return true; + } + + if (rhs.GetName() < lhs.GetName()) { + return false; + } + + return lhs.GetDetail() < rhs.GetDetail(); +} + bool operator>(const File& lhs, const File& rhs) { return rhs < lhs; } bool operator<=(const File& lhs, const File& rhs) { return !(lhs > rhs); }