[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:35:45 CEST 2016


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

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 +
 4 files changed, 40 insertions(+)

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;
 
 	/**



More information about the icinga-checkins mailing list