From 38693e1d6ca7f05d9488348ddf298488d1cc0995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 6 Sep 2015 23:35:58 +0200 Subject: GH-1047 parse world files and integrate MCEdit with world page --- depends/libnbtplusplus/include/tag_primitive.h | 102 +++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 depends/libnbtplusplus/include/tag_primitive.h (limited to 'depends/libnbtplusplus/include/tag_primitive.h') diff --git a/depends/libnbtplusplus/include/tag_primitive.h b/depends/libnbtplusplus/include/tag_primitive.h new file mode 100644 index 00000000..8b70c147 --- /dev/null +++ b/depends/libnbtplusplus/include/tag_primitive.h @@ -0,0 +1,102 @@ +/* + * 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 . + */ +#ifndef TAG_PRIMITIVE_H_INCLUDED +#define TAG_PRIMITIVE_H_INCLUDED + +#include "crtp_tag.h" +#include "primitive_detail.h" +#include "io/stream_reader.h" +#include "io/stream_writer.h" +#include +#include + +#include "nbt++_export.h" + +namespace nbt +{ + +/** + * @brief Tag that contains an integral or floating-point value + * + * Common class for tag_byte, tag_short, tag_int, tag_long, tag_float and tag_double. + */ +template +class tag_primitive final : public detail::crtp_tag> +{ +public: + ///The type of the value + typedef T value_type; + + ///The type of the tag + static constexpr tag_type type = detail::get_primitive_type::value; + + //Constructor + constexpr tag_primitive(T val = 0) noexcept: value(val) {} + + //Getters + operator T&() { return value; } + constexpr operator T() const { return value; } + constexpr T get() const { return value; } + + //Setters + tag_primitive& operator=(T val) { value = val; return *this; } + void set(T val) { value = val; } + + void read_payload(io::stream_reader& reader) override; + void write_payload(io::stream_writer& writer) const override; + +private: + T value; +}; + +template bool operator==(const tag_primitive& lhs, const tag_primitive& rhs) +{ return lhs.get() == rhs.get(); } +template bool operator!=(const tag_primitive& lhs, const tag_primitive& rhs) +{ return !(lhs == rhs); } + +//Typedefs that should be used instead of the template tag_primitive. +typedef tag_primitive tag_byte; +typedef tag_primitive tag_short; +typedef tag_primitive tag_int; +typedef tag_primitive tag_long; +typedef tag_primitive tag_float; +typedef tag_primitive tag_double; + +template +void tag_primitive::read_payload(io::stream_reader& reader) +{ + reader.read_num(value); + if(!reader.get_istr()) + { + std::ostringstream str; + str << "Error reading tag_" << type; + throw io::input_error(str.str()); + } +} + +template +void tag_primitive::write_payload(io::stream_writer& writer) const +{ + writer.write_num(value); +} + +} + +#endif // TAG_PRIMITIVE_H_INCLUDED -- cgit v1.2.3