From ba86b862d679b358c52aa925044365c8d6057e08 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Thu, 2 Jul 2015 09:04:06 +0200 Subject: Add get/set_ptr and operator bool to value --- include/value.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'include/value.h') diff --git a/include/value.h b/include/value.h index 491a92b2a0..a4ccf22873 100644 --- a/include/value.h +++ b/include/value.h @@ -34,13 +34,14 @@ class tag_list; /** * @brief Contains an NBT value of fixed type * - * A wrapper class that contains a dynamically allocated tag of a fixed type. - * Casting or assigning incompatible types will throw a exceptions. + * A convenience wrapper around @c std::unique_ptr, contains a tag of + * fixed type. */ class value { public: explicit value() {} + explicit value(std::unique_ptr&& t); //Movable but not (implicitly) copyable value(const value&) = delete; @@ -48,9 +49,6 @@ public: value& operator=(const value&) = delete; value& operator=(value&&) = default; - explicit value(std::unique_ptr&& t); - value& operator=(std::unique_ptr&& t); - /** * @brief Assigns the given value to the tag if the type matches * @throw std::bad_cast if the type of @c t is not the same as the type @@ -90,6 +88,9 @@ public: operator double() const; operator const std::string&() const; + ///Returns true if the contained tag is not @c nullptr + explicit operator bool() const; + /** * @brief In case of a tag_compound, accesses a tag by key with bounds checking * @throw std::bad_cast if the tag type is not tag_compound @@ -107,6 +108,10 @@ public: value& operator[](const std::string& key); const value& operator[](const std::string& key) const; + std::unique_ptr& get_ptr(); + const std::unique_ptr& get_ptr() const; + void set_ptr(std::unique_ptr&& t); + ///@sa tag::get_type tag_type get_type() const; -- cgit 0.0.5-2-1-g0f52