diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-06-30 19:28:35 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-06-30 19:28:35 +0200 |
| commit | 26a08e6eeabec972cf57c6eb4e8f91516ad07f0c (patch) | |
| tree | e9d899c2155e35e2abc81ed8d672e7b4eb3a8dc5 | |
| parent | 955bdfe3ae22039923d8d4df2ba3892031c55064 (diff) | |
| download | Project-Tick-26a08e6eeabec972cf57c6eb4e8f91516ad07f0c.tar.gz Project-Tick-26a08e6eeabec972cf57c6eb4e8f91516ad07f0c.zip | |
Create move_clone method
| -rw-r--r-- | include/tag.h | 3 | ||||
| -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-- | src/tag_compound.cpp | 5 | ||||
| -rw-r--r-- | src/tag_string.cpp | 5 |
6 files changed, 25 insertions, 0 deletions
diff --git a/include/tag.h b/include/tag.h index 29e63a9c54..acc537500f 100644 --- a/include/tag.h +++ b/include/tag.h @@ -21,6 +21,7 @@ #define TAG_H_INCLUDED #include <cstdint> +#include <memory> namespace nbt { @@ -52,6 +53,8 @@ public: ///Returns the type of the tag virtual tag_type get_type() const noexcept = 0; + virtual std::unique_ptr<tag> move_clone() && = 0; + friend bool operator==(const tag& lhs, const tag& rhs); friend bool operator!=(const tag& lhs, const tag& rhs); diff --git a/include/tag_compound.h b/include/tag_compound.h index e1d5218a9a..435fdbdff6 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -109,6 +109,8 @@ public: tag_type get_type() const noexcept override; + std::unique_ptr<tag> move_clone() && override; + private: std::map<std::string, value> tags; diff --git a/include/tag_primitive.h b/include/tag_primitive.h index bf8600c9f1..e35d462c48 100644 --- a/include/tag_primitive.h +++ b/include/tag_primitive.h @@ -53,6 +53,8 @@ public: tag_type get_type() const noexcept override; + std::unique_ptr<tag> move_clone() && override; + private: T value; @@ -110,6 +112,12 @@ tag_type tag_primitive<T>::get_type() const noexcept } template<class T> +std::unique_ptr<tag> tag_primitive<T>::move_clone() && +{ + return std::unique_ptr<tag>(new tag_primitive<T>(std::move(*this))); +} + +template<class T> bool tag_primitive<T>::equals(const tag& rhs) const { return value == static_cast<const tag_primitive<T>&>(rhs).value; diff --git a/include/tag_string.h b/include/tag_string.h index 05a2e1cb4d..456fa8ad08 100644 --- a/include/tag_string.h +++ b/include/tag_string.h @@ -47,6 +47,8 @@ public: tag_type get_type() const noexcept override; + std::unique_ptr<tag> move_clone() && override; + private: std::string value; diff --git a/src/tag_compound.cpp b/src/tag_compound.cpp index 5e9d81aaf7..20cb021df8 100644 --- a/src/tag_compound.cpp +++ b/src/tag_compound.cpp @@ -84,6 +84,11 @@ tag_type tag_compound::get_type() const noexcept return type; } +std::unique_ptr<tag> tag_compound::move_clone() && +{ + return std::unique_ptr<tag>(new tag_compound(std::move(*this))); +} + bool tag_compound::equals(const tag& rhs) const { return tags == static_cast<const tag_compound&>(rhs).tags; diff --git a/src/tag_string.cpp b/src/tag_string.cpp index 6a759088e5..6322d4a42c 100644 --- a/src/tag_string.cpp +++ b/src/tag_string.cpp @@ -72,6 +72,11 @@ tag_type tag_string::get_type() const noexcept return type; } +std::unique_ptr<tag> tag_string::move_clone() && +{ + return std::unique_ptr<tag>(new tag_string(std::move(*this))); +} + bool tag_string::equals(const tag& rhs) const { return value == static_cast<const tag_string&>(rhs).value; |
