Move overloaded symmetric operators out of File class

This commit is contained in:
Oliver Hamlet
2022-02-19 13:45:53 +00:00
parent d4de531de5
commit 0907f91b6f
2 changed files with 49 additions and 49 deletions
+14 -13
View File
@@ -63,19 +63,6 @@ public:
const std::string& condition = "",
const std::vector<MessageContent>& 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<MessageContent> 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,
+35 -36
View File
@@ -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<MessageContent> 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); }