summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-08-02 21:47:01 +0200
committerljfa-ag <ljfa-ag@web.de>2015-08-02 21:47:01 +0200
commitbe7e646d091bd1f250d77f443462607b5c27a419 (patch)
tree68b6f7eeb7aa9c1d9135046ba5c97b4317d9848e /src
parenta3fb29ae603a293f12959abbc35af1bf4a156c76 (diff)
downloadProject-Tick-be7e646d091bd1f250d77f443462607b5c27a419.tar.gz
Project-Tick-be7e646d091bd1f250d77f443462607b5c27a419.zip
Create tag::create function
Diffstat (limited to 'src')
-rw-r--r--src/tag.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tag.cpp b/src/tag.cpp
index fbed9fb6e1..b695bd98bb 100644
--- a/src/tag.cpp
+++ b/src/tag.cpp
@@ -18,7 +18,9 @@
* along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tag.h"
+#include "nbt_tags.h"
#include <ostream>
+#include <stdexcept>
#include <typeinfo>
namespace nbt
@@ -29,6 +31,26 @@ std::unique_ptr<tag> tag::clone() &&
return std::move(*this).move_clone();
}
+std::unique_ptr<tag> tag::create(tag_type type)
+{
+ switch(type)
+ {
+ case tag_type::Byte: return make_unique<tag_byte>();
+ case tag_type::Short: return make_unique<tag_short>();
+ case tag_type::Int: return make_unique<tag_int>();
+ case tag_type::Long: return make_unique<tag_long>();
+ case tag_type::Float: return make_unique<tag_float>();
+ case tag_type::Double: return make_unique<tag_double>();
+ case tag_type::Byte_Array: return make_unique<tag_byte_array>();
+ case tag_type::String: return make_unique<tag_string>();
+ case tag_type::List: return make_unique<tag_list>();
+ case tag_type::Compound: return make_unique<tag_compound>();
+ case tag_type::Int_Array: return make_unique<tag_int_array>();
+
+ default: throw std::invalid_argument("Invalid tag type");
+ }
+}
+
bool operator==(const tag& lhs, const tag& rhs)
{
if(typeid(lhs) != typeid(rhs))