From 1393bc318e61b57e2cd6906a6abd3fb4607111c7 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Sun, 28 Jun 2015 17:43:33 +0200 Subject: Rename nbt_value to value --- include/nbt_value.h | 107 ------------------------------------------------- include/tag_compound.h | 18 ++++----- include/value.h | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 116 deletions(-) delete mode 100644 include/nbt_value.h create mode 100644 include/value.h diff --git a/include/nbt_value.h b/include/nbt_value.h deleted file mode 100644 index 786d5e81eb..0000000000 --- a/include/nbt_value.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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_REF_PROXY_H_INCLUDED -#define TAG_REF_PROXY_H_INCLUDED - -#include "tag.h" -#include -#include - -namespace nbt -{ - -//Forward declarations -class tag_compound; -class tag_list; - -/** - * @brief Contains an NBT value of fixed type - * - * A wrapper class that can contain a value of an arbitrary but fixed type. - * Casting or assigning incompatible types will throw an exception. - * It can also refer to an uninitialized value (e.g. when using tag_compound::operator[] - * with a non-existant key). - */ -class nbt_value -{ -public: - //Movable but not (implicitly) copyable - nbt_value(const nbt_value&) = delete; - nbt_value(nbt_value&&) = default; - nbt_value& operator=(const nbt_value&) = delete; - nbt_value& operator=(nbt_value&&) = default; - - //nbt_value& operator=(std::unique_ptr&& ptr); - - //Assignment - /** - * @brief Assigns the given value to the tag if the type matches - * @throw std::bad_cast if the value is not convertible to the tag type - * via a widening conversion - */ - nbt_value& operator=(int8_t val); - nbt_value& operator=(int16_t val); - nbt_value& operator=(int32_t val); - nbt_value& operator=(int64_t val); - nbt_value& operator=(float val); - nbt_value& operator=(double val); - nbt_value& operator=(const std::string& str); - nbt_value& operator=(tag_compound&& comp); - nbt_value& operator=(tag_list&& list); - - //Conversion to tag - operator tag&(); - operator const tag&() const; - - //Conversions to primitives and string - /** - * @brief Casts the value if the type matches - * @throw std::bad_cast if the tag type is not convertible to the desired - * type via a widening conversion - */ - explicit operator int8_t() const; - explicit operator int16_t() const; - explicit operator int32_t() const; - explicit operator int64_t() const; - explicit operator float() const; - explicit operator double() const; - explicit operator const std::string&() const; - - /** - * @brief In case of a tag_compound, accesses a tag by key - * @throw std::bad_cast if the tag type is not tag_compound - * @sa tag_compound::operator[] - */ - nbt_value& operator[](const std::string& key); - const nbt_value& operator[](const std::string& key) const; - - ///@sa tag::get_type - tag_type get_type() const; - - friend bool operator==(const nbt_value& lhs, const nbt_value& rhs); - friend bool operator!=(const nbt_value& lhs, const nbt_value& rhs); - -private: - std::unique_ptr value; -}; - -} - -#endif // TAG_REF_PROXY_H_INCLUDED diff --git a/include/tag_compound.h b/include/tag_compound.h index 51f0cd2709..e0426dbf74 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -21,7 +21,7 @@ #define TAG_COMPOUND_H_INCLUDED #include "tag.h" -#include "nbt_value.h" +#include "value.h" #include #include #include @@ -43,27 +43,27 @@ public: ///Constructs an empty compound tag_compound() {} - //TODO: Make a separate class similar to and convertible to nbt_value for initializing tag values - //tag_compound(std::initializer_list> init); + //TODO: Make a separate class similar to and convertible to value for initializing tag values + //tag_compound(std::initializer_list> init); /** * @brief Accesses a tag by key with bounds checking * - * Returns a nbt_value to the tag with the specified key, or throws an + * Returns a value to the tag with the specified key, or throws an * exception if it does not exist. * @throw std::out_of_range if given key does not exist */ - nbt_value& at(const std::string& key); - const nbt_value& at(const std::string& key) const; + value& at(const std::string& key); + const value& at(const std::string& key) const; /** * @brief Accesses a tag by key * - * If the key exists, returns a nbt_value to the corresponding tag. + * If the key exists, returns a value to the corresponding tag. * Else, a new uninitalized entry is created under this key. */ - nbt_value& operator[](const std::string& key); - const nbt_value& operator[](const std::string& key) const; + value& operator[](const std::string& key); + const value& operator[](const std::string& key) const; /** * @brief Erases a tag from the compound diff --git a/include/value.h b/include/value.h new file mode 100644 index 0000000000..4553b3e8f4 --- /dev/null +++ b/include/value.h @@ -0,0 +1,107 @@ +/* + * 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_REF_PROXY_H_INCLUDED +#define TAG_REF_PROXY_H_INCLUDED + +#include "tag.h" +#include +#include + +namespace nbt +{ + +//Forward declarations +class tag_compound; +class tag_list; + +/** + * @brief Contains an NBT value of fixed type + * + * A wrapper class that can contain a tag of an arbitrary but fixed type. + * Casting or assigning incompatible types will throw an exception. + * It can also refer to an uninitialized value (e.g. when using tag_compound::operator[] + * with a non-existant key). + */ +class value +{ +public: + //Movable but not (implicitly) copyable + value(const value&) = delete; + value(value&&) = default; + value& operator=(const value&) = delete; + value& operator=(value&&) = default; + + //value& operator=(std::unique_ptr&& ptr); + + //Assignment + /** + * @brief Assigns the given value to the tag if the type matches + * @throw std::bad_cast if the value is not convertible to the tag type + * via a widening conversion + */ + value& operator=(int8_t val); + value& operator=(int16_t val); + value& operator=(int32_t val); + value& operator=(int64_t val); + value& operator=(float val); + value& operator=(double val); + value& operator=(const std::string& str); + value& operator=(tag_compound&& comp); + value& operator=(tag_list&& list); + + //Conversion to tag + operator tag&(); + operator const tag&() const; + + //Conversions to primitives and string + /** + * @brief Casts the value if the type matches + * @throw std::bad_cast if the tag type is not convertible to the desired + * type via a widening conversion + */ + explicit operator int8_t() const; + explicit operator int16_t() const; + explicit operator int32_t() const; + explicit operator int64_t() const; + explicit operator float() const; + explicit operator double() const; + explicit operator const std::string&() const; + + /** + * @brief In case of a tag_compound, accesses a tag by key + * @throw std::bad_cast if the tag type is not tag_compound + * @sa tag_compound::operator[] + */ + value& operator[](const std::string& key); + const value& operator[](const std::string& key) const; + + ///@sa tag::get_type + tag_type get_type() const; + + friend bool operator==(const value& lhs, const value& rhs); + friend bool operator!=(const value& lhs, const value& rhs); + +private: + std::unique_ptr tag_; +}; + +} + +#endif // TAG_REF_PROXY_H_INCLUDED -- cgit 0.0.5-2-1-g0f52