[icinga-checkins] icinga.org: icinga2/master: Add rvalue support for the Array and Dictionary classes

git at icinga.org git at icinga.org
Sat Aug 27 07:42:35 CEST 2016


Module: icinga2
Branch: master
Commit: 56ba6089d03668fc0fe8b7b1e56c04fe1ccaada8
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=56ba6089d03668fc0fe8b7b1e56c04fe1ccaada8

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Aug 27 07:35:04 2016 +0200

Add rvalue support for the Array and Dictionary classes

refs #12555

---

 lib/base/array.cpp      |   25 +++++++++++++++++++++++++
 lib/base/array.hpp      |    2 ++
 lib/base/dictionary.cpp |   12 ++++++++++++
 lib/base/dictionary.hpp |    1 +
 lib/base/value.hpp      |    7 ++++++-
 5 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/lib/base/array.cpp b/lib/base/array.cpp
index 9b7067c..581284a 100644
--- a/lib/base/array.cpp
+++ b/lib/base/array.cpp
@@ -57,6 +57,19 @@ void Array::Set(unsigned int index, const Value& value)
 }
 
 /**
+ * Sets a value in the array.
+ *
+ * @param index The index.
+ * @param value The value.
+ */
+void Array::Set(unsigned int index, Value&& value)
+{
+	ObjectLock olock(this);
+
+	m_Data.at(index).Swap(value);
+}
+
+/**
  * Adds a value to the array.
  *
  * @param value The value.
@@ -69,6 +82,18 @@ void Array::Add(const Value& value)
 }
 
 /**
+ * Adds a value to the array.
+ *
+ * @param value The value.
+ */
+void Array::Add(Value&& value)
+{
+	ObjectLock olock(this);
+
+	m_Data.push_back(value);
+}
+
+/**
  * Returns the number of elements in the array.
  *
  * @returns Number of elements.
diff --git a/lib/base/array.hpp b/lib/base/array.hpp
index 432ec22..5016d66 100644
--- a/lib/base/array.hpp
+++ b/lib/base/array.hpp
@@ -55,7 +55,9 @@ public:
 
 	Value Get(unsigned int index) const;
 	void Set(unsigned int index, const Value& value);
+	void Set(unsigned int index, Value&& value);
 	void Add(const Value& value);
+	void Add(Value&& value);
 
 	/**
 	 * Returns an iterator to the beginning of the array.
diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp
index b1a5cba..5d8da25 100644
--- a/lib/base/dictionary.cpp
+++ b/lib/base/dictionary.cpp
@@ -78,6 +78,18 @@ void Dictionary::Set(const String& key, const Value& value)
 	m_Data[key] = value;
 }
 
+/**
+ * Sets a value in the dictionary.
+ *
+ * @param key The key.
+ * @param value The value.
+ */
+void Dictionary::Set(const String& key, Value&& value)
+{
+	ObjectLock olock(this);
+
+	m_Data[key].Swap(value);
+}
 
 /**
  * Returns the number of elements in the dictionary.
diff --git a/lib/base/dictionary.hpp b/lib/base/dictionary.hpp
index c83f8c0..ff2e4b5 100644
--- a/lib/base/dictionary.hpp
+++ b/lib/base/dictionary.hpp
@@ -58,6 +58,7 @@ public:
 	Value Get(const String& key) const;
 	bool Get(const String& key, Value *result) const;
 	void Set(const String& key, const Value& value);
+	void Set(const String& key, Value&& value);
 	bool Contains(const String& key) const;
 
 	/**
diff --git a/lib/base/value.hpp b/lib/base/value.hpp
index 48c8a63..1d265a5 100644
--- a/lib/base/value.hpp
+++ b/lib/base/value.hpp
@@ -244,11 +244,16 @@ public:
 	*
 	* @returns The type.
 	*/
-	ValueType GetType(void) const
+	inline ValueType GetType(void) const
 	{
 		return static_cast<ValueType>(m_Value.which());
 	}
 
+	inline void Swap(Value& other)
+	{
+		m_Value.swap(other.m_Value);
+	}
+
 	String GetTypeName(void) const;
 
 	Type::Ptr GetReflectionType(void) const;



More information about the icinga-checkins mailing list