From d648754b1f35e7a6465869157ae9afa0b0ee451d Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Wed, 1 Jul 2015 19:17:50 +0200 Subject: Overload operator== for each tag individually --- include/tag_compound.h | 3 +++ include/tag_primitive.h | 17 ++++++++++++++++- include/tag_string.h | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/tag_compound.h b/include/tag_compound.h index 435fdbdff6..fb2d27123a 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -115,6 +115,9 @@ private: std::map tags; bool equals(const tag& rhs) const override; + + friend bool operator==(const tag_compound& lhs, const tag_compound& rhs); + friend bool operator!=(const tag_compound& lhs, const tag_compound& rhs); }; template diff --git a/include/tag_primitive.h b/include/tag_primitive.h index e35d462c48..73c7b1e727 100644 --- a/include/tag_primitive.h +++ b/include/tag_primitive.h @@ -61,6 +61,9 @@ private: bool equals(const tag& rhs) const override; }; +template bool operator==(const tag_primitive& lhs, const tag_primitive& rhs); +template bool operator!=(const tag_primitive& lhs, const tag_primitive& rhs); + //Typedefs that should be used instead of the template tag_primitive. typedef tag_primitive tag_byte; typedef tag_primitive tag_short; @@ -120,7 +123,19 @@ std::unique_ptr tag_primitive::move_clone() && template bool tag_primitive::equals(const tag& rhs) const { - return value == static_cast&>(rhs).value; + return *this == static_cast&>(rhs); +} + +template +bool operator==(const tag_primitive& lhs, const tag_primitive& rhs) +{ + return lhs.get() == rhs.get(); +} + +template +bool operator!=(const tag_primitive& lhs, const tag_primitive& rhs) +{ + return !(lhs == rhs); } } diff --git a/include/tag_string.h b/include/tag_string.h index 456fa8ad08..f1b622eee9 100644 --- a/include/tag_string.h +++ b/include/tag_string.h @@ -55,6 +55,9 @@ private: bool equals(const tag& rhs) const override; }; +bool operator==(const tag_string& lhs, const tag_string& rhs); +bool operator!=(const tag_string& lhs, const tag_string& rhs); + } #endif // TAG_STRING_H_INCLUDED -- cgit 0.0.5-2-1-g0f52