diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-03-22 19:12:45 +1100 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-03-22 19:12:45 +1100 |
commit | e318098f0b5c761348d09b80d35585afc40a0905 (patch) | |
tree | 8c10362bbe25283df3071cf0bc1398a35443ecf8 /source/core | |
parent | 9b10964a3ea121c277c63d9bc370215753768df5 (diff) |
Add equality operator for Directives (fixes networking bug)
Diffstat (limited to 'source/core')
-rw-r--r-- | source/core/StarDirectives.cpp | 35 | ||||
-rw-r--r-- | source/core/StarDirectives.hpp | 14 |
2 files changed, 44 insertions, 5 deletions
diff --git a/source/core/StarDirectives.cpp b/source/core/StarDirectives.cpp index 245c8c0..4770200 100644 --- a/source/core/StarDirectives.cpp +++ b/source/core/StarDirectives.cpp @@ -46,7 +46,7 @@ Directives::Shared::Shared(List<Entry>&& givenEntries, String&& givenString, Str entries = std::move(givenEntries); string = std::move(givenString); prefix = givenPrefix; - hash = XXH3_64bits(string.utf8Ptr(), string.utf8Size()); + hash = string.empty() ? 0 : XXH3_64bits(string.utf8Ptr(), string.utf8Size()); } Directives::Directives() {} @@ -63,7 +63,7 @@ Directives::Directives(const char* directives) { parse(directives); } -Directives::Directives(Directives&& directives) { +Directives::Directives(Directives&& directives) noexcept { *this = std::move(directives); } @@ -99,7 +99,7 @@ Directives& Directives::operator=(const char* s) { return *this; } -Directives& Directives::operator=(Directives&& other) { +Directives& Directives::operator=(Directives&& other) noexcept { shared = std::move(other.shared); return *this; } @@ -215,6 +215,23 @@ bool Directives::empty() const { Directives::operator bool() const { return !empty(); } +bool Directives::equals(Directives const& other) const { + return hash() == other.hash(); +} + +bool Directives::equals(String const& string) const { + auto directiveString = stringPtr(); + return directiveString ? string == *directiveString : string.empty(); +} + +bool Directives::operator==(Directives const& other) const { + return equals(other); +} + +bool Directives::operator==(String const& string) const { + return equals(string); +} + DataStream& operator>>(DataStream& ds, Directives& directives) { String string; ds.read(string); @@ -233,6 +250,18 @@ DataStream& operator<<(DataStream & ds, Directives const& directives) { return ds; } +bool operator==(Directives const& d1, Directives const& d2) { + return d1.equals(d2); +} + +bool operator==(String const& string, Directives const& directives) { + return directives.equals(string); +} + +bool operator==(Directives const& directives, String const& string) { + return directives.equals(string); +} + DirectivesGroup::DirectivesGroup() : m_count(0) {} DirectivesGroup::DirectivesGroup(String const& directives) : m_count(0) { if (directives.empty()) diff --git a/source/core/StarDirectives.hpp b/source/core/StarDirectives.hpp index ec43b9d..e272915 100644 --- a/source/core/StarDirectives.hpp +++ b/source/core/StarDirectives.hpp @@ -44,13 +44,13 @@ public: Directives(String&& directives); Directives(const char* directives); Directives(Directives const& directives); - Directives(Directives&& directives); + Directives(Directives&& directives) noexcept; ~Directives(); Directives& operator=(String const& s); Directives& operator=(String&& s); Directives& operator=(const char* s); - Directives& operator=(Directives&& other); + Directives& operator=(Directives&& other) noexcept; Directives& operator=(Directives const& other); void loadOperations() const; @@ -65,9 +65,19 @@ public: bool empty() const; operator bool() const; + bool equals(Directives const& other) const; + bool equals(String const& string) const; + + bool operator==(Directives const& other) const; + bool operator==(String const& string) const; + friend DataStream& operator>>(DataStream& ds, Directives& directives); friend DataStream& operator<<(DataStream& ds, Directives const& directives); + //friend bool operator==(Directives const& d1, String const& d2); + //friend bool operator==(Directives const& directives, String const& string); + //friend bool operator==(String const& string, Directives const& directives); + std::shared_ptr<Shared const> shared; }; |