Add rvalue support for the Array and Dictionary classes

refs #12555
This commit is contained in:
Gunnar Beutner 2016-08-27 07:35:04 +02:00
parent 7194b36d3e
commit 56ba6089d0
5 changed files with 46 additions and 1 deletions

View 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.
*

View 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.

View 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.

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

View 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;