Replace C++ comparison operators with <=>

This commit is contained in:
Oliver Hamlet
2025-06-11 22:13:53 +01:00
parent 4ffd62572d
commit 4e088e4dce
22 changed files with 211 additions and 646 deletions
+1
View File
@@ -48,6 +48,7 @@ set(LIBLOOT_SRC_TESTS_INTERFACE_H_FILES
"${CMAKE_SOURCE_DIR}/src/tests/api/interface/game_interface_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/api/interface/is_compatible_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/file_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/filename_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/group_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/location_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/message_test.h"
+5 -43
View File
@@ -98,6 +98,11 @@ public:
*/
LOOT_API std::string GetConstraint() const;
/**
* Compares two File objects.
*/
LOOT_API auto operator<=>(const File& rhs) const = default;
private:
Filename name_;
std::string display_;
@@ -105,49 +110,6 @@ private:
std::string condition_;
std::string constraint_;
};
/**
* 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,
* false otherwise.
*/
LOOT_API bool operator>(const File& lhs, const File& rhs);
/**
* Check if the first File object is less than or equal to the second File
* object.
* @returns True if the first File object is not greater than the second File
* object, false otherwise.
*/
LOOT_API bool operator<=(const File& lhs, const File& rhs);
/**
* Check if the first File object is greater than or equal to the second File
* object.
* @returns True if the first File object is not less than the second File
* object, false otherwise.
*/
LOOT_API bool operator>=(const File& lhs, const File& rhs);
}
#endif
+12 -40
View File
@@ -24,6 +24,7 @@
#ifndef LOOT_METADATA_FILENAME
#define LOOT_METADATA_FILENAME
#include <compare>
#include <string>
#include <string_view>
@@ -53,55 +54,26 @@ public:
private:
std::string filename_;
LOOT_API friend bool operator==(const Filename& lhs, const Filename& rhs);
LOOT_API friend std::weak_ordering operator<=>(const Filename& lhs,
const Filename& rhs);
LOOT_API friend bool operator<(const Filename& lhs, const Filename& rhs);
LOOT_API friend bool operator==(const Filename& lhs, const Filename& rhs);
};
/**
* Compare two Filename objects.
*
* Filenames are compared case-insensitively.
*/
LOOT_API std::weak_ordering operator<=>(const Filename& lhs,
const Filename& rhs);
/**
* Check if two Filename objects are equal by comparing their fields.
* @returns True if the filenames are case-insensitively equal and all other
* fields are case-sensitively equal, false otherwise.
*/
LOOT_API bool operator==(const Filename& lhs, const Filename& rhs);
/**
* Check if two Filename objects are not equal.
* @returns True if the Filename objects are not equal, false otherwise.
*/
LOOT_API bool operator!=(const Filename& lhs, const Filename& rhs);
/**
* A less-than operator implemented with no semantics so that Filename objects
* can be stored in sets.
* @returns True if this Filename is less than the given Filename, false
* otherwise.
*/
LOOT_API bool operator<(const Filename& lhs, const Filename& rhs);
/**
* Check if the first Filename object is greater than the second Filename
* object.
* @returns True if the second Filename object is less than the first Filename
* object, false otherwise.
*/
LOOT_API bool operator>(const Filename& lhs, const Filename& rhs);
/**
* Check if the first Filename object is less than or equal to the second
* Filename object.
* @returns True if the first Filename object is not greater than the second
* Filename object, false otherwise.
*/
LOOT_API bool operator<=(const Filename& lhs, const Filename& rhs);
/**
* Check if the first Filename object is greater than or equal to the second
* Filename object.
* @returns True if the first Filename object is not less than the second
* Filename object, false otherwise.
*/
LOOT_API bool operator>=(const Filename& lhs, const Filename& rhs);
}
#endif
+5 -44
View File
@@ -79,55 +79,16 @@ public:
*/
LOOT_API std::vector<std::string> GetAfterGroups() const;
/**
* Compares two Group objects.
*/
LOOT_API auto operator<=>(const Group& rhs) const = default;
private:
std::string name_{DEFAULT_NAME};
std::string description_;
std::vector<std::string> afterGroups_;
};
/**
* Check if two Group objects are equal by comparing their names.
* @returns True if the objects' fields are equal, false otherwise.
*/
LOOT_API bool operator==(const Group& lhs, const Group& rhs);
/**
* Check if two Group objects are not equal.
* @returns True if the Group objects are not equal, false otherwise.
*/
LOOT_API bool operator!=(const Group& lhs, const Group& rhs);
/**
* A less-than operator implemented with no semantics so that Group objects
* can be stored in sets.
* @returns True if the first Group is less than the second Group, false
* otherwise.
*/
LOOT_API bool operator<(const Group& lhs, const Group& rhs);
/**
* Check if the first Group object is greater than the second Group
* object.
* @returns True if the second Group object is less than the first Group
* object, false otherwise.
*/
LOOT_API bool operator>(const Group& lhs, const Group& rhs);
/**
* Check if the first Group object is less than or equal to the second
* Group object.
* @returns True if the first Group object is not greater than the second
* Group object, false otherwise.
*/
LOOT_API bool operator<=(const Group& lhs, const Group& rhs);
/**
* Check if the first Group object is greater than or equal to the second
* Group object.
* @returns True if the first Group object is not less than the second
* Group object, false otherwise.
*/
LOOT_API bool operator>=(const Group& lhs, const Group& rhs);
}
#endif
+5 -44
View File
@@ -63,54 +63,15 @@ public:
*/
LOOT_API std::string GetName() const;
/**
* Compares two Location objects.
*/
LOOT_API auto operator<=>(const Location& rhs) const = default;
private:
std::string url_;
std::string name_;
};
/**
* Check if two Location objects are equal by comparing their fields.
* @returns True if the objects' fields are equal, false otherwise.
*/
LOOT_API bool operator==(const Location& lhs, const Location& rhs);
/**
* Check if two Location objects are not equal.
* @returns True if the Location objects are not equal, false otherwise.
*/
LOOT_API bool operator!=(const Location& lhs, const Location& rhs);
/**
* A less-than operator implemented with no semantics so that Location objects
* can be stored in sets.
* @returns True if the first Location is less than the second Location, false
* otherwise.
*/
LOOT_API bool operator<(const Location& lhs, const Location& rhs);
/**
* Check if the first Location object is greater than the second Location
* object.
* @returns True if the second Location object is less than the first Location
* object, false otherwise.
*/
LOOT_API bool operator>(const Location& lhs, const Location& rhs);
/**
* Check if the first Location object is less than or equal to the second
* Location object.
* @returns True if the first Location object is not greater than the second
* Location object, false otherwise.
*/
LOOT_API bool operator<=(const Location& lhs, const Location& rhs);
/**
* Check if the first Location object is greater than or equal to the second
* Location object.
* @returns True if the first Location object is not less than the second
* Location object, false otherwise.
*/
LOOT_API bool operator>=(const Location& lhs, const Location& rhs);
}
#endif
+5 -43
View File
@@ -90,54 +90,16 @@ public:
*/
LOOT_API std::string GetCondition() const;
/**
* Compares two Message objects.
*/
LOOT_API auto operator<=>(const Message& rhs) const = default;
private:
MessageType type_{MessageType::say};
std::vector<MessageContent> content_;
std::string condition_;
};
/**
* Check if two Message objects are equal by comparing their fields.
* @returns True if the objects' fields are equal, false otherwise.
*/
LOOT_API bool operator==(const Message& lhs, const Message& rhs);
/**
* Check if two Message objects are not equal.
* @returns True if the Message objects are not equal, false otherwise.
*/
LOOT_API bool operator!=(const Message& lhs, const Message& rhs);
/**
* A less-than operator implemented with no semantics so that Message objects
* can be stored in sets.
* @returns Returns true if the first Message is less than the second Message,
* and false otherwise.
*/
LOOT_API bool operator<(const Message& lhs, const Message& rhs);
/**
* Check if the first Message object is greater than the second Message object.
* @returns True if the second Message object is less than the first Message
* object, false otherwise.
*/
LOOT_API bool operator>(const Message& lhs, const Message& rhs);
/**
* Check if the first Message object is less than or equal to the second
* Message object.
* @returns True if the first Message object is not greater than the second
* Message object, false otherwise.
*/
LOOT_API bool operator<=(const Message& lhs, const Message& rhs);
/**
* Check if the first Message object is greater than or equal to the second
* Message object.
* @returns True if the first Message object is not less than the second
* Message object, false otherwise.
*/
LOOT_API bool operator>=(const Message& lhs, const Message& rhs);
}
#endif
+5 -44
View File
@@ -71,55 +71,16 @@ public:
*/
LOOT_API std::string GetLanguage() const;
/**
* Compares two MessageContent objects.
*/
LOOT_API auto operator<=>(const MessageContent& rhs) const = default;
private:
std::string text_;
std::string language_{DEFAULT_LANGUAGE};
};
/**
* Check if two MessageContent objects are equal by comparing their fields.
* @returns True if the objects' fields are equal, false otherwise.
*/
LOOT_API bool operator==(const MessageContent& lhs, const MessageContent& rhs);
/**
* Check if two MessageContent objects are not equal.
* @returns True if the MessageContent objects are not equal, false otherwise.
*/
LOOT_API bool operator!=(const MessageContent& lhs, const MessageContent& rhs);
/**
* A less-than operator implemented with no semantics so that MessageContent
* objects can be stored in sets.
* @returns True if the first MessageContent is less than the second
* MessageContent, false otherwise.
*/
LOOT_API bool operator<(const MessageContent& lhs, const MessageContent& rhs);
/**
* Check if the first MessageContent object is greater than the second
* MessageContent object.
* @returns True if the second MessageContent object is less than the first
* MessageContent object, false otherwise.
*/
LOOT_API bool operator>(const MessageContent& lhs, const MessageContent& rhs);
/**
* Check if the first MessageContent object is less than or equal to the second
* MessageContent object.
* @returns True if the first MessageContent object is not greater than the
* second MessageContent object, false otherwise.
*/
LOOT_API bool operator<=(const MessageContent& lhs, const MessageContent& rhs);
/**
* Check if the first MessageContent object is greater than or equal to the
* second MessageContent object.
* @returns True if the first MessageContent object is not less than the second
* MessageContent object, false otherwise.
*/
LOOT_API bool operator>=(const MessageContent& lhs, const MessageContent& rhs);
/**
* Choose a MessageContent object from a vector given a language.
* @param content
@@ -122,6 +122,11 @@ public:
*/
LOOT_API std::vector<MessageContent> GetDetail() const;
/**
* Compares two PluginCleaningData objects.
*/
LOOT_API auto operator<=>(const PluginCleaningData& rhs) const = default;
private:
uint32_t crc_{0};
unsigned int itm_{0};
@@ -130,57 +135,6 @@ private:
std::string utility_;
std::vector<MessageContent> detail_;
};
/**
* Check if two PluginCleaningData objects are equal by comparing their
* fields.
* @returns True if the objects' fields are equal, false otherwise.
*/
LOOT_API bool operator==(const PluginCleaningData& lhs,
const PluginCleaningData& rhs);
/**
* Check if two MessageContent objects are not equal.
* @returns True if the MessageContent objects are not equal, false otherwise.
*/
LOOT_API bool operator!=(const PluginCleaningData& lhs,
const PluginCleaningData& rhs);
/**
* A less-than operator implemented with no semantics so that
* PluginCleaningData objects can be stored in sets.
* @returns True if the first PluginCleaningData is less than the second
* PluginCleaningData, false otherwise.
*/
LOOT_API bool operator<(const PluginCleaningData& lhs,
const PluginCleaningData& rhs);
/**
* Check if the first PluginCleaningData object is greater than the second
* PluginCleaningData object.
* @returns True if the second PluginCleaningData object is less than the first
* PluginCleaningData object, false otherwise.
*/
LOOT_API bool operator>(const PluginCleaningData& lhs,
const PluginCleaningData& rhs);
/**
* Check if the first PluginCleaningData object is less than or equal to the
* second PluginCleaningData object.
* @returns True if the first PluginCleaningData object is not greater than the
* second PluginCleaningData object, false otherwise.
*/
LOOT_API bool operator<=(const PluginCleaningData& lhs,
const PluginCleaningData& rhs);
/**
* Check if the first PluginCleaningData object is greater than or equal to the
* second PluginCleaningData object.
* @returns True if the first PluginCleaningData object is not less than the
* second PluginCleaningData object, false otherwise.
*/
LOOT_API bool operator>=(const PluginCleaningData& lhs,
const PluginCleaningData& rhs);
}
#endif
+15 -39
View File
@@ -24,6 +24,7 @@
#ifndef LOOT_METADATA_TAG
#define LOOT_METADATA_TAG
#include <compare>
#include <string>
#include <string_view>
@@ -73,53 +74,28 @@ public:
*/
LOOT_API std::string GetCondition() const;
/**
* Check if two Tag objects are equal.
* @returns True if the objects' fields are equal, false otherwise.
*/
LOOT_API bool operator==(const Tag& rhs) const = default;
private:
std::string name_;
bool addTag_{true};
std::string condition_;
LOOT_API friend std::strong_ordering operator<=>(const Tag& lhs,
const Tag& rhs);
};
/**
* Check if two Tag objects are equal.
* @returns True if the objects' fields are equal, false otherwise.
* Compares two Tag objects.
*
* Tag objects that suggest additions are considered less than those that
* suggest removals.
*/
LOOT_API bool operator==(const Tag& lhs, const Tag& rhs);
/**
* Check if two Tag objects are not equal.
* @returns True if the Tag objects are not equal, false otherwise.
*/
LOOT_API bool operator!=(const Tag& lhs, const Tag& rhs);
/**
* A less-than operator implemented with no semantics so that Tag objects
* can be stored in sets.
* @returns True if the first Tag is less than the second Tag, false otherwise.
*/
LOOT_API bool operator<(const Tag& lhs, const Tag& rhs);
/**
* Check if the first Tag object is greater than the second Tag object.
* @returns True if the second Tag object is less than the first Tag object,
* false otherwise.
*/
LOOT_API bool operator>(const Tag& lhs, const Tag& rhs);
/**
* Check if the first Tag object is less than or equal to the second Tag
* object.
* @returns True if the first Tag object is not greater than the second Tag
* object, false otherwise.
*/
LOOT_API bool operator<=(const Tag& lhs, const Tag& rhs);
/**
* Check if the first Tag object is greater than or equal to the second Tag
* object.
* @returns True if the first Tag object is not less than the second Tag
* object, false otherwise.
*/
LOOT_API bool operator>=(const Tag& lhs, const Tag& rhs);
LOOT_API std::strong_ordering operator<=>(const Tag& lhs, const Tag& rhs);
}
#endif
-51
View File
@@ -45,55 +45,4 @@ std::vector<MessageContent> File::GetDetail() const { return detail_; }
std::string File::GetCondition() const { return condition_; }
std::string File::GetConstraint() const { return constraint_; }
bool operator==(const File& lhs, const File& rhs) {
return lhs.GetDisplayName() == rhs.GetDisplayName() &&
lhs.GetCondition() == rhs.GetCondition() &&
lhs.GetConstraint() == rhs.GetConstraint() &&
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.GetConstraint() < rhs.GetConstraint()) {
return true;
}
if (rhs.GetConstraint() < lhs.GetConstraint()) {
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); }
bool operator>=(const File& lhs, const File& rhs) { return !(lhs < rhs); }
}
+16 -21
View File
@@ -33,27 +33,22 @@ Filename::Filename(std::string_view filename) : filename_(filename) {}
Filename::operator std::string() const { return filename_; }
std::weak_ordering operator<=>(const Filename& lhs, const Filename& rhs) {
auto result = loot::rust::new_filename(lhs.filename_)
->cmp(*loot::rust::new_filename(rhs.filename_));
if (result > 0) {
return std::weak_ordering::greater;
}
if (result == 0) {
return std::weak_ordering::equivalent;
}
return std::weak_ordering::less;
}
bool operator==(const Filename& lhs, const Filename& rhs) {
return loot::rust::new_filename(lhs.filename_)
->eq(*loot::rust::new_filename(rhs.filename_));
}
bool operator!=(const Filename& lhs, const Filename& rhs) {
return !(lhs == rhs);
}
bool operator<(const Filename& lhs, const Filename& rhs) {
return loot::rust::new_filename(lhs.filename_)
->lt(*loot::rust::new_filename(rhs.filename_));
}
bool operator>(const Filename& lhs, const Filename& rhs) { return rhs < lhs; }
bool operator<=(const Filename& lhs, const Filename& rhs) {
return !(lhs > rhs);
}
bool operator>=(const Filename& lhs, const Filename& rhs) {
return !(lhs < rhs);
return (lhs <=> rhs) == std::weak_ordering::equivalent;
}
}
-34
View File
@@ -35,38 +35,4 @@ std::string Group::GetName() const { return name_; }
std::string Group::GetDescription() const { return description_; }
std::vector<std::string> Group::GetAfterGroups() const { return afterGroups_; }
bool operator==(const Group& lhs, const Group& rhs) {
return lhs.GetName() == rhs.GetName() &&
lhs.GetDescription() == rhs.GetDescription() &&
lhs.GetAfterGroups() == rhs.GetAfterGroups();
}
bool operator!=(const Group& lhs, const Group& rhs) { return !(lhs == rhs); }
bool operator<(const Group& lhs, const Group& rhs) {
if (lhs.GetName() < rhs.GetName()) {
return true;
}
if (rhs.GetName() < lhs.GetName()) {
return false;
}
if (lhs.GetDescription() < rhs.GetDescription()) {
return true;
}
if (rhs.GetDescription() < lhs.GetDescription()) {
return false;
}
return lhs.GetAfterGroups() < rhs.GetAfterGroups();
}
bool operator>(const Group& lhs, const Group& rhs) { return rhs < lhs; }
bool operator<=(const Group& lhs, const Group& rhs) { return !(lhs > rhs); }
bool operator>=(const Group& lhs, const Group& rhs) { return !(lhs < rhs); }
}
-30
View File
@@ -31,34 +31,4 @@ Location::Location(std::string_view url, std::string_view name) :
std::string Location::GetURL() const { return url_; }
std::string Location::GetName() const { return name_; }
bool operator==(const Location& lhs, const Location& rhs) {
return lhs.GetURL() == rhs.GetURL() && lhs.GetName() == rhs.GetName();
}
bool operator!=(const Location& lhs, const Location& rhs) {
return !(lhs == rhs);
}
bool operator<(const Location& lhs, const Location& rhs) {
if (lhs.GetURL() < rhs.GetURL()) {
return true;
}
if (rhs.GetURL() < lhs.GetURL()) {
return false;
}
return lhs.GetName() < rhs.GetName();
}
bool operator>(const Location& lhs, const Location& rhs) { return rhs < lhs; }
bool operator<=(const Location& lhs, const Location& rhs) {
return !(lhs > rhs);
}
bool operator>=(const Location& lhs, const Location& rhs) {
return !(lhs < rhs);
}
}
-36
View File
@@ -54,40 +54,4 @@ MessageType Message::GetType() const { return type_; }
std::vector<MessageContent> Message::GetContent() const { return content_; }
std::string Message::GetCondition() const { return condition_; }
bool operator==(const Message& lhs, const Message& rhs) {
return lhs.GetType() == rhs.GetType() &&
lhs.GetCondition() == rhs.GetCondition() &&
lhs.GetContent() == rhs.GetContent();
}
bool operator!=(const Message& lhs, const Message& rhs) {
return !(lhs == rhs);
}
bool operator<(const Message& lhs, const Message& rhs) {
if (lhs.GetType() < rhs.GetType()) {
return true;
}
if (rhs.GetType() < lhs.GetType()) {
return false;
}
if (lhs.GetCondition() < rhs.GetCondition()) {
return true;
}
if (rhs.GetCondition() < lhs.GetCondition()) {
return false;
}
return lhs.GetContent() < rhs.GetContent();
}
bool operator>(const Message& lhs, const Message& rhs) { return rhs < lhs; }
bool operator<=(const Message& lhs, const Message& rhs) { return !(lhs > rhs); }
bool operator>=(const Message& lhs, const Message& rhs) { return !(lhs < rhs); }
}
-33
View File
@@ -33,39 +33,6 @@ std::string MessageContent::GetText() const { return text_; }
std::string MessageContent::GetLanguage() const { return language_; }
bool operator==(const MessageContent& lhs, const MessageContent& rhs) {
return lhs.GetText() == rhs.GetText() &&
lhs.GetLanguage() == rhs.GetLanguage();
}
bool operator!=(const MessageContent& lhs, const MessageContent& rhs) {
return !(lhs == rhs);
}
bool operator<(const MessageContent& lhs, const MessageContent& rhs) {
if (lhs.GetText() < rhs.GetText()) {
return true;
}
if (rhs.GetText() < lhs.GetText()) {
return false;
}
return lhs.GetLanguage() < rhs.GetLanguage();
}
bool operator>(const MessageContent& lhs, const MessageContent& rhs) {
return rhs < lhs;
}
bool operator<=(const MessageContent& lhs, const MessageContent& rhs) {
return !(lhs > rhs);
}
bool operator>=(const MessageContent& lhs, const MessageContent& rhs) {
return !(lhs < rhs);
}
std::optional<MessageContent> SelectMessageContent(
const std::vector<MessageContent> content,
std::string_view language) {
@@ -57,73 +57,4 @@ std::string PluginCleaningData::GetCleaningUtility() const { return utility_; }
std::vector<MessageContent> PluginCleaningData::GetDetail() const {
return detail_;
}
bool operator==(const PluginCleaningData& lhs, const PluginCleaningData& rhs) {
return lhs.GetCRC() == rhs.GetCRC() &&
lhs.GetITMCount() == rhs.GetITMCount() &&
lhs.GetDeletedReferenceCount() == rhs.GetDeletedReferenceCount() &&
lhs.GetDeletedNavmeshCount() == rhs.GetDeletedNavmeshCount() &&
lhs.GetCleaningUtility() == rhs.GetCleaningUtility() &&
lhs.GetDetail() == rhs.GetDetail();
}
bool operator!=(const PluginCleaningData& lhs, const PluginCleaningData& rhs) {
return !(lhs == rhs);
}
bool operator<(const PluginCleaningData& lhs, const PluginCleaningData& rhs) {
if (lhs.GetCRC() < rhs.GetCRC()) {
return true;
}
if (rhs.GetCRC() < lhs.GetCRC()) {
return false;
}
if (lhs.GetCleaningUtility() < rhs.GetCleaningUtility()) {
return true;
}
if (rhs.GetCleaningUtility() < lhs.GetCleaningUtility()) {
return false;
}
if (lhs.GetITMCount() < rhs.GetITMCount()) {
return true;
}
if (rhs.GetITMCount() < lhs.GetITMCount()) {
return false;
}
if (lhs.GetDeletedReferenceCount() < rhs.GetDeletedReferenceCount()) {
return true;
}
if (rhs.GetDeletedReferenceCount() < lhs.GetDeletedReferenceCount()) {
return false;
}
if (lhs.GetDeletedNavmeshCount() < rhs.GetDeletedNavmeshCount()) {
return true;
}
if (rhs.GetDeletedNavmeshCount() < lhs.GetDeletedNavmeshCount()) {
return false;
}
return lhs.GetDetail() < rhs.GetDetail();
}
bool operator>(const PluginCleaningData& lhs, const PluginCleaningData& rhs) {
return rhs < lhs;
}
bool operator<=(const PluginCleaningData& lhs, const PluginCleaningData& rhs) {
return !(lhs > rhs);
}
bool operator>=(const PluginCleaningData& lhs, const PluginCleaningData& rhs) {
return !(lhs < rhs);
}
}
+10 -23
View File
@@ -36,33 +36,20 @@ std::string Tag::GetName() const { return name_; }
std::string Tag::GetCondition() const { return condition_; }
bool operator==(const Tag& lhs, const Tag& rhs) {
return lhs.IsAddition() == rhs.IsAddition() &&
lhs.GetName() == rhs.GetName() &&
lhs.GetCondition() == rhs.GetCondition();
}
bool operator!=(const Tag& lhs, const Tag& rhs) { return !(lhs == rhs); }
bool operator<(const Tag& lhs, const Tag& rhs) {
std::strong_ordering operator<=>(const Tag& lhs, const Tag& rhs) {
if (lhs.IsAddition() != rhs.IsAddition()) {
return lhs.IsAddition() && !rhs.IsAddition();
if (lhs.IsAddition()) {
return std::strong_ordering::less;
}
return std::strong_ordering::greater;
}
if (lhs.GetName() < rhs.GetName()) {
return true;
auto nameOrder = lhs.GetName() <=> rhs.GetName();
if (nameOrder != std::strong_ordering::equal) {
return nameOrder;
}
if (rhs.GetName() < lhs.GetName()) {
return false;
}
return lhs.GetCondition() < rhs.GetCondition();
return lhs.GetCondition() <=> rhs.GetCondition();
}
bool operator>(const Tag& lhs, const Tag& rhs) { return rhs < lhs; }
bool operator<=(const Tag& lhs, const Tag& rhs) { return !(lhs > rhs); }
bool operator>=(const Tag& lhs, const Tag& rhs) { return !(lhs < rhs); }
}
+2
View File
@@ -615,6 +615,8 @@ mod ffi {
pub fn boxed_clone(&self) -> Box<Filename>;
pub fn cmp(&self, other: &Filename) -> i8;
pub fn eq(&self, other: &Filename) -> bool;
pub fn ne(&self, other: &Filename) -> bool;
+9 -1
View File
@@ -446,7 +446,7 @@ impl From<Box<File>> for libloot::metadata::File {
}
}
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Filename(libloot::metadata::Filename);
@@ -459,6 +459,14 @@ impl Filename {
Box::new(Self(self.0.clone()))
}
#[expect(
clippy::as_conversions,
reason = "Ordering is repr(i8) but provides no way to convert to i8 without 'as'"
)]
pub fn cmp(&self, other: &Self) -> i8 {
Ord::cmp(self, other) as i8
}
delegate! {
to self.0 {
pub fn as_str(&self) -> &str;
+1
View File
@@ -26,6 +26,7 @@
#include "loot/api.h"
#include "tests/api/interface/metadata/file_test.h"
#include "tests/api/interface/metadata/filename_test.h"
#include "tests/api/interface/metadata/group_test.h"
#include "tests/api/interface/metadata/location_test.h"
#include "tests/api/interface/metadata/message_content_test.h"

Some files were not shown because too many files have changed in this diff Show More