[icinga-checkins] icinga.org: icinga2/feature/choco: Add another rvalue constructor to the String class

git at icinga.org git at icinga.org
Wed Aug 31 13:41:17 CEST 2016


Module: icinga2
Branch: feature/choco
Commit: 54f0cb2c2cf30265982e0d842ded4a738bc6798c
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=54f0cb2c2cf30265982e0d842ded4a738bc6798c

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Aug 31 12:48:49 2016 +0200

Add another rvalue constructor to the String class

refs #12555

---

 lib/base/string.cpp |   17 +++++++++++++++++
 lib/base/string.hpp |    4 ++++
 lib/base/value.hpp  |    6 ++++++
 3 files changed, 27 insertions(+)

diff --git a/lib/base/string.cpp b/lib/base/string.cpp
index c80d7d5..45da410 100644
--- a/lib/base/string.cpp
+++ b/lib/base/string.cpp
@@ -29,6 +29,23 @@ REGISTER_BUILTIN_TYPE(String, String::GetPrototype());
 
 const String::SizeType String::NPos = std::string::npos;
 
+String::String(Value&& other)
+{
+	*this = std::move(other);
+}
+
+String& String::operator=(Value&& other)
+{
+	const String *p = other.GetPtr<String>();
+
+	if (p)
+		m_Data = std::move(p->m_Data);
+	else
+		m_Data = other;
+
+	return *this;
+}
+
 String& String::operator+=(const Value& rhs)
 {
 	m_Data += static_cast<String>(rhs);
diff --git a/lib/base/string.hpp b/lib/base/string.hpp
index 695f420..ea1fc83 100644
--- a/lib/base/string.hpp
+++ b/lib/base/string.hpp
@@ -85,6 +85,8 @@ public:
 		: m_Data(std::move(other.m_Data))
 	{ }
 
+	String(Value&& other);
+
 	inline ~String(void)
 	{ }
 
@@ -105,6 +107,8 @@ public:
 		return *this;
 	}
 
+	String& operator=(Value&& rhs);
+
 	inline String& operator=(const std::string& rhs)
 	{
 		m_Data = rhs;
diff --git a/lib/base/value.hpp b/lib/base/value.hpp
index 476f7b1..4b6800a 100644
--- a/lib/base/value.hpp
+++ b/lib/base/value.hpp
@@ -286,6 +286,12 @@ public:
 		return boost::get<T>(m_Value);
 	}
 
+	template<typename T>
+	const T *GetPtr(void) const
+	{
+		return &boost::get<T>(m_Value);
+	}
+
 private:
 	boost::variant<boost::blank, double, bool, String, Object::Ptr> m_Value;
 };



More information about the icinga-checkins mailing list