diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-07-15 21:50:55 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-07-15 21:56:59 +0200 |
| commit | 578dd6911154a836cda92b5d2cef15efae7c96b9 (patch) | |
| tree | bee30b2521001b06ff76c6dfd884b8c3f31e6b19 | |
| parent | ce3287483e396697d9c4b50629b6c4d3581bdec4 (diff) | |
| download | Project-Tick-578dd6911154a836cda92b5d2cef15efae7c96b9.tar.gz Project-Tick-578dd6911154a836cda92b5d2cef15efae7c96b9.zip | |
Move implementation of tag_array into .cpp file
| -rw-r--r-- | include/tag_array.h | 96 | ||||
| -rw-r--r-- | src/tag_array.cpp | 120 |
2 files changed, 124 insertions, 92 deletions
diff --git a/include/tag_array.h b/include/tag_array.h index 41ec1e573e..7aca60722b 100644 --- a/include/tag_array.h +++ b/include/tag_array.h @@ -27,16 +27,17 @@ namespace nbt { +///@cond namespace detail { - + ///Meta-struct that holds the tag_type value for a specific array type template<class T> struct get_array_type - { static_assert(sizeof(T) != sizeof(T), "Can only use byte or int as parameter for tag_array"); }; + { static_assert(sizeof(T) != sizeof(T), "Invalid type paramter for tag_primitive, can only use byte or int"); }; template<> struct get_array_type<int8_t> : public std::integral_constant<tag_type, tag_type::Byte_Array> {}; template<> struct get_array_type<int32_t> : public std::integral_constant<tag_type, tag_type::Int_Array> {}; - } +///@cond /** * @brief Tag that contains an array of byte or int values @@ -114,95 +115,6 @@ template<class T> bool operator!=(const tag_array<T>& lhs, const tag_array<T>& r typedef tag_array<int8_t> tag_byte_array; typedef tag_array<int32_t> tag_int_array; -template<class T> -tag_array<T>::tag_array(std::initializer_list<T> init): - data(init) -{} - -template<class T> -tag_array<T>::tag_array(std::vector<T>&& vec): - data(std::move(vec)) -{} - -template<class T> -std::vector<T>& tag_array<T>::get() -{ - return data; -} - -template<class T> -const std::vector<T>& tag_array<T>::get() const -{ - return data; -} - -template<class T> -T& tag_array<T>::at(size_t i) -{ - return data.at(i); -} - -template<class T> -T tag_array<T>::at(size_t i) const -{ - return data.at(i); -} - -template<class T> -T& tag_array<T>::operator[](size_t i) -{ - return data[i]; -} - -template<class T> -T tag_array<T>::operator[](size_t i) const -{ - return data[i]; -} - -template<class T> -void tag_array<T>::push_back(T val) -{ - data.push_back(val); -} - -template<class T> -void tag_array<T>::pop_back() -{ - data.pop_back(); -} - -template<class T> -size_t tag_array<T>::size() const -{ - return data.size(); -} - -template<class T> -void tag_array<T>::clear() -{ - data.clear(); -} - -template<class T> auto tag_array<T>::begin() -> iterator { return data.begin(); } -template<class T> auto tag_array<T>::end() -> iterator { return data.end(); } -template<class T> auto tag_array<T>::begin() const -> const_iterator { return data.begin(); } -template<class T> auto tag_array<T>::end() const -> const_iterator { return data.end(); } -template<class T> auto tag_array<T>::cbegin() const -> const_iterator { return data.cbegin(); } -template<class T> auto tag_array<T>::cend() const -> const_iterator { return data.cend(); } - -template<class T> -bool operator==(const tag_array<T>& lhs, const tag_array<T>& rhs) -{ - return lhs.get() == rhs.get(); -} - -template<class T> -bool operator!=(const tag_array<T>& lhs, const tag_array<T>& rhs) -{ - return !(lhs == rhs); -} - } #endif // TAG_ARRAY_H_INCLUDED diff --git a/src/tag_array.cpp b/src/tag_array.cpp new file mode 100644 index 0000000000..0db749d1f6 --- /dev/null +++ b/src/tag_array.cpp @@ -0,0 +1,120 @@ +/* + * 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/>. + */ +#include "tag_array.h" + +namespace nbt +{ + +template<class T> +tag_array<T>::tag_array(std::initializer_list<T> init): + data(init) +{} + +template<class T> +tag_array<T>::tag_array(std::vector<T>&& vec): + data(std::move(vec)) +{} + +template<class T> +std::vector<T>& tag_array<T>::get() +{ + return data; +} + +template<class T> +const std::vector<T>& tag_array<T>::get() const +{ + return data; +} + +template<class T> +T& tag_array<T>::at(size_t i) +{ + return data.at(i); +} + +template<class T> +T tag_array<T>::at(size_t i) const +{ + return data.at(i); +} + +template<class T> +T& tag_array<T>::operator[](size_t i) +{ + return data[i]; +} + +template<class T> +T tag_array<T>::operator[](size_t i) const +{ + return data[i]; +} + +template<class T> +void tag_array<T>::push_back(T val) +{ + data.push_back(val); +} + +template<class T> +void tag_array<T>::pop_back() +{ + data.pop_back(); +} + +template<class T> +size_t tag_array<T>::size() const +{ + return data.size(); +} + +template<class T> +void tag_array<T>::clear() +{ + data.clear(); +} + +template<class T> auto tag_array<T>::begin() -> iterator { return data.begin(); } +template<class T> auto tag_array<T>::end() -> iterator { return data.end(); } +template<class T> auto tag_array<T>::begin() const -> const_iterator { return data.begin(); } +template<class T> auto tag_array<T>::end() const -> const_iterator { return data.end(); } +template<class T> auto tag_array<T>::cbegin() const -> const_iterator { return data.cbegin(); } +template<class T> auto tag_array<T>::cend() const -> const_iterator { return data.cend(); } + +template<class T> +bool operator==(const tag_array<T>& lhs, const tag_array<T>& rhs) +{ + return lhs.get() == rhs.get(); +} + +template<class T> +bool operator!=(const tag_array<T>& lhs, const tag_array<T>& rhs) +{ + return !(lhs == rhs); +} + +//Enforce template instantiations. Just as for tag_primitive we have to instantiate operator!= +template class tag_array<int8_t>; +template class tag_array<int32_t>; +template bool operator!=<int8_t> (const tag_array<int8_t>& , const tag_array<int8_t>&); +template bool operator!=<int32_t>(const tag_array<int32_t>&, const tag_array<int32_t>&); + +} |
