summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-07-01 19:48:04 +0200
committerljfa-ag <ljfa-ag@web.de>2015-07-01 19:48:04 +0200
commit2345716fbdf380dde60cccb71cbc335cf587fec6 (patch)
treedd673eb847666a2d4db272a3e3e01bb4a6b148cf
parent6168f3ad47a5eddd6b10a84455f8fbd5a9852818 (diff)
downloadProject-Tick-2345716fbdf380dde60cccb71cbc335cf587fec6.tar.gz
Project-Tick-2345716fbdf380dde60cccb71cbc335cf587fec6.zip
Create tag::assign method
Implement value::operator= in terms of it
-rw-r--r--include/tag.h8
-rw-r--r--include/tag_compound.h2
-rw-r--r--include/tag_primitive.h8
-rw-r--r--include/tag_string.h2
-rw-r--r--src/tag_compound.cpp5
-rw-r--r--src/tag_string.cpp5
-rw-r--r--src/value.cpp4
7 files changed, 33 insertions, 1 deletions
diff --git a/include/tag.h b/include/tag.h
index acc537500f..a9cbc0019f 100644
--- a/include/tag.h
+++ b/include/tag.h
@@ -64,6 +64,14 @@ private:
* @param rhs an instance of the same class as @c *this
*/
virtual bool equals(const tag& rhs) const = 0;
+
+ /**
+ * @brief Assigns the given tag if the class is the same
+ * @throw std::bad_cast if @c rhs is not the same type as @c *this
+ */
+ virtual tag& assign(tag&& rhs) = 0;
+
+ friend class value;
};
}
diff --git a/include/tag_compound.h b/include/tag_compound.h
index fb2d27123a..32380a0c6c 100644
--- a/include/tag_compound.h
+++ b/include/tag_compound.h
@@ -116,6 +116,8 @@ private:
bool equals(const tag& rhs) const override;
+ tag_compound& assign(tag&& rhs) override;
+
friend bool operator==(const tag_compound& lhs, const tag_compound& rhs);
friend bool operator!=(const tag_compound& lhs, const tag_compound& rhs);
};
diff --git a/include/tag_primitive.h b/include/tag_primitive.h
index 73c7b1e727..9c4cd3b2b9 100644
--- a/include/tag_primitive.h
+++ b/include/tag_primitive.h
@@ -59,6 +59,8 @@ private:
T value;
bool equals(const tag& rhs) const override;
+
+ tag_primitive<T>& assign(tag&& rhs) override;
};
template<class T> bool operator==(const tag_primitive<T>& lhs, const tag_primitive<T>& rhs);
@@ -127,6 +129,12 @@ bool tag_primitive<T>::equals(const tag& rhs) const
}
template<class T>
+tag_primitive<T>& tag_primitive<T>::assign(tag&& rhs)
+{
+ return *this = dynamic_cast<tag_primitive<T>&&>(rhs);
+}
+
+template<class T>
bool operator==(const tag_primitive<T>& lhs, const tag_primitive<T>& rhs)
{
return lhs.get() == rhs.get();
diff --git a/include/tag_string.h b/include/tag_string.h
index f1b622eee9..7b71e9122a 100644
--- a/include/tag_string.h
+++ b/include/tag_string.h
@@ -53,6 +53,8 @@ private:
std::string value;
bool equals(const tag& rhs) const override;
+
+ tag_string& assign(tag&& rhs) override;
};
bool operator==(const tag_string& lhs, const tag_string& rhs);
diff --git a/src/tag_compound.cpp b/src/tag_compound.cpp
index 53fd9df8ac..1d4fd6d720 100644
--- a/src/tag_compound.cpp
+++ b/src/tag_compound.cpp
@@ -94,6 +94,11 @@ bool tag_compound::equals(const tag& rhs) const
return *this == static_cast<const tag_compound&>(rhs);
}
+tag_compound& tag_compound::assign(tag&& rhs)
+{
+ return *this = dynamic_cast<tag_compound&&>(rhs);
+}
+
bool operator==(const tag_compound& lhs, const tag_compound& rhs)
{
return lhs.tags == rhs.tags;
diff --git a/src/tag_string.cpp b/src/tag_string.cpp
index b3ef075cd3..aade42768b 100644
--- a/src/tag_string.cpp
+++ b/src/tag_string.cpp
@@ -82,6 +82,11 @@ bool tag_string::equals(const tag& rhs) const
return *this == static_cast<const tag_string&>(rhs);
}
+tag_string& tag_string::assign(tag&& rhs)
+{
+ return *this = dynamic_cast<tag_string&&>(rhs);
+}
+
bool operator==(const tag_string& lhs, const tag_string& rhs)
{
return lhs.get() == rhs.get();
diff --git a/src/value.cpp b/src/value.cpp
index 339c737505..a5f8e3c894 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -19,6 +19,7 @@
*/
#include "value.h"
#include "libnbt.h"
+#include <typeinfo>
namespace nbt
{
@@ -35,7 +36,8 @@ value& value::operator=(std::unique_ptr<tag>&& t)
value& value::operator=(tag&& t)
{
- return *this = std::move(t).move_clone();
+ tag_->assign(std::move(t));
+ return *this;
}
tag_type value::get_type() const