diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-06-28 16:54:16 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-06-28 16:54:16 +0200 |
| commit | e040454ca3ba94b4a4c13c51a2cb3dd5cba8749b (patch) | |
| tree | e1d5a059411aa777798de1f5d2e271e508e48df3 | |
| parent | 6c1c90d668915ce698fe71a53891986e82d4af7a (diff) | |
| download | Project-Tick-e040454ca3ba94b4a4c13c51a2cb3dd5cba8749b.tar.gz Project-Tick-e040454ca3ba94b4a4c13c51a2cb3dd5cba8749b.zip | |
Add operator== and equals for tag
| -rw-r--r-- | include/tag.h | 6 | ||||
| -rw-r--r-- | include/tag_compound.h | 2 | ||||
| -rw-r--r-- | include/tag_primitive.h | 8 | ||||
| -rw-r--r-- | include/tag_string.h | 2 | ||||
| -rw-r--r-- | test/nbttest.cpp | 2 |
5 files changed, 19 insertions, 1 deletions
diff --git a/include/tag.h b/include/tag.h index 56d3594474..2bca595f9d 100644 --- a/include/tag.h +++ b/include/tag.h @@ -51,6 +51,12 @@ public: ///Returns the type of the tag virtual tag_type get_type() const noexcept = 0; + + friend bool operator==(const tag& lhs, const tag& rhs); + friend bool operator!=(const tag& lhs, const tag& rhs); + +private: + virtual bool equals(const tag& rhs) const = 0; }; } diff --git a/include/tag_compound.h b/include/tag_compound.h index 8fdc2f6617..51f0cd2709 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -92,6 +92,8 @@ public: private: + + bool equals(const tag& rhs) const override; }; } diff --git a/include/tag_primitive.h b/include/tag_primitive.h index 5704da4430..4c210ff0a8 100644 --- a/include/tag_primitive.h +++ b/include/tag_primitive.h @@ -55,6 +55,8 @@ public: private: T value; + + bool equals(const tag& rhs) const override; }; //Typedefs that should be used instead of the template tag_primitive. @@ -107,6 +109,12 @@ tag_type tag_primitive<T>::get_type() const noexcept return type; } +template<class T> +bool tag_primitive<T>::equals(const tag& rhs) const +{ + return value == static_cast<const tag_primitive<T>&>(rhs).value; +} + } #endif // TAG_PRIMITIVE_H_INCLUDED diff --git a/include/tag_string.h b/include/tag_string.h index 28d1b77085..1daa0c2c6b 100644 --- a/include/tag_string.h +++ b/include/tag_string.h @@ -52,6 +52,8 @@ public: private: std::string value; + + bool equals(const tag& rhs) const override; }; } diff --git a/test/nbttest.cpp b/test/nbttest.cpp index b77c9b85bf..a596259050 100644 --- a/test/nbttest.cpp +++ b/test/nbttest.cpp @@ -112,7 +112,7 @@ void test_tag_compound() {"baz", -2.0}, {"quux", tag_compound{{"Hello", "World"}, {"zero", 0}}} }*/; - //ASSERT(comp == comp2); + ASSERT(comp == comp2); ASSERT(comp != (const tag_compound&)comp2["quux"]); ASSERT(comp != comp2["quux"]); } |
