diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-07-01 21:44:33 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-07-01 21:44:33 +0200 |
| commit | 3dfa9f71eedd26eaaaba60573d2a6b7a2ab60b8c (patch) | |
| tree | 71604ee7ed20865d85fbf35199b1a00a55e53858 | |
| parent | ffaf121d24428a9d822c1e3de512b9593be7aa0e (diff) | |
| download | Project-Tick-3dfa9f71eedd26eaaaba60573d2a6b7a2ab60b8c.tar.gz Project-Tick-3dfa9f71eedd26eaaaba60573d2a6b7a2ab60b8c.zip | |
Also define get_type with CRTP
| -rw-r--r-- | include/crtp_tag.h | 14 | ||||
| -rw-r--r-- | include/tag_compound.h | 2 | ||||
| -rw-r--r-- | include/tag_primitive.h | 8 | ||||
| -rw-r--r-- | include/tag_string.h | 2 | ||||
| -rw-r--r-- | src/tag_compound.cpp | 5 | ||||
| -rw-r--r-- | 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<tag> move_clone() && override final; private: @@ -40,6 +45,15 @@ namespace detail }; template<class Sub> + crtp_tag<Sub>::~crtp_tag() {} + + template<class Sub> + tag_type crtp_tag<Sub>::get_type() const noexcept + { + return Sub::type; + } + + template<class Sub> std::unique_ptr<tag> crtp_tag<Sub>::move_clone() && { return std::unique_ptr<tag>( 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; }; @@ -105,12 +103,6 @@ T tag_primitive<T>::get() const } template<class T> -tag_type tag_primitive<T>::get_type() const noexcept -{ - return type; -} - -template<class T> bool operator==(const tag_primitive<T>& lhs, const tag_primitive<T>& rhs) { return lhs.get() == rhs.get(); 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(); |
