summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-07-12 12:29:25 +0200
committerljfa-ag <ljfa-ag@web.de>2015-07-12 12:29:25 +0200
commitbd8ac94ccb071ffb4cc16b3fb514e789ca1f866d (patch)
tree4fb66e697bf5a5898f35541a0ef5e6264e5e9506
parent125c0c3acbac2b1aabdcc6d2b7f1a84c16d4b38e (diff)
downloadProject-Tick-bd8ac94ccb071ffb4cc16b3fb514e789ca1f866d.tar.gz
Project-Tick-bd8ac94ccb071ffb4cc16b3fb514e789ca1f866d.zip
Create tag_list
-rw-r--r--include/libnbt.h1
-rw-r--r--include/tag_list.h103
-rw-r--r--test/nbttest.cpp2
3 files changed, 105 insertions, 1 deletions
diff --git a/include/libnbt.h b/include/libnbt.h
index 9d873254f6..965fa309ca 100644
--- a/include/libnbt.h
+++ b/include/libnbt.h
@@ -23,5 +23,6 @@
#include "tag_primitive.h"
#include "tag_string.h"
#include "tag_compound.h"
+#include "tag_list.h"
#endif // LIBNBT_H_INCLUDED
diff --git a/include/tag_list.h b/include/tag_list.h
new file mode 100644
index 0000000000..afc04c0616
--- /dev/null
+++ b/include/tag_list.h
@@ -0,0 +1,103 @@
+/*
+ * libnbt++ - A library for the Minecraft Named Binary Tag format.
+ * Copyright (C) 2013, 2015 ljfa-ag
+ *
+ * This file is part of libnbt++.
+ *
+ * libnbt++ is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libnbt++ is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef TAG_LIST_H_INCLUDED
+#define TAG_LIST_H_INCLUDED
+
+#include "crtp_tag.h"
+#include <vector>
+
+namespace nbt
+{
+
+///Tag that contains multiple unnamed tags of the same type
+class tag_list : public detail::crtp_tag<tag_list>
+{
+public:
+ //Iterator types
+ typedef std::vector<value>::iterator iterator;
+ typedef std::vector<value>::const_iterator const_iterator;
+
+ ///The type of the tag
+ static constexpr tag_type type = tag_type::List;
+
+ ///Constructs an empty list
+ tag_list() {}
+
+ /**
+ * @brief Accesses a tag by index with bounds checking
+ *
+ * Returns a value to the tag at the specified index, or throws an
+ * exception if it is out of range.
+ * @throw std::out_of_range if given key does not exist
+ */
+ value& at(size_t i);
+ const value& at(size_t i) const;
+
+ /**
+ * @brief Accesses a tag by index
+ *
+ * Returns a value to the tag at the specified index. No bounds checking
+ * is performed.
+ */
+ value& operator[](size_t i);
+ const value& operator[](size_t i) const;
+
+ /**
+ * @brief Appends the tag to the end of the list
+ * @throw std::bad_cast if the type of the tag does not match the list's
+ * content type
+ */
+ void push_back(value&& val);
+
+ /**
+ * @brief Constructs and appends a tag to the end of the list
+ * @throw std::bad_cast if the type of the tag does not match the list's
+ * content type
+ */
+ template<class T, class... Args>
+ void emplace_back(Args&&... args);
+
+ ///Removes the last element of the list
+ void pop_back();
+
+ ///Returns the number of tags in the list
+ size_t size() const;
+
+ ///Erases all tags from the list
+ void clear();
+
+ //Iterators
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+ const_iterator cbegin() const;
+ const_iterator cend() const;
+
+ friend bool operator==(const tag_list& lhs, const tag_list& rhs);
+ friend bool operator!=(const tag_list& lhs, const tag_list& rhs);
+
+private:
+ std::vector<value> tags;
+};
+
+}
+
+#endif // TAG_LIST_H_INCLUDED
diff --git a/test/nbttest.cpp b/test/nbttest.cpp
index f4d0405273..f24b25f5f6 100644
--- a/test/nbttest.cpp
+++ b/test/nbttest.cpp
@@ -32,7 +32,7 @@ void test_get_type()
ASSERT(tag_double().get_type() == tag_type::Double);
//ASSERT(tag_byte_array().get_type() == tag_type::Byte_Array);
ASSERT(tag_string().get_type() == tag_type::String);
- //ASSERT(tag_list().get_type() == tag_type::List);
+ ASSERT(tag_list().get_type() == tag_type::List);
ASSERT(tag_compound().get_type() == tag_type::Compound);
//ASSERT(tag_int_array().get_type() == tag_type::Int_Array);
std::clog << "test_get_type passed" << std::endl;