diff --git a/doomsday/libcore/include/de/data/variable.h b/doomsday/libcore/include/de/data/variable.h index 025b0bdedd..2d08e977ab 100644 --- a/doomsday/libcore/include/de/data/variable.h +++ b/doomsday/libcore/include/de/data/variable.h @@ -176,6 +176,20 @@ class DENG2_PUBLIC Variable : public ISerializable return *v; } + /** + * Returns the value of the variable. + */ + template + Type const &value() const { + Type const *v = dynamic_cast(valuePtr()); + if(!v) { + /// @throw TypeError Casting to Type failed. + throw TypeError("Variable::value", + QString("Illegal type conversion to ") + typeid(Type).name()); + } + return *v; + } + /** * Returns the Record that the variable references. If the variable does * not have a RecordValue, an exception is thrown. @@ -184,6 +198,10 @@ class DENG2_PUBLIC Variable : public ISerializable */ Record const &valueAsRecord() const; + Record &valueAsRecord(); + + operator Record & (); + operator Record const & () const; // Automatic conversion to native primitive types. @@ -191,20 +209,6 @@ class DENG2_PUBLIC Variable : public ISerializable operator QString () const; operator ddouble () const; - /** - * Returns the value of the variable. - */ - template - Type const &value() const { - Type const *v = dynamic_cast(valuePtr()); - if(!v) { - /// @throw TypeError Casting to Type failed. - throw TypeError("Variable::value", - QString("Illegal type conversion to ") + typeid(Type).name()); - } - return *v; - } - /** * Returns the current mode flags of the variable. */ diff --git a/doomsday/libcore/src/data/record.cpp b/doomsday/libcore/src/data/record.cpp index c0dded59ff..cef65da3ca 100644 --- a/doomsday/libcore/src/data/record.cpp +++ b/doomsday/libcore/src/data/record.cpp @@ -704,7 +704,7 @@ Record const &Record::parentRecordForMember(String const &name) const if(lastOmitted.isEmpty()) return *this; // Omit the final segment of the dotted path to find out the parent record. - return (*this)[lastOmitted].valueAsRecord(); + return (*this)[lastOmitted]; } QTextStream &operator << (QTextStream &os, Record const &record) diff --git a/doomsday/libcore/src/data/variable.cpp b/doomsday/libcore/src/data/variable.cpp index f737585a05..a3941e9737 100644 --- a/doomsday/libcore/src/data/variable.cpp +++ b/doomsday/libcore/src/data/variable.cpp @@ -167,11 +167,21 @@ Value const *Variable::valuePtr() const return d->value; } +Record &Variable::valueAsRecord() +{ + return value().dereference(); +} + Record const &Variable::valueAsRecord() const { return value().dereference(); } +Variable::operator Record & () +{ + return valueAsRecord(); +} + Variable::operator Record const & () const { return valueAsRecord();