From 3dfa9f71eedd26eaaaba60573d2a6b7a2ab60b8c Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Wed, 1 Jul 2015 21:44:33 +0200 Subject: Also define get_type with CRTP --- include/crtp_tag.h | 14 ++++++++++++++ include/tag_compound.h | 2 -- include/tag_primitive.h | 8 -------- include/tag_string.h | 2 -- src/tag_compound.cpp | 5 ----- src/tag_string.cpp | 5 ----- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/include/crtp_tag.h b/include/crtp_tag.h index f35b9d0c9a..fa28a74d41 100644 --- a/include/crtp_tag.h +++ b/include/crtp_tag.h @@ -32,6 +32,11 @@ namespace detail class crtp_tag : public tag { public: + //Pure virtual destructor to make the class abstract + virtual ~crtp_tag() = 0; + + tag_type get_type() const noexcept override final; + std::unique_ptr move_clone() && override final; private: @@ -39,6 +44,15 @@ namespace detail tag& assign(tag&& rhs) override final; }; + template + crtp_tag::~crtp_tag() {} + + template + tag_type crtp_tag::get_type() const noexcept + { + return Sub::type; + } + template std::unique_ptr crtp_tag::move_clone() && { diff --git a/include/tag_compound.h b/include/tag_compound.h index 265479c8af..ddd96e0a58 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -107,8 +107,6 @@ public: const_iterator cbegin() const; const_iterator cend() const; - tag_type get_type() const noexcept 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 6087495048..e839be7da0 100644 --- a/include/tag_primitive.h +++ b/include/tag_primitive.h @@ -51,8 +51,6 @@ public: tag_primitive& operator=(T value); void set(T value); - tag_type get_type() const noexcept override; - private: T value; }; @@ -104,12 +102,6 @@ T tag_primitive::get() const return value; } -template -tag_type tag_primitive::get_type() const noexcept -{ - return type; -} - template bool operator==(const tag_primitive& lhs, const tag_primitive& rhs) { diff --git a/include/tag_string.h b/include/tag_string.h index 3c514bae96..f4476993e3 100644 --- a/include/tag_string.h +++ b/include/tag_string.h @@ -45,8 +45,6 @@ public: void set(const std::string& str); void set(std::string&& str); - tag_type get_type() const noexcept override; - private: std::string value; }; diff --git a/src/tag_compound.cpp b/src/tag_compound.cpp index 6aa12e64ff..6bc83301e2 100644 --- a/src/tag_compound.cpp +++ b/src/tag_compound.cpp @@ -79,11 +79,6 @@ auto tag_compound::end() const -> const_iterator { return tags.end(); } auto tag_compound::cbegin() const -> const_iterator { return tags.cbegin(); } auto tag_compound::cend() const -> const_iterator { return tags.cend(); } -tag_type tag_compound::get_type() const noexcept -{ - return type; -} - bool operator==(const tag_compound& lhs, const tag_compound& rhs) { return lhs.tags == rhs.tags; diff --git a/src/tag_string.cpp b/src/tag_string.cpp index 1f1e242e3a..6bd1465e84 100644 --- a/src/tag_string.cpp +++ b/src/tag_string.cpp @@ -67,11 +67,6 @@ void tag_string::set(std::string&& str) value = std::move(str); } -tag_type tag_string::get_type() const noexcept -{ - return type; -} - bool operator==(const tag_string& lhs, const tag_string& rhs) { return lhs.get() == rhs.get(); -- cgit 0.0.5-2-1-g0f52