From 2345716fbdf380dde60cccb71cbc335cf587fec6 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Wed, 1 Jul 2015 19:48:04 +0200 Subject: Create tag::assign method Implement value::operator= in terms of it --- include/tag.h | 8 ++++++++ include/tag_compound.h | 2 ++ include/tag_primitive.h | 8 ++++++++ include/tag_string.h | 2 ++ 4 files changed, 20 insertions(+) (limited to 'include') diff --git a/include/tag.h b/include/tag.h index acc537500f..a9cbc0019f 100644 --- a/include/tag.h +++ b/include/tag.h @@ -64,6 +64,14 @@ private: * @param rhs an instance of the same class as @c *this */ virtual bool equals(const tag& rhs) const = 0; + + /** + * @brief Assigns the given tag if the class is the same + * @throw std::bad_cast if @c rhs is not the same type as @c *this + */ + virtual tag& assign(tag&& rhs) = 0; + + friend class value; }; } diff --git a/include/tag_compound.h b/include/tag_compound.h index fb2d27123a..32380a0c6c 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -116,6 +116,8 @@ private: bool equals(const tag& rhs) const override; + tag_compound& assign(tag&& rhs) override; + friend bool operator==(const tag_compound& lhs, const tag_compound& rhs); friend bool operator!=(const tag_compound& lhs, const tag_compound& rhs); }; diff --git a/include/tag_primitive.h b/include/tag_primitive.h index 73c7b1e727..9c4cd3b2b9 100644 --- a/include/tag_primitive.h +++ b/include/tag_primitive.h @@ -59,6 +59,8 @@ private: T value; bool equals(const tag& rhs) const override; + + tag_primitive& assign(tag&& rhs) override; }; template bool operator==(const tag_primitive& lhs, const tag_primitive& rhs); @@ -126,6 +128,12 @@ bool tag_primitive::equals(const tag& rhs) const return *this == static_cast&>(rhs); } +template +tag_primitive& tag_primitive::assign(tag&& rhs) +{ + return *this = dynamic_cast&&>(rhs); +} + template bool operator==(const tag_primitive& lhs, const tag_primitive& rhs) { diff --git a/include/tag_string.h b/include/tag_string.h index f1b622eee9..7b71e9122a 100644 --- a/include/tag_string.h +++ b/include/tag_string.h @@ -53,6 +53,8 @@ private: std::string value; bool equals(const tag& rhs) const override; + + tag_string& assign(tag&& rhs) override; }; bool operator==(const tag_string& lhs, const tag_string& rhs); -- cgit 0.0.5-2-1-g0f52