Skip to content

Commit

Permalink
libdeng2|Script: More convenient way to add values into an array
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 3, 2012
1 parent ea21e6e commit 23f6b48
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
18 changes: 18 additions & 0 deletions doomsday/libdeng2/include/de/data/arrayvalue.h
Expand Up @@ -97,6 +97,24 @@ class DENG2_PUBLIC ArrayValue : public Value
*/
void remove(dint index);

/**
* Adds a value to the array.
*
* @param value Value to add. Array gets ownership.
*
* @return Reference to the array.
*/
ArrayValue &operator << (Value *value);

/**
* Adds a value to the array.
*
* @param value Value to add. A duplicate of this value is added to the array.
*
* @return Reference to the array.
*/
ArrayValue &operator << (Value const &value);

/**
* Returns a reference to a value in the array.
*
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libdeng2/src/core/config.cpp
Expand Up @@ -72,10 +72,10 @@ void Config::read()
// Current version.
Version verInfo;
QScopedPointer<ArrayValue> version(new ArrayValue());
version->add(new NumberValue(verInfo.major));
version->add(new NumberValue(verInfo.minor));
version->add(new NumberValue(verInfo.patch));
version->add(new NumberValue(verInfo.build));
*version << NumberValue(verInfo.major)
<< NumberValue(verInfo.minor)
<< NumberValue(verInfo.patch)
<< NumberValue(verInfo.build);

File &scriptFile = App::rootFolder().locate<File>(d->configPath);
bool shouldRunScript = false;
Expand Down
12 changes: 12 additions & 0 deletions doomsday/libdeng2/src/data/arrayvalue.cpp
Expand Up @@ -258,6 +258,18 @@ void ArrayValue::remove(dint index)
delete *elem;
_elements.erase(elem);
}

ArrayValue &ArrayValue::operator << (Value *value)
{
add(value);
return *this;
}

ArrayValue &ArrayValue::operator << (Value const &value)
{
add(value.duplicate());
return *this;
}

Value *ArrayValue::pop()
{
Expand Down

0 comments on commit 23f6b48

Please sign in to comment.