summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-07-07 17:04:39 +0200
committerljfa-ag <ljfa-ag@web.de>2015-07-07 17:04:39 +0200
commit49bcfa77e1252fb9e4e55d6a5f97a420f6de8fc4 (patch)
treee8ed279f93623fb35364ed2e8e21e516256f5681
parent4ea7019e8594254b77b72ea66e7700b2d8e6d2ef (diff)
downloadProject-Tick-49bcfa77e1252fb9e4e55d6a5f97a420f6de8fc4.tar.gz
Project-Tick-49bcfa77e1252fb9e4e55d6a5f97a420f6de8fc4.zip
Create copy and clone functions for value and tag
-rw-r--r--include/crtp_tag.h10
-rw-r--r--include/tag.h1
-rw-r--r--include/value.h5
-rw-r--r--src/value.cpp5
4 files changed, 21 insertions, 0 deletions
diff --git a/include/crtp_tag.h b/include/crtp_tag.h
index abd8b3b1ce..928759d6b8 100644
--- a/include/crtp_tag.h
+++ b/include/crtp_tag.h
@@ -37,6 +37,7 @@ namespace detail
tag_type get_type() const noexcept override final;
+ std::unique_ptr<tag> clone() const& override final;
std::unique_ptr<tag> move_clone() && override final;
private:
@@ -53,6 +54,15 @@ namespace detail
return Sub::type;
}
+ //TODO: Add copy constructors for tags that are missing it before this becomes useable
+ /*template<class Sub>
+ std::unique_ptr<tag> crtp_tag<Sub>::clone() const&
+ {
+ return std::unique_ptr<tag>(
+ new Sub(static_cast<const Sub&>(*this))
+ );
+ }*/
+
template<class Sub>
std::unique_ptr<tag> crtp_tag<Sub>::move_clone() &&
{
diff --git a/include/tag.h b/include/tag.h
index 6b037b9a32..da1d5098ad 100644
--- a/include/tag.h
+++ b/include/tag.h
@@ -54,6 +54,7 @@ public:
///Returns the type of the tag
virtual tag_type get_type() const noexcept = 0;
+ virtual std::unique_ptr<tag> clone() const& = 0;
virtual std::unique_ptr<tag> move_clone() && = 0;
friend bool operator==(const tag& lhs, const tag& rhs);
diff --git a/include/value.h b/include/value.h
index 7d3dfc0e92..64e79efe9c 100644
--- a/include/value.h
+++ b/include/value.h
@@ -128,6 +128,11 @@ public:
value& operator[](const std::string& key);
value& operator[](const char* key); //need this overload because of conflict with built-in operator[]
+ /**
+ * @brief Creates a copy of the value
+ */
+ value copy() const;
+
std::unique_ptr<tag>& get_ptr();
const std::unique_ptr<tag>& get_ptr() const;
void set_ptr(std::unique_ptr<tag>&& t);
diff --git a/src/value.cpp b/src/value.cpp
index bf75b8931b..d6c276471a 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -356,6 +356,11 @@ value& value::operator[](const char* key)
return (*this)[std::string(key)];
}
+value value::copy() const
+{
+ return value(tag_->clone());
+}
+
std::unique_ptr<tag>& value::get_ptr()
{
return tag_;