From 1ce4f17facba4dfe62cf52c83b4d59e51b659c31 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Sun, 12 Jul 2015 18:19:38 +0200 Subject: Implement tag_list --- src/tag_list.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/tag_list.cpp (limited to 'src') diff --git a/src/tag_list.cpp b/src/tag_list.cpp new file mode 100644 index 0000000000..2b66889e56 --- /dev/null +++ b/src/tag_list.cpp @@ -0,0 +1,99 @@ +/* + * 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 . + */ +#include "tag_list.h" + +namespace nbt +{ + +tag_list::tag_list(): + tag_list(tag_type::Null) +{} + +tag_list::tag_list(tag_type type): + el_type_(type) +{} + +value& tag_list::at(size_t i) +{ + return tags.at(i); +} + +const value& tag_list::at(size_t i) const +{ + return tags.at(i); +} + +value& tag_list::operator[](size_t i) +{ + return tags[i]; +} + +const value& tag_list::operator[](size_t i) const +{ + return tags[i]; +} + +void tag_list::set(size_t i, value&& val) +{ + if(val.get_type() != el_type_) + throw std::bad_cast(); + tags.at(i) = std::move(val); +} + +void tag_list::push_back(value&& val) +{ + if(!val) //don't allow null values + throw std::bad_cast(); + if(el_type_ == tag_type::Null) //set content type if undetermined + el_type_ = val.get_type(); + else if(el_type_ != val.get_type()) + throw std::bad_cast(); + tags.push_back(std::move(val)); +} + +void tag_list::pop_back() +{ + tags.pop_back(); +} + +tag_type tag_list::el_type() const +{ + return el_type_; +} + +size_t tag_list::size() const +{ + return tags.size(); +} + +void tag_list::clear() +{ + tags.clear(); +} + +auto tag_list::begin() -> iterator { return tags.begin(); } +auto tag_list::end() -> iterator { return tags.end(); } +auto tag_list::begin() const -> const_iterator { return tags.begin(); } +auto tag_list::end() const -> const_iterator { return tags.end(); } +auto tag_list::cbegin() const -> const_iterator { return tags.cbegin(); } +auto tag_list::cend() const -> const_iterator { return tags.cend(); } + +} + -- cgit 0.0.5-2-1-g0f52