diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-09-06 23:35:58 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-09-06 23:35:58 +0200 |
commit | 38693e1d6ca7f05d9488348ddf298488d1cc0995 (patch) | |
tree | d99551fc3ebbef931d10ee45cb34f2ee791cc1fe /depends/libnbtplusplus/include/crtp_tag.h | |
parent | 40b233448c7a3977d45831b8aa6cf31019c03940 (diff) | |
download | MultiMC-38693e1d6ca7f05d9488348ddf298488d1cc0995.tar MultiMC-38693e1d6ca7f05d9488348ddf298488d1cc0995.tar.gz MultiMC-38693e1d6ca7f05d9488348ddf298488d1cc0995.tar.lz MultiMC-38693e1d6ca7f05d9488348ddf298488d1cc0995.tar.xz MultiMC-38693e1d6ca7f05d9488348ddf298488d1cc0995.zip |
GH-1047 parse world files and integrate MCEdit with world page
Diffstat (limited to 'depends/libnbtplusplus/include/crtp_tag.h')
-rw-r--r-- | depends/libnbtplusplus/include/crtp_tag.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/depends/libnbtplusplus/include/crtp_tag.h b/depends/libnbtplusplus/include/crtp_tag.h new file mode 100644 index 00000000..82b41907 --- /dev/null +++ b/depends/libnbtplusplus/include/crtp_tag.h @@ -0,0 +1,66 @@ +/* + * 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 CRTP_TAG_H_INCLUDED +#define CRTP_TAG_H_INCLUDED + +#include "tag.h" +#include "nbt_visitor.h" +#include "make_unique.h" + +#include "nbt++_export.h" + +namespace nbt +{ + +namespace detail +{ + + template<class Sub> + class NBT___EXPORT crtp_tag : public tag + { + public: + //Pure virtual destructor to make the class abstract + virtual ~crtp_tag() noexcept = 0; + + tag_type get_type() const noexcept override final { return Sub::type; }; + + std::unique_ptr<tag> clone() const& override final { return make_unique<Sub>(sub_this()); } + std::unique_ptr<tag> move_clone() && override final { return make_unique<Sub>(std::move(sub_this())); } + + tag& assign(tag&& rhs) override final { return sub_this() = dynamic_cast<Sub&&>(rhs); } + + void accept(nbt_visitor& visitor) override final { visitor.visit(sub_this()); } + void accept(const_nbt_visitor& visitor) const override final { visitor.visit(sub_this()); } + + private: + bool equals(const tag& rhs) const override final { return sub_this() == static_cast<const Sub&>(rhs); } + + Sub& sub_this() { return static_cast<Sub&>(*this); } + const Sub& sub_this() const { return static_cast<const Sub&>(*this); } + }; + + template<class Sub> + crtp_tag<Sub>::~crtp_tag() noexcept {} + +} + +} + +#endif // CRTP_TAG_H_INCLUDED |