]> granicus.if.org Git - icinga2/commitdiff
Add rvalue support for the Array and Dictionary classes
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 27 Aug 2016 05:35:04 +0000 (07:35 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 27 Aug 2016 05:42:28 +0000 (07:42 +0200)
refs #12555

lib/base/array.cpp
lib/base/array.hpp
lib/base/dictionary.cpp
lib/base/dictionary.hpp
lib/base/value.hpp

index 9b7067cd8caaf627e3e9909d90f1d479813ff85d..581284aa9d18aebc7ee621a29adcfa4ca9069fe1 100644 (file)
@@ -56,6 +56,19 @@ void Array::Set(unsigned int index, const Value& value)
        m_Data.at(index) = 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.
  *
@@ -68,6 +81,18 @@ void Array::Add(const Value& value)
        m_Data.push_back(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.
  *
index 432ec221fc53a5d277cd674946e28eb03d860862..5016d66b0acf74b52e472fef404ad2c7cd58d976 100644 (file)
@@ -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.
index b1a5cbafec7300ea674bc42897585a2e3e779b55..5d8da2549f12a0b03a21a1f4605f3bdd0265dcd8 100644 (file)
@@ -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.
index c83f8c0bae1a9a07e377f4d7b1e9d820c0d5e538..ff2e4b5697a6c944b65fa306372a78bcbaafcb0b 100644 (file)
@@ -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;
 
        /**
index 48c8a63ded768b9b8f888e1fd87ff2d2e123efb4..1d265a5af2845e14c05cef064c13e7786aaa3f14 100644 (file)
@@ -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;